orbitgw 2022-04-17 00:17 采纳率: 72.7%
浏览 32
已结题

如何使用纯win32api不使用MFC来自绘非客户区

想用纯winapi写一个美化桌面窗口,但是出现了很多小问题

case WM_NCPAINT:
    { 
        int tbheight, tbwidth;
        RECT wndrect, clientrect;
        GetWindowRect(hwnd, &wndrect);
        GetClientRect(hwnd, &clientrect);
        tbheight = GetSystemMetrics(SM_CYSIZE);//标题栏宽度
        //end 得到系统标题栏的信息
        //填充标题栏
        RECT rcWindow;
        GetWindowRect(hwnd, &rcWindow);
        HDC hDc = GetWindowDC(hwnd);
        HBRUSH hBrush = CreateSolidBrush(RGB(25, 0, 255));
        HBRUSH hOldbrush = (HBRUSH)SelectObject(hDc, (HGDIOBJ)hBrush);
        PatBlt(hDc, 0, 0, wndrect.right - wndrect.left, tbheight, PATCOPY);
        //end 填充标题栏
            //填充边框
        NONCLIENTMETRICS  nonmet;
        nonmet.cbSize = sizeof(NONCLIENTMETRICS);
        SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nonmet, 0);

        RECT borderleft, borderright, bordertop, borderbottom;
        borderleft.left = 0;
        borderleft.right = wndrect.left + 7;
        borderleft.top = tbheight;
        borderleft.bottom = wndrect.bottom;
        hBrush = CreateSolidBrush(RGB(200, 0, 0));
        SelectObject(hDc, (HGDIOBJ)hBrush);
        PatBlt(hDc, borderleft.left, borderleft.top, nonmet.iPaddedBorderWidth + 4, borderleft.bottom - borderleft.top, PATCOPY);
        SelectObject(hDc, (HGDIOBJ)hOldbrush);

        bordertop.left = 0;
        bordertop.bottom = wndrect.top + nonmet.iCaptionHeight + nonmet.iPaddedBorderWidth + 4;
        bordertop.right = wndrect.right;
        bordertop.top = nonmet.iCaptionHeight;
        hBrush = CreateSolidBrush(RGB(0, 200, 0));
        SelectObject(hDc, (HGDIOBJ)hBrush);
        PatBlt(hDc, bordertop.left, bordertop.top, bordertop.right - bordertop.left, nonmet.iPaddedBorderWidth + 5, PATCOPY);
        SelectObject(hDc, (HGDIOBJ)hOldbrush);

        borderright.left = wndrect.right - wndrect.left - nonmet.iPaddedBorderWidth - 4;
        borderright.top = nonmet.iCaptionHeight;
        borderright.bottom = wndrect.bottom;
        borderright.right = wndrect.right - wndrect.left;
        hBrush = CreateSolidBrush(RGB(0, 100, 200));
        SelectObject(hDc, (HGDIOBJ)hBrush);
        PatBlt(hDc, borderright.left, borderright.top, nonmet.iPaddedBorderWidth + 4, borderright.bottom - borderright.top, PATCOPY);


        borderbottom.bottom = wndrect.bottom;
        borderbottom.left = nonmet.iPaddedBorderWidth + 4;
        borderbottom.right = wndrect.right - wndrect.left - nonmet.iPaddedBorderWidth - 4;
        borderbottom.top = wndrect.bottom - wndrect.top - nonmet.iPaddedBorderWidth - 4;
        hBrush = CreateSolidBrush(RGB(100, 80, 80));
        SelectObject(hDc, (HGDIOBJ)hBrush);
        PatBlt(hDc, borderbottom.left, borderbottom.top, borderbottom.right - borderbottom.left, nonmet.iPaddedBorderWidth + 4, PATCOPY);
        //end 填充边框
        SelectObject(hDc, (HGDIOBJ)hOldbrush);
        ReleaseDC(hwnd, hDc);
        //DefWindowProc(hwnd,uMsg,wParam,lParam);
        RECT btnrect;
        btnrect.bottom = nonmet.iCaptionHeight + nonmet.iBorderWidth;
        btnrect.left = wndrect.right - wndrect.left - nonmet.iCaptionHeight * 3 - nonmet.iBorderWidth;
        btnrect.right = btnrect.left + nonmet.iCaptionHeight * 3;
        btnrect.top = nonmet.iBorderWidth;

        HDC hcomdc = CreateCompatibleDC(hDc);
        HBITMAP hbmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BITMAP));
        HBITMAP holdbmp = (HBITMAP)SelectObject(hcomdc, (HGDIOBJ)hbmp);
        StretchBlt(hDc, btnrect.left - nonmet.iPaddedBorderWidth - 14, btnrect.top + nonmet.iPaddedBorderWidth + 4, nonmet.iCaptionHeight * 3 + 12, nonme  t.iCaptionHeight, hcomdc, 0, 0, 60, 20, SRCCOPY);

源码是参考https://www.cnblogs.com/ddx-deng/p/3755833.html
但是
第一,标题栏按钮还是没显示出来?
第二,窗口置于底层就原型毕露了?
第三,标题栏如何用位图填充?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 4月25日
    • 创建了问题 4月17日

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?