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 do I load a 16x16 icon?

How do I load a 16x16 icon?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelplearning
9 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.
  • B Offline
    B Offline
    Barvus
    wrote on last edited by
    #1

    I'm trying to display a small icon in a CStatusBarCtrl. I created a 16x16 icon, IDI_X, in the resource editor, then I tried the following: HICON hIcon; hIcon = theApp.LoadIcon(MAKEINTRESOURCE(IDI_X)); m_wndSBC.SetIcon(0, hIcon); The icon is resized to 32x32 and doesn't fit in the status bar. The CApp::LoadIcon documentation says it can only be used to load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric. It says to use LoadImage instead. So, I tried this: HANDLE hIcon; hIcon = LoadImage(NULL, MAKEINTRESOURCE(IDI_X), IMAGE_ICON, 0, 0, 0); DWORD dwError; dwError = GetLastError(); That didn't work either. LoadImage returns NULL and GetLastError returns 1813: "The specified resource type cannot be found in the image file." Can anyone help?

    B M 2 Replies Last reply
    0
    • B Barvus

      I'm trying to display a small icon in a CStatusBarCtrl. I created a 16x16 icon, IDI_X, in the resource editor, then I tried the following: HICON hIcon; hIcon = theApp.LoadIcon(MAKEINTRESOURCE(IDI_X)); m_wndSBC.SetIcon(0, hIcon); The icon is resized to 32x32 and doesn't fit in the status bar. The CApp::LoadIcon documentation says it can only be used to load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric. It says to use LoadImage instead. So, I tried this: HANDLE hIcon; hIcon = LoadImage(NULL, MAKEINTRESOURCE(IDI_X), IMAGE_ICON, 0, 0, 0); DWORD dwError; dwError = GetLastError(); That didn't work either. LoadImage returns NULL and GetLastError returns 1813: "The specified resource type cannot be found in the image file." Can anyone help?

      B Offline
      B Offline
      Barvus
      wrote on last edited by
      #2

      Just an update. I got it to work by doing the following: HANDLE hIcon; hIcon = ::LoadImage(NULL, "res\\icon1.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE); m_wndSBC.SetIcon(0, (HICON) hIcon); But I'd still like to know why it didn't work the other way, if anyone can help. Thanks.

      1 Reply Last reply
      0
      • B Barvus

        I'm trying to display a small icon in a CStatusBarCtrl. I created a 16x16 icon, IDI_X, in the resource editor, then I tried the following: HICON hIcon; hIcon = theApp.LoadIcon(MAKEINTRESOURCE(IDI_X)); m_wndSBC.SetIcon(0, hIcon); The icon is resized to 32x32 and doesn't fit in the status bar. The CApp::LoadIcon documentation says it can only be used to load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric. It says to use LoadImage instead. So, I tried this: HANDLE hIcon; hIcon = LoadImage(NULL, MAKEINTRESOURCE(IDI_X), IMAGE_ICON, 0, 0, 0); DWORD dwError; dwError = GetLastError(); That didn't work either. LoadImage returns NULL and GetLastError returns 1813: "The specified resource type cannot be found in the image file." Can anyone help?

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        LoadIcon() can only load 32x32 icons. Specify the size in the LoadImage() call, 16x16 so the system knows which size you want. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Pinky, are you pondering what I'm pondering? I think so Brain, but how will we fit the hamster inside the accordion?

        B 1 Reply Last reply
        0
        • M Michael Dunn

          LoadIcon() can only load 32x32 icons. Specify the size in the LoadImage() call, 16x16 so the system knows which size you want. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Pinky, are you pondering what I'm pondering? I think so Brain, but how will we fit the hamster inside the accordion?

          B Offline
          B Offline
          Barvus
          wrote on last edited by
          #4

          Hmmm... I'm still getting the same error 1831. What am I doing wrong? :confused: m_hIconX = LoadImage(NULL, MAKEINTRESOURCE(IDI_X), IMAGE_ICON, 16, 16, 0); DWORD dwError; dwError = GetLastError();

          M F 2 Replies Last reply
          0
          • B Barvus

            Hmmm... I'm still getting the same error 1831. What am I doing wrong? :confused: m_hIconX = LoadImage(NULL, MAKEINTRESOURCE(IDI_X), IMAGE_ICON, 16, 16, 0); DWORD dwError; dwError = GetLastError();

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            You need to pass the module handle of your EXE for the first parameter. In MFC you use AfxGetResourceHandle() --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   -- Buffy

            B 1 Reply Last reply
            0
            • M Michael Dunn

              You need to pass the module handle of your EXE for the first parameter. In MFC you use AfxGetResourceHandle() --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   -- Buffy

              B Offline
              B Offline
              Barvus
              wrote on last edited by
              #6

              Thanks, Mike! That did the trick. Much appreciated.

              1 Reply Last reply
              0
              • B Barvus

                Hmmm... I'm still getting the same error 1831. What am I doing wrong? :confused: m_hIconX = LoadImage(NULL, MAKEINTRESOURCE(IDI_X), IMAGE_ICON, 16, 16, 0); DWORD dwError; dwError = GetLastError();

                F Offline
                F Offline
                f64
                wrote on last edited by
                #7

                Hi Barvus, An unrelated coment to your problem, I saw you used GetLastError() just to check what was wrong with the LoadImage call, good news for you, you don't have to type those two lines ever again, you can check the registers and pseudoregister and see among other things, the last error directly, to better undestand what I'm talking about, check this article An introduction to debugging in MSVC++ using Pseudoregisters By Wouter Dhondt Fabian

                B 1 Reply Last reply
                0
                • F f64

                  Hi Barvus, An unrelated coment to your problem, I saw you used GetLastError() just to check what was wrong with the LoadImage call, good news for you, you don't have to type those two lines ever again, you can check the registers and pseudoregister and see among other things, the last error directly, to better undestand what I'm talking about, check this article An introduction to debugging in MSVC++ using Pseudoregisters By Wouter Dhondt Fabian

                  B Offline
                  B Offline
                  Barvus
                  wrote on last edited by
                  #8

                  Hey, thanks for the tip! Good to know. I wonder why that's not documented in MSDN.... Or is it? Must be buried somewhere deep.

                  F 1 Reply Last reply
                  0
                  • B Barvus

                    Hey, thanks for the tip! Good to know. I wonder why that's not documented in MSDN.... Or is it? Must be buried somewhere deep.

                    F Offline
                    F Offline
                    f64
                    wrote on last edited by
                    #9

                    It is!!! :) Viewing the Last Error Code for the Current Thread

                    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