Reputation:
I'm trying to draw a border around my window, but my code doesn't seem to work. It doesn't draw anything. Could anyone tell me what's wrong with it?
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC = 0;
PAINTSTRUCT ps;
ZeroMemory(&ps, sizeof(PAINTSTRUCT));
HPEN hp353535 = 0;
RECT rWnd;
GetWindowRect(hWnd, &rWnd);
switch(msg)
{
case WM_PAINT:
// I could/should put GetWindowRect() here..
hDC = BeginPaint(hWnd, &ps);
hp353535 = CreatePen(PS_SOLID, 7, RGB(247, 247, 247));
SelectObject(hDC, hp353535);
MoveToEx(hDC, rWnd.left, rWnd.top, 0);
LineTo(hDC, rWnd.right, rWnd.top);
LineTo(hDC, rWnd.right, rWnd.bottom);
LineTo(hDC, rWnd.left, rWnd.bottom);
LineTo(hDC, rWnd.left, rWnd.top);
DeleteObject(hp353535);
EndPaint(hWnd, &ps);
break;
// More cases
}
}
Upvotes: 1
Views: 1097
Reputation: 17444
GetWindowRect() returns screen coordinates, while drawing uses client coordinates (i.e. relative to the upper-left corner of your window). I think using GetClientRect() helps.
Upvotes: 4