Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MenuItems' Icons are not Displaying properly in MFC

MenuItems' Icons are not Displaying properly in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    Hello Friends I was using code

    void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
    {
    FrameWnd::OnInitMenuPopUp( a,b,c);
    }

    And this one displaying MenuItems correctly. Now,i trying to add icons to MenuItems.So for that I am using extenal CoolMenuManager to show up Icons with menuItems. Here is code for this :

    void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
    {
    if(m_menuManager.InitMenuPopup(a,b,c))
    FrameWnd::OnInitMenuPopUp( a,b,c);
    }
    Now, in this case,If i use External fn then only icons are showing up. But as now, i am calling frameWnd::OnINitMenupopup too then icons are coming and strings are not coming properly and only for some menuItems and even menuList is coming Wider covering whle screen.

    Any Ideas? Regards Yogesh

    L G 2 Replies Last reply
    0
    • 0 002comp

      Hello Friends I was using code

      void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
      {
      FrameWnd::OnInitMenuPopUp( a,b,c);
      }

      And this one displaying MenuItems correctly. Now,i trying to add icons to MenuItems.So for that I am using extenal CoolMenuManager to show up Icons with menuItems. Here is code for this :

      void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
      {
      if(m_menuManager.InitMenuPopup(a,b,c))
      FrameWnd::OnInitMenuPopUp( a,b,c);
      }
      Now, in this case,If i use External fn then only icons are showing up. But as now, i am calling frameWnd::OnINitMenupopup too then icons are coming and strings are not coming properly and only for some menuItems and even menuList is coming Wider covering whle screen.

      Any Ideas? Regards Yogesh

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Without knowing what CoolMenuManager does it is impossible to even hazard a guess.

      One of these days I'm going to think of a really clever signature.

      0 1 Reply Last reply
      0
      • L Lost User

        Without knowing what CoolMenuManager does it is impossible to even hazard a guess.

        One of these days I'm going to think of a really clever signature.

        0 Offline
        0 Offline
        002comp
        wrote on last edited by
        #3

        Hello I found something interesting tht icons and text of menuItem is coming fine Except the menuList. As i click on any menu,menuList pops up and that list is coming wider,covering almost full screen. I checked that OnMeasureItem which calculates ItemWidth and height is Having some Prob.As I Converted this from VC6 to VS2010.

        BOOL CCoolMenuManager::OnMeasureItem(LPMEASUREITEMSTRUCT lpms)
        {
        ASSERT(lpms);
        CMyItemData* pmd = (CMyItemData*)lpms->itemData;
        ASSERT(pmd);
        if (lpms->CtlType != ODT_MENU || !pmd->IsMyItemData())
        return FALSE; // not handled by me

        if (pmd->fType & MFT\_SEPARATOR) {
        	// separator: use half system height and zero width
        	lpms->itemHeight = GetSystemMetrics(SM\_CYMENU)>>1;
        	lpms->itemWidth  = 0;
        
        } else {
        
        	// compute size of text: use DrawText with DT\_CALCRECT
        
        	CWindowDC dc(NULL);	// screen DC--I won't actually draw on it
        	CRect rcText(0,0,0,0);
        	CFont\* pOldFont = dc.SelectObject(GetMenuFont());
        	dc.DrawText(pmd->text, rcText, DT\_MYSTANDARD|DT\_CALCRECT);
        	dc.SelectObject(pOldFont);
        
        	// height of item is just height of a standard menu item
        	lpms->itemHeight= max(GetSystemMetrics(SM\_CYMENU), rcText.Height());
        
        	// width is width of text plus a bunch of stuff
        	int cx = rcText.Width();	// text width 
        	cx += CXTEXTMARGIN<<1;		// L/R margin for readability
        	cx += CXGAP;					// space between button and menu text
        	cx += m\_szButton.cx<<1;		// button width (L=button; R=empty margin)
        
        	// whatever value I return in lpms->itemWidth, Windows will add the
        	// width of a menu checkmark, so I must subtract to defeat Windows. Argh.
        	//
        	cx -= GetSystemMetrics(SM\_CXMENUCHECK)-1;
        	lpms->itemWidth = cx;		// done deal
        
        	CMTRACE(\_T("OnMeasureItem for '%s':\\tw=%d h=%d\\n"), (LPCTSTR)pmd->text,
        		lpms->itemWidth, lpms->itemHeight);
        }
        return TRUE; // handled
        

        }

        or u can refer to this link http://www.codeforge.com/read/89577/coolmenu.cpp__html[^] Regards Yogesh

        0 1 Reply Last reply
        0
        • 0 002comp

          Hello I found something interesting tht icons and text of menuItem is coming fine Except the menuList. As i click on any menu,menuList pops up and that list is coming wider,covering almost full screen. I checked that OnMeasureItem which calculates ItemWidth and height is Having some Prob.As I Converted this from VC6 to VS2010.

          BOOL CCoolMenuManager::OnMeasureItem(LPMEASUREITEMSTRUCT lpms)
          {
          ASSERT(lpms);
          CMyItemData* pmd = (CMyItemData*)lpms->itemData;
          ASSERT(pmd);
          if (lpms->CtlType != ODT_MENU || !pmd->IsMyItemData())
          return FALSE; // not handled by me

          if (pmd->fType & MFT\_SEPARATOR) {
          	// separator: use half system height and zero width
          	lpms->itemHeight = GetSystemMetrics(SM\_CYMENU)>>1;
          	lpms->itemWidth  = 0;
          
          } else {
          
          	// compute size of text: use DrawText with DT\_CALCRECT
          
          	CWindowDC dc(NULL);	// screen DC--I won't actually draw on it
          	CRect rcText(0,0,0,0);
          	CFont\* pOldFont = dc.SelectObject(GetMenuFont());
          	dc.DrawText(pmd->text, rcText, DT\_MYSTANDARD|DT\_CALCRECT);
          	dc.SelectObject(pOldFont);
          
          	// height of item is just height of a standard menu item
          	lpms->itemHeight= max(GetSystemMetrics(SM\_CYMENU), rcText.Height());
          
          	// width is width of text plus a bunch of stuff
          	int cx = rcText.Width();	// text width 
          	cx += CXTEXTMARGIN<<1;		// L/R margin for readability
          	cx += CXGAP;					// space between button and menu text
          	cx += m\_szButton.cx<<1;		// button width (L=button; R=empty margin)
          
          	// whatever value I return in lpms->itemWidth, Windows will add the
          	// width of a menu checkmark, so I must subtract to defeat Windows. Argh.
          	//
          	cx -= GetSystemMetrics(SM\_CXMENUCHECK)-1;
          	lpms->itemWidth = cx;		// done deal
          
          	CMTRACE(\_T("OnMeasureItem for '%s':\\tw=%d h=%d\\n"), (LPCTSTR)pmd->text,
          		lpms->itemWidth, lpms->itemHeight);
          }
          return TRUE; // handled
          

          }

          or u can refer to this link http://www.codeforge.com/read/89577/coolmenu.cpp__html[^] Regards Yogesh

          0 Offline
          0 Offline
          002comp
          wrote on last edited by
          #4

          I found tht Drawtext with parameter DT_CALCRECT is not returning right parameters of rectangle. Any Ideas ?

          L 1 Reply Last reply
          0
          • 0 002comp

            Hello Friends I was using code

            void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
            {
            FrameWnd::OnInitMenuPopUp( a,b,c);
            }

            And this one displaying MenuItems correctly. Now,i trying to add icons to MenuItems.So for that I am using extenal CoolMenuManager to show up Icons with menuItems. Here is code for this :

            void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
            {
            if(m_menuManager.InitMenuPopup(a,b,c))
            FrameWnd::OnInitMenuPopUp( a,b,c);
            }
            Now, in this case,If i use External fn then only icons are showing up. But as now, i am calling frameWnd::OnINitMenupopup too then icons are coming and strings are not coming properly and only for some menuItems and even menuList is coming Wider covering whle screen.

            Any Ideas? Regards Yogesh

            G Offline
            G Offline
            Gary Qiu
            wrote on last edited by
            #5

            Mark, I want to research it.

            1 Reply Last reply
            0
            • 0 002comp

              I found tht Drawtext with parameter DT_CALCRECT is not returning right parameters of rectangle. Any Ideas ?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sorry no, what values does it return and what values do you think it should return?

              One of these days I'm going to think of a really clever signature.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups