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. Simple Menus That Display Icons in Win32 API (No MFC)

Simple Menus That Display Icons in Win32 API (No MFC)

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonhelp
4 Posts 2 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.
  • A Offline
    A Offline
    Aabid
    wrote on last edited by
    #1

    Hello Friends my task is to append icons to menu (ie .ico), it is very easy to add bmp file to menu, but in order to need transparency i have to use icons only not bmps. There are lots of programs for this in MFC , but i need to do it in Win32 API using VC++ Any help is greatly appreciated

    D 1 Reply Last reply
    0
    • A Aabid

      Hello Friends my task is to append icons to menu (ie .ico), it is very easy to add bmp file to menu, but in order to need transparency i have to use icons only not bmps. There are lots of programs for this in MFC , but i need to do it in Win32 API using VC++ Any help is greatly appreciated

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Aabid wrote:

      There are lots of programs for this in MFC , but i need to do it in Win32 API

      Knowing that MFC is just a thin wrapper around the Win32 API, you should be able to look at the MFC code to tell what MFC is doing, and pick out the relevant parts.

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      A 1 Reply Last reply
      0
      • D David Crow

        Aabid wrote:

        There are lots of programs for this in MFC , but i need to do it in Win32 API

        Knowing that MFC is just a thin wrapper around the Win32 API, you should be able to look at the MFC code to tell what MFC is doing, and pick out the relevant parts.

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        A Offline
        A Offline
        Aabid
        wrote on last edited by
        #3

        Hi david can u guide me how to convert this function to Win32 API, ie how can i handle this function as message void CMainFrame::OnInitMenu(CMenu* pMenu) { #if _MFC_VER < 0x0800 #undef __FUNCTION__ #define __FUNCTION__ "OnInitMenu()" #endif // _MFC_VER < 0x0800 AfxTrace(_T(__FUNCTION__) _T(": %#0x\n"), pMenu->GetSafeHmenu()); MENUITEMINFO minfo; minfo.cbSize = sizeof(minfo); for (UINT pos=0; pos<pMenu->GetMenuItemCount(); pos++) { minfo.fMask = MIIM_FTYPE | MIIM_ID; pMenu->GetMenuItemInfo(pos, &minfo, TRUE); HICON hIcon = GetIconForItem(minfo.wID); if (hIcon && !(minfo.fType & MFT_OWNERDRAW)) { AfxTrace(_T("replace for id=%#0x\n"), minfo.wID); minfo.fMask = MIIM_FTYPE | MIIM_BITMAP; minfo.hbmpItem = HBMMENU_CALLBACK; minfo.fType = MFT_STRING; ::SetMenuItemInfo(pMenu->GetSafeHmenu(), pos, TRUE, &minfo); } else AfxTrace(_T("keep for id=%#0x\n"), minfo.wID); // ::DestroyIcon(hIcon); // we use LR_SHARED instead } } We Have To Conert it into case WM_INITMENU:

        D 1 Reply Last reply
        0
        • A Aabid

          Hi david can u guide me how to convert this function to Win32 API, ie how can i handle this function as message void CMainFrame::OnInitMenu(CMenu* pMenu) { #if _MFC_VER < 0x0800 #undef __FUNCTION__ #define __FUNCTION__ "OnInitMenu()" #endif // _MFC_VER < 0x0800 AfxTrace(_T(__FUNCTION__) _T(": %#0x\n"), pMenu->GetSafeHmenu()); MENUITEMINFO minfo; minfo.cbSize = sizeof(minfo); for (UINT pos=0; pos<pMenu->GetMenuItemCount(); pos++) { minfo.fMask = MIIM_FTYPE | MIIM_ID; pMenu->GetMenuItemInfo(pos, &minfo, TRUE); HICON hIcon = GetIconForItem(minfo.wID); if (hIcon && !(minfo.fType & MFT_OWNERDRAW)) { AfxTrace(_T("replace for id=%#0x\n"), minfo.wID); minfo.fMask = MIIM_FTYPE | MIIM_BITMAP; minfo.hbmpItem = HBMMENU_CALLBACK; minfo.fType = MFT_STRING; ::SetMenuItemInfo(pMenu->GetSafeHmenu(), pos, TRUE, &minfo); } else AfxTrace(_T("keep for id=%#0x\n"), minfo.wID); // ::DestroyIcon(hIcon); // we use LR_SHARED instead } } We Have To Conert it into case WM_INITMENU:

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          See here. Googling for such will also turn up dozens of examples.

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          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