una tipos segmentacion retencion por hacer estrategias empresa ejemplos como clientes clasificacion categorizacion categoria c++ user-interface winapi

c++ - tipos - ¿Cómo obtengo la posición de un control en relación con el cliente correcto de la ventana?



segmentacion de clientes ejemplos (2)

Quiero poder escribir código como este:

HWND hwnd = <the hwnd of a button in a window>; int positionX; int positionY; GetWindowPos(hwnd, &positionX, &positionY); SetWindowPos(hwnd, 0, positionX, positionY, 0, 0, SWP_NOZORDER | SWP_NOSIZE);

Y haz que no haga nada. Sin embargo, no puedo averiguar cómo escribir una función GetWindowPos() que me dé respuestas en las unidades correctas:

void GetWindowPos(HWND hWnd, int *x, int *y) { HWND hWndParent = GetParent(hWnd); RECT parentScreenRect; RECT itemScreenRect; GetWindowRect(hWndParent, &parentScreenRect); GetWindowRect(hWnd, &itemScreenRect); (*x) = itemScreenRect.left - parentScreenRect.left; (*y) = itemScreenRect.top - parentScreenRect.top; }

Si utilizo esta función, obtengo coordenadas relativas a la esquina superior izquierda de la ventana principal, pero SetWindowPos() desea coordenadas relativas al área debajo de la barra de título (supongo que esto es el "área del cliente", pero La terminología de win32 es todo un poco nueva para mí.

Solución Esta es la función de trabajo GetWindowPos() (gracias Sergio):

void GetWindowPos(HWND hWnd, int *x, int *y) { HWND hWndParent = GetParent(hWnd); POINT p = {0}; MapWindowPoints(hWnd, hWndParent, &p, 1); (*x) = p.x; (*y) = p.y; }


Creo que quieres algo así. No sé caliente para encontrar los controles. Este segmento de código alinea la posición de una etiqueta en el centro de la ventana de acuerdo con el tamaño de la forma.

AllignLabelToCenter(lblCompanyName, frmObj) Public Sub AllignLabelToCenter(ByRef lbl As Label, ByVal objFrm As Form) Dim CenterOfForm As Short = GetCenter(objFrm.Size.Width) Dim CenterOfLabel As Short = GetCenter(lbl.Size.Width) lbl.Location = New System.Drawing.Point(CenterOfForm - CenterOfLabel, lbl.Location.Y) End Sub Private ReadOnly Property GetCenter(ByVal obj As Short) Get Return obj / 2 End Get End Property


Intente utilizar GetClientRect para obtener coordenadas y MapWindowPoints para transformarlo.