Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » add icon in CExtPopupMenuWnd Collapse All
Subject Author Date
L Freddi Jun 24, 2009 - 1:51 AM

Hi, supporters


I want to add icon beside menu string in CExtPopupMenuWnd.


Please give me function name, using sample.


thanks.

Technical Support Jun 24, 2009 - 12:54 PM

By default popup menu items are using the command descriptions stored in the command manager. So, you should update the command descriptions in the command manager with icons. You can use the g_CmdManager->UpdateFromToolBar() code (the CExtCmdManager::UpdateFromToolBar() method) for loading icons for all the required menu commands from the toolbar resource. This toolbar resource may be created for command manager only. It’s not necessary to use it with toolbar control. You can use the CExtCmdManager::CmdSetIcon() method for assigning/changing/removing icon of individual commands registered in the command manager.

If your popup menus uses menu command items which are not based on the command manager, then you should use the CExtPopupMenuWnd::ItemSetPopupIcon() method for assigning an icon to menu item.

The CExtPopupMenuWnd::ItemInsert() method inserts menu items which are based on the command manager. The CExtPopupMenuWnd::ItemInsertCommand() method inserts menu items which are not based on the command manager. By default the CExtPopupMenuWnd::LoadMenu() and CExtPopupMenuWnd::UpdateFromMenu() methods are initializing popup menu with menu command items which are based on the command manager because the bNoRefToCmdMngr parameter of these methods has the false flag as default parameter value.

L Freddi Jun 25, 2009 - 12:09 AM

thanks to your fast reply.


and I have three guestion.


As follow your direction, I made popup menu but had three problem.


================================================================

   CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;   

   pPopup->UpdateFromMenu(GetSafeHwnd(), &menu, true, true, true);


    CExtBitmap _bmp;

    VERIFY(_bmp.LoadBMP_Resource( MAKEINTRESOURCE(IDB_BITMAP_VIEW)));

    

    static const COLORREF clrTransparentPaint = RGB(255,0,255);

    static const CSize _sizeBitmapPartPaint(16,16);


    CPoint ptBitmapOffset(0, 0);

    CRect rcBitmapPart(ptBitmapOffset, _sizeBitmapPartPaint);

    CExtCmdIcon _icon;

    _icon.m_bmpNormal.FromBitmap(_bmp, &rcBitmapPart);

    ASSERT( ! _icon.IsEmpty() );

    _icon.m_bmpNormal.AlphaColor( clrTransparentPaint, RGB(0,0,0), 0 );

    pPopup->ItemSetPopupIcon(nPos, _icon);


====================================================================


1. Menu’s status don’t change.


ex) pCmdUI->Enable(FALSE); Menu don’t change to disable status.


I searched this board for answer, pPopup->UpdateFromMenu(GetSafeHwnd(), &menu, true, true, true); true->false.


But,  if bNoRefToCmdMngr is  false, ItemSetPopupIcon function don’t work.


2. I don’t know menu’s check status.


ex) pCmdUI->SetCheck(TRUE);  


3.Because icon replace on check , I want to know check status as differenct icon type.


as below source, Can CExtBitmap use CDib class? 


=====================================================

 DWORD tagImageMap[IB_NUMBER_OF_IMAGES] = {1,0,3,2,0};


 IB_MAP_OF_IMAGES tagIbMap;

 CDib clsDib;

clsDib.ReadFromFile(ICON_IMAGE);

 for (int i = 0; i < IB_NUMBER_OF_IMAGES; i++)

 {

   tagIbMap.adwImageOrder[i] = tagImageMap[i];

 }

============================================================


 


 

Technical Support Jun 28, 2009 - 10:44 AM

Frist of all, if the IDB_BITMAP_VIEW bitmap is not a 32-bit one, then you should invoke the CExtBitmap::Make32() method before invoking the CExtBitmap::AlphaColor() method.

Second, the CCmdUI::Enable() method is not invoked because entire command updating method is not invoked. The CExtPopupMenuWnd::UpdateFromMenu() method in your code snippet initializes popup menu with command items which are not based on the command manager. These command items are also not updated via MFC’s command updating mechanism. You absolutely correctly changed the bNoRefToCmdMngr parameter to false. Now your popup menu is based on the command manager. You should update the command manager from the menu resource at your application startup. Then you should update the command manager with icons like we described in our previous answer in this forum thread.

Third, the MFC’s command updating mechanism allows you to change the checked status of menu items and toolbar buttons but not to get the current checked status. The current checked status of any particular command should be kept in your application internally.

Fourth, we have no idea what is CDib class? May be it’s described here:

http://www.jomier.com/julien/projects/wst/Documentation/html/classCDIB.html

If this description is what is CDib class in your question, then you can get CBitmap from CDib and then invoke the CExtBitmap::FromBitmap() method.