我希望能够在窗口的非客户区域的菜单栏右侧进行绘图.
这可能,使用C++/MFC?
查理打了个答案WM_NCPAINT
.如果您使用的是MFC,代码看起来像这样:
// in the message map ON_WM_NCPAINT() // ... void CMainFrame::OnNcPaint() { // still want the menu to be drawn, so trigger default handler first Default(); // get menu bar bounds MENUBARINFO menuInfo = {sizeof(MENUBARINFO)}; if ( GetMenuBarInfo(OBJID_MENU, 0, &menuInfo) ) { CRect windowBounds; GetWindowRect(&windowBounds); CRect menuBounds(menuInfo.rcBar); menuBounds.OffsetRect(-windowBounds.TopLeft()); // horrible, horrible icon-drawing code. Don't use this. Seriously. CWindowDC dc(this); HICON appIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); ::DrawIconEx(dc, menuBounds.right-18, menuBounds.top+2, appIcon, 0,0, 0, NULL, DI_NORMAL); ::DestroyIcon(appIcon); } }