PDA

View Full Version : [C++ - Win32] GetWindowRect() cosa restituisce?


zarko
17-02-2010, 18:33
Ciao a tutti!

Mi trovo davanti a un quesito da novellino :help:
La funzione GetWindowRect() restituisce il rettangolo esterno o interno (quello disegnabile per intenderci) della finestra??
E se restituisce quello esterno come faccio a ottenere quello interno?

Io vorrei ottenere la finestra principale contenente 4 child windows uguali disposte 2 x 2 con 10px di distanza tra loro e dal bordo interno della finestra. Quindi avevo pensato a questo:

RECT mainWndRect;
GetWindowRect(engine->GetMainHWnd(), &mainWndRect);

int childWndWidth = (mainWndRect.right - mainWndRect.left - 30) / 2;
int childWndHeight = (mainWndRect.bottom - mainWndRect.top - 30) / 2;

HWND childHWnd1 = CreateWindowEx(WS_EX_CLIENTEDGE,
TEXT("static"),
NULL,
WS_CHILD | SS_BLACKRECT | WS_VISIBLE,
10,
10,
childWndWidth,
childWndHeight,
engine->GetMainHWnd(),
NULL,
hInst,
NULL);
HWND childHWnd2 = CreateWindowEx(WS_EX_CLIENTEDGE,
TEXT("static"),
NULL,
WS_CHILD | SS_BLACKRECT | WS_VISIBLE,
20 + childWndWidth,
10,
childWndWidth,
childWndHeight,
engine->GetMainHWnd(),
NULL,
hInst,
NULL);
HWND childHWnd3 = CreateWindowEx(WS_EX_CLIENTEDGE,
TEXT("static"),
NULL,
WS_CHILD | SS_BLACKRECT | WS_VISIBLE,
10,
20 + childWndHeight,
childWndWidth,
childWndHeight,
engine->GetMainHWnd(),
NULL,
hInst,
NULL);
HWND childHWnd4 = CreateWindowEx(WS_EX_CLIENTEDGE,
TEXT("static"),
NULL,
WS_CHILD | SS_BLACKRECT | WS_VISIBLE,
20 + childWndWidth,
20 + childWndHeight,
childWndWidth,
childWndHeight,
engine->GetMainHWnd(),
NULL,
hInst,
NULL);


Che perņ non funziona.. le finestre appaiono, ma sporgono di qualche pixel oltre i bordi inferiore e destro..

fero86
18-02-2010, 01:22
La funzione GetWindowRect() restituisce il rettangolo esterno o interno (quello disegnabile per intenderci) della finestra?? esterno; per ottenere quello interno chiama GetClientRect.
l'area "disegnabile", come la chiami tu, si chiama "client area", mentre tutto il resto si chiama "non-client area" ed include la barra di spostamento, i bordi, il menu di sistema, ecc.

zarko
18-02-2010, 08:04
Grazie mille!! Adesso funziona! :)