用GDI在我的窗口周围绘制边框不起作用?

时间:2013-01-26 13:30:58

标签: c++ windows winapi border gdi

我正试图在我的窗口周围画一个边框,但我的代码似乎不起作用。它没有任何吸引力。谁能告诉我它有什么问题?

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
    }
}

1 个答案:

答案 0 :(得分:4)

GetWindowRect()返回屏幕坐标,而绘图使用客户端坐标(即相对于窗口的左上角)。我认为使用GetClientRect()有帮助。