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

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

最佳答案

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

关于c++ - 使用 GDI 在我的窗口周围绘制边框不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14537412/

相关文章:

c++ - GetProcessId 失败,错误 6 : The handle is invalid

c++ - 为什么模板函数不能是模板类的友元模板函数?

windows - 使用 Windows 7 计算器计算对数

windows - 如何使用 Delphi 检查字符串是否是有效的 Windows 文件夹名称?

Ruby on rails跨平台win/linux脚本

php - 发送文件 POST C++

c++ - 异步过程调用

c++ - 返回一个 shared_ptr

c++ - 需要帮助为 JNI 调用构建 DLL。 Unresolved external 引用。 Borland 编译器

C++ (gcc) 嵌套模板问题?