Jump to content
  • Advertisement
Sign in to follow this  
Daaark

Replacing titlebar icon

This topic is 4726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I made an icon to go with my program the other day, and I placed it in a resource file and compiled it. It immediatley changed so that my .exe had the icon representing it. I didn't think it would work that easy (never done that before). But when I opened my program I still have the default on the titlebar. I know I can change it while the window is being created, however that's buried in my OpenGL window framework that I do not want to change so that I need to include an icon load into it. I want to just change my icon at runtime. I looked up some stuff on MSDN and found these two methods, but they are not working. They compile, but none have an effect when executed. Note that GetHWND() just returns the handle to my main window, and it DOES work. rsc.h, defines my 32x32 .ico file
#define IDR_ICO_MAIN 411
HICON hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_ICO_MAIN));
SendMessage(GetHWND(), WM_SETICON, ICON_BIG, (LPARAM) hIcon );
SendMessage(GetHWND(), WM_SETICON, ICON_SMALL, (LPARAM) hIcon );
SetClassLong(GetHWND(),GCL_HICON,(LONG) 
LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_ICO_MAIN)));

Share this post


Link to post
Share on other sites
Advertisement
I am apssing them to the deault handler. Could it be something with my icon? Does it need to be 8bit?
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{

case WM_ACTIVATE:
{
if (LOWORD(wParam) == WA_INACTIVE) bActive = false;
else
{
bActive = true;

//must reacquire the input devices
if (bAcquired) InputAcquire();
}

break;
}


case WM_CLOSE:
case WM_QUIT:
{
bDone = true;
break;
}

case WM_DESTROY:
PostQuitMessage (0);
break;

default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

Share this post


Link to post
Share on other sites
    HICON hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_ICO_MAIN));
if (hIcon == NULL)
{
MessageBox(GetHWND(),"Icon failed to load!",APP_TITLE,MB_OK|MB_ICONERROR);
}




Yep. The box is popping up. Does it need to be 16x16? I'm not sure what can be wrong here. It's in my res file and it shows up in the .exe when I look for an icon in it with explorer and the .exe even uses it in explorer. :S I wonder if GetModuleHandle(NULL) is doing what I expect. Is that how I properly get my hInstance? It has always worked before when I'm loading controls and stuff.

Share this post


Link to post
Share on other sites
Hmm, probably the icon id is off?

Try to get hold of Resource Hacker or open the .exe in your Visual Studio. It should show you the resources (types and ids) inside. Maybe the define for the icon id got mangled.

Share this post


Link to post
Share on other sites
I read the LoadIcon docs again and and swapped out my icon for default icons and it worked. I don't have visual studio. I'm using Codeblocks and VC++Toolkit. :S

Share this post


Link to post
Share on other sites
I just tried reducing the icon from 24bpp to 16 colours, it still doesn't load. [sad] Comes up NULL.

Share this post


Link to post
Share on other sites
Weird, try to open your exe with Resource Hacker (it's a nifty freeware tool allowing you to read and even modify the resources of exes and dlls). Look esp. at the resource sections and the ID. It should contain one Icon and one Icon Group. The id of the icon group should resemble the define you pass in LoadIcon.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!