如何在非客户区绘图?

How to draw in the nonclient area?(如何在非客户区绘图?)

本文介绍了如何在非客户区绘图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在窗口的非客户区中的菜单栏右侧进行一些绘图.

I'd like to be able to do some drawing to the right of the menu bar, in the nonclient area of a window.

这可能吗,使用 C++/MFC?

Is this possible, using C++ / MFC?

推荐答案

Charlie 用 WM_NCPAINT 找到了答案.如果您使用的是 MFC,代码将如下所示:

Charlie hit on the answer with WM_NCPAINT. If you're using MFC, the code would look something like this:

// 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);
   }
}

这篇关于如何在非客户区绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在非客户区绘图?

基础教程推荐