如何处理非用户区的消息,列如如果我要在标题栏画上自己的颜色,该怎么办,有人说要处理WM_NCPAINT消息,可是在类向导中找不到这个消息,不知如何处理,能不能给一小段代码的例子。谢谢!
解决方案 »
- win32程序,设置了WS_SYSMENU属性,如何去掉任务栏的右键菜单?
- 经理说要我的软件配合硬件,要软件跟着硬件走,我想也是,但这下我难住了,大家看看!
- 控件问题
- 简单问题,过来看看!
- 急!高分求,怎么做自解压程序,还可以自动的打包资源到这个自解压程序。有例子更好
- 如何控制Lib文件的输出路径?
- 分别在debug,release模式下运行有什么区别,那位大大能给我讲讲个子怎么回事么?
- ★我想把一些图片,声音资源都集成在一个.DLL中(因为不想用户看到),应该如何做?在线等,急
- 请指教:是否有API可以获取目录的大小
- 要分的请过来
- COM @ wince.net+SAPI 遇到的问题
- 如果调用其它程序??在线等待
至于标题栏,给你个例子吧,在这个例子里,我在标题栏上多添了一个按钮。
void CResizableMiniDockFrameWnd::OnNcPaint()
{
CWindowDC dc(this); CRect rectClient(0,0,0,0);
GetClientRect(rectClient);
CRect rectWindow(0,0,0,0);
GetWindowRect(rectWindow);
ScreenToClient(rectWindow);
rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
dc.ExcludeClipRect(rectClient);
rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
CSize sizeFrame(GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME));
CSize sizeBorder(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
CSize sizeSmIcon(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
CMemoryDC dcMemory;
dcMemory.Create(&dc, rectWindow);
//边框
dcMemory.DrawEdge(&rectWindow, EDGE_RAISED, BF_RECT);
CRect rectCaption(rectWindow);
rectCaption.DeflateRect(sizeFrame.cx, sizeFrame.cy);
rectCaption.bottom = rectCaption.top + sizeSmIcon.cy - sizeBorder.cy;
//标题栏底色
BOOL bGradient = FALSE;
::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0);
COLORREF clrLeft = ::GetSysColor(COLOR_ACTIVECAPTION);
COLORREF clrRight = ::GetSysColor(COLOR_GRADIENTACTIVECAPTION);
COLORREF clrGray = ::GetSysColor(COLOR_INACTIVECAPTION);
if(bGradient && m_bActive)
{
int nShift = 6;
int nSteps = 1 << nShift;
for(int i=0; i<nSteps; ++i)
{
int nRed = (GetRValue(clrLeft) * (nSteps - i) + GetRValue(clrRight) * i) >> nShift;
int nGreen = (GetGValue(clrLeft) * (nSteps - i) + GetGValue(clrRight) * i) >> nShift;
int nBlue = (GetBValue(clrLeft) * (nSteps - i) + GetBValue(clrRight) * i) >> nShift;
CRect rect(rectCaption);
rect.left = rectCaption.left +((i * rectCaption.Width()) >> nShift);
rect.right = rectCaption.left +(((i + 1) * rectCaption.Width()) >> nShift);
if(rect.Width() > 0)
{
dcMemory.FillSolidRect(rect, RGB(nRed, nGreen, nBlue));
}
}
}
else
{
dcMemory.FillSolidRect(&rectCaption, m_bActive ? clrLeft:clrGray);
}
LOGFONT fontCaption = {0};
::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &fontCaption, 0);
fontCaption.lfWeight = FW_BOLD;
HFONT hCaptionFont = CreateFontIndirect(&fontCaption);
HGDIOBJ hOldFont = dcMemory.SelectObject(hCaptionFont);
dcMemory.SetTextColor(::GetSysColor(COLOR_CAPTIONTEXT));
dcMemory.SetBkMode(TRANSPARENT);
CString strCaption(_T(""));
GetWindowText(strCaption);
if(strCaption.IsEmpty())
{
strCaption = _T("ToolBar");
}
CSize sizeText(dcMemory.GetTextExtent(strCaption));
//输出文本(右端扣除Button所占的位置)
CRect rectText(rectCaption);
rectText.left += sizeBorder.cx * 2;
rectText.right -= sizeSmIcon.cx * 2 + sizeBorder.cx;
dcMemory.DrawText(strCaption, &rectText, DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS);
dcMemory.SelectObject(hOldFont);
DeleteObject(hCaptionFont);
DrawButton(&dcMemory, rectCaption);
dcMemory.Flush();
}
void CResizableMiniDockFrameWnd::DrawButton(CDC* pDC, CRect& rectCaption)
{
ASSERT_VALID(pDC);
CRect rectClose = rectCaption;
rectClose.top += 1;
rectClose.bottom = rectClose.top + 12;
rectClose.right -= 1;
rectClose.left = rectClose.right - 12;
CRect rectExpand = rectClose;
rectExpand.OffsetRect(-14,0);
//background
pDC->FillSolidRect(&rectClose, afxData.clrBtnFace);
pDC->FillSolidRect(&rectClose, afxData.clrBtnFace);
//close button
DrawFrameControl(pDC->GetSafeHdc(), rectClose, DFC_BUTTON,
DFCS_BUTTONPUSH|(m_btnClose.IsPushed()?DFCS_PUSHED:0));
CPoint pt = rectClose.TopLeft();
pt.Offset(m_btnClose.IsPushed()?2:1, m_btnClose.IsPushed()?2:1);
m_ImageList.Draw(pDC, m_btnClose.GetIcon(), pt, ILD_TRANSPARENT); //expand button
DrawFrameControl(pDC->GetSafeHdc(), rectExpand, DFC_BUTTON,
DFCS_BUTTONPUSH|(m_btnExpand.IsPushed()?DFCS_PUSHED:0));
pt = rectExpand.TopLeft();
pt.Offset(1,1);
m_ImageList.Draw(pDC, m_btnExpand.GetIcon(), pt, ILD_TRANSPARENT);
}
The WM_NCPAINT message is sent to a window when its frame must be painted. A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_NCPAINT
WPARAM wParam, // handle to update region (HRGN)
LPARAM lParam // not used
);
Parameters
wParam
Handle to the update region of the window. The update region is clipped to the window frame. When wParam is 1, the entire window frame needs to be updated.
lParam
This parameter is not used.
Return Values
An application returns zero if it processes this message. Res
The DefWindowProc function paints the window frame. An application can intercept the WM_NCPAINT message and paint its own custom window frame. The clipping region for a window is always rectangular, even if the shape of the frame is altered. The wParam value can be passed to GetDCEx as in the following example.case WM_NCPAINT:
{
HDC hdc;
hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
// Paint into this DC
ReleaseDC(hwnd, hdc);
}