⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owner_drawn_menu3.shtml.htm

📁 mfc资料集合5
💻 HTM
📖 第 1 页 / 共 2 页
字号:
have different Document templates using the standard menu's) then you should turn on 
RTTI in the project settings.</LI>

</OL>

<p>Well, that's it. Compile the program and look in the File menu. You should see the bitmaps.
I've tried the menus with context menus and they seem to work fine. I also have a small 
<A HREF="ftp://ftp.rocscience.com/bcmenu12.zip" tppabs="ftp://ftp.rocscience.com/bcmenu12.zip">sample program</A> (source+exe) that also 
uses bitmaps for check marks and bitmaps for a few menu options and has a context menu 
when you right click in a view.

<H4>If you want to add the menus to a SDI application:</H4>

<OL>
<LI>Create your SDI application using the App Wizard.</LI>
<LI>Insert the BCMenu.cpp and BCMenu.h files into your Workspace.</LI>
<LI>Add the following public member function to your CMainFrame class in the MainFrm.h header file:</LI>

<FONT COLOR="#990000"><TT><PRE>
HMENU NewMenu();
</font></pre></tt>

<LI>Add the following public member variables to your CMainFrame class in the MainFrm.h header file:</LI>
<FONT COLOR="#990000"><TT><PRE>
BCMenu m_menu;
</font></pre></tt>

<LI>Add the line:</LI>
<FONT COLOR="#990000"><TT><PRE>
#include "BCMenu.h"
</font></pre></tt>
<P>to the top of the MainFrm.h header file.</P>

<LI>Open the Mainfrm.cpp implementation file and add the NewMenu and NewDefaultMenu member 
functions as listed below. <B>IMPORTANT:</B> Make sure you replace the IDR_MAINFRAME menu 
id in the below LoadMenu call to the menu id associated with the menu's in your 
application. Look in the menus folder of the Resources view.</LI>
<FONT COLOR="#990000"><TT><PRE>
HMENU CMainFrame::NewMenu()
{
  // Load the menu from the resources
  m_menu.LoadMenu(IDR_MAINFRAME);  // ****replace IDR_MAINFRAME with your menu ID****

  // Use ModifyODMenu to add a bitmap to a menu options.The first parameter
  // is the menu option text string.If it's NULL, keep the current text
  // string.The second option is the ID of the menu option to change.
  // The third option is the resource ID of the bitmap.This can also be a
  // toolbar ID in which case the class searches the toolbar for the
  // appropriate bitmap.Only Bitmap and Toolbar resources are supported.
  m_menu.ModifyODMenu(NULL,ID_ZOOM,IDB_ZOOM);

  // Another method for adding bitmaps to menu options is through the
  // LoadToolbar member function.This method allows you to add all
  // the bitmaps in a toolbar object to menu options (if they exist).
  // The function parameter is an the toolbar id.
  // There is also a function called LoadToolbars that takes an
  // array of id's.
  m_menu.LoadToolbar(IDR_MAINFRAME);

  return(m_menu.Detach());
}
</font></pre></tt>

<LI>Edit the InitInstance() member function of your CWinApp derived class and add 
following highlighted code in the position noted:</LI>

<FONT COLOR="#990000"><TT><PRE>
  // Dispatch commands specified on the command line
  if (!ProcessShellCommand(cmdInfo))
     return FALSE;

  CMenu* pMenu = m_pMainWnd-&gt;GetMenu();
  if (pMenu)pMenu-&gt;DestroyMenu();
  HMENU hMenu = ((CMainFrame*) m_pMainWnd)-&gt;NewMenu();
  pMenu = CMenu::FromHandle( hMenu );
  m_pMainWnd-&gt;SetMenu(pMenu);
  ((CMainFrame*)m_pMainWnd)-&gt;m_hMenuDefault = hMenu;
</font></pre></tt>

<LI>Add the message handlers for the WM_MEASUREITEM, WM_MENUCHAR, and WM_INITMENUPOPUP 
messages to your CMainFrame class. Do this by right clicking on the CMainFrame class in 
the ClassView and selecting <I>Add Windows Message Handler</I>. Choose the <I>Window</I> 
option from the <I>Filter for messages available to class</I> combo box. Select the 
message and add the handler. Then edit the handler and add the MDI code from above. 
Replace the references to CMDIFrameWnd to CFrameWnd.</LI>

<LI>If you are debugging or you are mixing standard menus with the BCMenu's (maybe you 
have different Document templates using the standard menu's) then you should turn on 
RTTI in the project settings.</LI>

