NCpaint, 非客戶區實現陰影
如何改變單文件的標題顏色?|||在OnNcPaint 中呼叫 drawtext
記住DC要用 CWindowDC。|||最近樓主在VC區比較活躍!!
快速進步中的菜鳥!|||
|||WM_NCPAINT|||OnNcPaint 就是 WM_NCPAINT 的訊息響應函式。你響應一下WM_NCPAINT 。在訊息響應函式裡面畫標題的顏色就行了。|||WM_NCPAINT 手動新增?我是在CMainFrame哦,沒有看到WM_NCPAINT阿|||
void CMainFrame::DrawTitleBar(CDC *pDC)
{
if (m_hWnd)
{
CBrush Brush(RGB(0,0,0));
CBrush* pOldBrush = pDC-SelectObject(Brush);
CRect rtWnd, rtTitle, rtButtons;
GetWindowRect(rtWnd);
CPoint point;
//填充頂部框架
point.x = rtWnd.Width();
point.y = GetSystemMetrics(SM_CYSIZE) GetSystemMetrics(SM_CYFRAME) 1;
pDC-PatBlt(0, 0, point.x, point.y, PATCOPY);
//填充左側框架
point.x = GetSystemMetrics(SM_CXFRAME);
point.y = rtWnd.Height();
286it網
pDC-PatBlt(0, 0, point.x, point.y, PATCOPY);
}
}
//訊息響應
LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT lrst=CFrameWnd::DefWindowProc(message, wParam, lParam);
if (!::IsWindow(m_hWnd))
return lrst;
if (message == WM_MOVE || message == WM_NCPAINT ||message == WM_NCACTIVATE ||message == WM_NOTIFY)
{
CDC* pWinDC = GetWindowDC();
if (pWinDC)
DrawTitleBar(pWinDC);
ReleaseDC(pWinDC);
}
return lrst;
}
________________________________________________________________
在處理WM_NCPAINT的基礎上,加上
void CXXXXXDlg::OnInitMenu(CMenu* pMenu)
{
CDialog::OnInitMenu(pMenu);
SendMessage(WM_NCPAINT);
}
LRESULT CXXXXXDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_NCHITTEST)
{
LRESULT lRet = CDialog::WindowProc(message, wParam, lParam);
if (lRet == HTZOOM || lRet == HTMINBUTTON || lRet == HTCLOSE)
return HTCAPTION;
else
return lRet;
}
else if (message == WM_SETCURSOR || message == WM_NCLBUTTONDOWN || message == WM_NCLBUTTONDBLCLK)
{
ModifyStyle(WS_SYSMENU, 0);
LRESULT lRet = CODDialog::WindowProc(message, wParam, lParam);
ModifyStyle(0, WS_SYSMENU);
return lRet;
}
return CDialog::WindowProc(message, wParam, lParam);
}
以避免對視窗標題的重畫
_____________________________________________________
在WM_NCPAINT繪圖前,先呼叫DefWindoProc處理訊息,然後繪圖。
繪製的時候,用GetTitleBarInfo獲得標題欄的高度,然後就能控制不在標題欄以外的地方繪圖了。比如:
case WM_NCPAINT:
{
DefWindowProc(hDlg, message, wParam, lParam);
HDC hdc;
hdc = GetWindowDC(hDlg);
// Paint into this DC
RECT rcDialog,rc;
GetWindowRect(hDlg, &rcDialog);
HBRUSH hbr = CreateSolidBrush(0);
rc.left = 0; rc.top = 0;
rc.right = rcDialog.right - rcDialog.left;
TITLEBARINFO tbi;
tbi.cbSize = sizeof(tbi);
GetTitleBarInfo(hDlg, &tbi);
rc.bottom = tbi.rcTitleBar.bottom - tbi.rcTitleBar.top;
HBRUSH hOldbr = SelectObject(hdc, hbr);
FillRect(hdc, &rc, hbr);
SelectObject(hdc, hOldbr);
DeleteObject(hbr);
ReleaseDC(hDlg, hdc);
return TRUE;
}
後來我用這些程式碼完成了這個功能。
這些程式碼是加在OnNcPaint函式裡面的。
//用下面這段程式碼讓選單顯示
CMenu * pMenu = GetMenu();