非客户区重绘

来源:互联网 发布:网络虐狗是什么意思 编辑:程序博客网 时间:2024/05/29 17:14


我用C写的一个标题部分重绘的小程序。

在运行中发现程序的标题在非客户区上并不会重绘,像是被覆盖,在查阅资料后发现在WM_NCPAINT消息运行后应该return掉,阻止程序继续运行DefWindowProc函数

switch(uMsg){case WM_CREATE:{if(g_imgCaption.IsNull()){g_imgCaption.LoadFromResource((HINSTANCE)::GetModuleHandle(NULL), IDB_CAPTION);}}break;case WM_DESTROY:{PostQuitMessage(0);}break;case WM_NCPAINT:{if (::IsIconic(hWnd))break;HDC hDC = ::GetWindowDC(hWnd);assert(hDC);CRect rcWnd;GetWindowRect(hWnd, &rcWnd);CRect rcClient;::GetClientRect(hWnd, &rcClient);CRect rcCaption;rcCaption.left = 0;rcCaption.right = rcCaption.left + rcWnd.Width();rcCaption.top = 0;rcCaption.bottom = rcCaption.top + ( rcWnd.Height() - rcClient.Height() - (rcWnd.Width()-rcClient.Width())/2 );if (!g_imgCaption.IsNull()){g_imgCaption.Draw(hDC, rcCaption);}::ReleaseDC(hWnd, hDC);}return true;}return ::DefWindowProc(hWnd, uMsg, wParam, lParam);




初学者刚开始写博客。

0 0
原创粉丝点击