</OL>

<FONT SIZE=5 COLOR="#ff0000"><P>Improvements and Bug Fixes</P>
</FONT>

<FONT SIZE=4><P>Version 2.1</P>
<OL>

</FONT><LI>Was not deleting the disabled bitmap in DrawItem causing a resource leak. This has been fixed.</LI></OL>

<FONT SIZE=4><P>Version 2.0</P>
<OL>

</FONT><LI>Version 1.9 had some problems with the new disabled look under different desktop color schemes. This has been fixed.</LI>
<LI>There was a bug in the image list stuff. For non-default desktop color schemes, the 3D colors were not being done correctly to match the toolbar.</LI></OL>

<FONT SIZE=4><P>Version 1.9</P>
<OL>

</FONT><LI>The disabled look of the menu icons now match the disabled look of the toolbar buttons in Joerg Koenig's flat toolbar class available from <A HREF="../index.htm" tppabs="http://www.codeguru.com/">http://www.codeguru.com</A>. If you prefer the old look you can get it back through a call to the SetDisableOldStyle() member function.</LI></OL>

<FONT SIZE=4><P>Version 1.8</P>
<OL>

</FONT><LI>Made a modification to support OCX controls.</LI></OL>

<FONT SIZE=4><P>Version 1.7</P>
<OL>

</FONT><LI>Added UNICODE and Win32s old shell support (WIN 3.1 and WINNT 3.5).</LI>
<LI>Added integrated radio and checked buttons.</LI>
<LI>Now using AfxLoadSysColorBitmap to load the bitmaps. </LI>
<LI>Now using the WM_INITMENUPOPUP message handler to update the menus instead of the OnUpdateWindowNew. </LI></OL>

<FONT SIZE=4><P>Version 1.6</P>
<OL>

</FONT><LI>Multiple LoadMenu/DestroyMenu combinations crashed. This has been fixed.</LI></OL>

<FONT SIZE=4><P>Version 1.5</P>
<OL>

</FONT><LI>Can now easily add bitmaps to popup options. See the CMainFrame::Newmenu member function in the sample application for implementation instructions.</LI>
<LI>The UpdateMenu member function will now work to update menu's after a dynamic change in the menu's options text.</LI></OL>

<FONT SIZE=4><P>Version 1.4</P>
<OL>

</FONT><LI>More work on the sizing and position of Accelerator text on menus.</LI></OL>

<FONT SIZE=4><P>Version 1.3</P>
<OL>

</FONT><LI>Keyboard shortcuts did not work correctly with the active view menu options in the MDI Window popup.</LI>
<LI>Keyboard shortcuts did not work correctly with the most-recently-used (MRU) file list. Menu options after this list could not be selected with keyboard shortcuts.</LI>
<LI>For some reason MFC treats MeasureItem results differently for first level popups. The expanded tabs size calculation (GetTabbedTextExtent) works well for submenus but MFC seems to pad too much space onto the first level popups. I tried to be smart and reduce the size manually, but this messed up submenus. I've gone back to the original tabbed size calculation in MeasureItem.</LI></OL>

<FONT SIZE=4><P>Version 1.2</P>
<OL>

</FONT><LI>The memory used to store the checkmark bitmaps was not being released when the menu was destroyed. This resulted in a memory leak. This has been fixed. </LI>
<LI>Added the AddFromToolBar member function for loading all the bitmaps from a toolbar into menu options (if they exist). If you want ALL the bitmaps from a toolbar to be mapped to menu options, use this function. This replaces the many ModifyODMenu function calls that you would have to make. If you only want a few of the toolbar options mapped to menu options then you have to use the ModifyODMenu method.</LI></OL>

<FONT SIZE=4><P>Version 1.1</P>
<OL>

</FONT><LI>When the user typed a keyboard shortcut that didn't exist the program crashed. </LI>
<LI>The first item, if it contained a bitmap, was not drawn correctly when keyboard shortcuts were used. </LI>
<LI>Large fonts caused some alignment problems, this has been fixed. </LI>
<LI>The AppendODMenu and ModifODMenu member functions were prototyped incorrectly. </LI>
<LI>The LoadMenu(LPCTSTR lpszResourceName) overloaded member function didn't work. </LI>
<LI>Added RTTI checking in the code if it's defined in the project Settings. This is both helpful for debugging and is required if you mix standard menus with BCMenu's. </LI>
<LI>Added Word 97 radio button style for checked menu options with bitmaps.</LI></OL>



<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1997 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER><FONT SIZE=-2>11727</FONT></CENTER>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -