想用纯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的
但是
第一,标题栏按钮还是没显示出来?
第二,窗口置于底层就原型毕露了?
第三,标题栏如何用位图填充?