How do I load a 16x16 icon?
-
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?
-
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?
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.
-
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?
LoadIcon()
can only load 32x32 icons. Specify the size in theLoadImage()
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? -
LoadIcon()
can only load 32x32 icons. Specify the size in theLoadImage()
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? -
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();
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 -
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 -
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();
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
-
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
-
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.