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. How to Load Image from Toolbar BMP resources for MenuItem icons ?

How to Load Image from Toolbar BMP resources for MenuItem icons ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicshelptutorial
9 Posts 4 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 am drawing Owner Draw Menu Icons. For that I want to use Toolbar bmp images as Menu Item icons. I used LoadImage to Find the Icons from Resources Like this

    hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), resName, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED);

    And it is working fine. But for this I need to Define All new Icons with same name as MenuItem in resources.
    That's, why I want to Load it from Toolbar bmp resources inspite of Icon Resources.
    How can I load Image in same manner by name from Toolbar bmp ?

    Any Help will be Appreciated. Regards Yogesh

    C _ _ 3 Replies Last reply
    0
    • 0 002comp

      Hello Friends I am drawing Owner Draw Menu Icons. For that I want to use Toolbar bmp images as Menu Item icons. I used LoadImage to Find the Icons from Resources Like this

      hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), resName, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED);

      And it is working fine. But for this I need to Define All new Icons with same name as MenuItem in resources.
      That's, why I want to Load it from Toolbar bmp resources inspite of Icon Resources.
      How can I load Image in same manner by name from Toolbar bmp ?

      Any Help will be Appreciated. Regards Yogesh

      C Offline
      C Offline
      Coder Block
      wrote on last edited by
      #2

      Basically, MFC is quit strong to handle all this things enternally, you only need to do is that give same ID to toolbar and menubar item. Like, If you have PQR.bmp on ID_CLICK_ME toolbar then give ID_CLICK_ME to menu bar item so it directly taken POR.bmp as menubar bitmap.

      0 1 Reply Last reply
      0
      • C Coder Block

        Basically, MFC is quit strong to handle all this things enternally, you only need to do is that give same ID to toolbar and menubar item. Like, If you have PQR.bmp on ID_CLICK_ME toolbar then give ID_CLICK_ME to menu bar item so it directly taken POR.bmp as menubar bitmap.

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

        Thanks For your Reply. Actually , I am giving toolbar single bmp name to MenuItem. For Example. ToolBar name is IDR_TOOLBAR1 which consist of images whose names are ID_FILE_NEW,ID_FILE_OPEN. And Under Menu IDR_MENU1 have menuItems New,Open with ID ID_FILE_NEW and ID_FILE_OPEN same as in toolbar bmp. And Used same LoadImage function to load Icon but returning NULL. Or am I doing something Wrong? Regards y

        C 1 Reply Last reply
        0
        • 0 002comp

          Thanks For your Reply. Actually , I am giving toolbar single bmp name to MenuItem. For Example. ToolBar name is IDR_TOOLBAR1 which consist of images whose names are ID_FILE_NEW,ID_FILE_OPEN. And Under Menu IDR_MENU1 have menuItems New,Open with ID ID_FILE_NEW and ID_FILE_OPEN same as in toolbar bmp. And Used same LoadImage function to load Icon but returning NULL. Or am I doing something Wrong? Regards y

          C Offline
          C Offline
          Coder Block
          wrote on last edited by
          #4

          why are you not trying this??

          CImage image;
          image.Load(_T("C:\\image.png")); // just change extension to load jpg
          CBitmap bitmap;
          bitmap.Attach(image.Detach());

          0 1 Reply Last reply
          0
          • 0 002comp

            Hello Friends I am drawing Owner Draw Menu Icons. For that I want to use Toolbar bmp images as Menu Item icons. I used LoadImage to Find the Icons from Resources Like this

            hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), resName, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED);

            And it is working fine. But for this I need to Define All new Icons with same name as MenuItem in resources.
            That's, why I want to Load it from Toolbar bmp resources inspite of Icon Resources.
            How can I load Image in same manner by name from Toolbar bmp ?

            Any Help will be Appreciated. Regards Yogesh

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            The new CMFCMenuBar class already does this for you. To use this class you will need Visual Studio 2008 with Feature pack or VS 2010 and later.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++) (October 2009 - September 2013)

            Polymorphism in C

            0 1 Reply Last reply
            0
            • 0 002comp

              Hello Friends I am drawing Owner Draw Menu Icons. For that I want to use Toolbar bmp images as Menu Item icons. I used LoadImage to Find the Icons from Resources Like this

              hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), resName, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED);

              And it is working fine. But for this I need to Define All new Icons with same name as MenuItem in resources.
              That's, why I want to Load it from Toolbar bmp resources inspite of Icon Resources.
              How can I load Image in same manner by name from Toolbar bmp ?

              Any Help will be Appreciated. Regards Yogesh

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              Another solution you can find here[^] ....

              0 1 Reply Last reply
              0
              • _ _Superman_

                The new CMFCMenuBar class already does this for you. To use this class you will need Visual Studio 2008 with Feature pack or VS 2010 and later.

                «_Superman_»  _I love work. It gives me something to do between weekends.

                _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                Polymorphism in C

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

                How Can I use CMFCMenuBar to load Images from Toolbar. As I am already using CMenu. Do I need to get CMFCMenubar object OnInitmenuPopup? or Some other way . I am confused about using CMFCMenubar. Regards Y

                1 Reply Last reply
                0
                • _ _Flaviu

                  Another solution you can find here[^] ....

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

                  Thanks Flaviu2 But I saw this Post already. here it is just conversion from ICon to bitmap. And My problem is to first Find out the Icons from Resources by name from either toolbar bmp .

                  1 Reply Last reply
                  0
                  • C Coder Block

                    why are you not trying this??

                    CImage image;
                    image.Load(_T("C:\\image.png")); // just change extension to load jpg
                    CBitmap bitmap;
                    bitmap.Attach(image.Detach());

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

                    If I try this way then I have to load each and every image for Menuitems again single by single. I am looking for a way to use from Toolbar bmp into MenuItems Icons. So,only I am accessing over resources by name to match with same menuitem Icon. Anyway,thanks For ideas. But ,better if I use from toolbar bmp. Y

                    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