Dynamically changing an icon

This is a discussion on Dynamically changing an icon within the Windows Programming forums, part of the Platform Specific Boards category; How do I dynamically change an applications icon with only the window's handle. I've tried the following: Code: LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1)); ...

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Dynamically changing an icon

    How do I dynamically change an applications icon with only the window's handle. I've tried the following:
    Code:
    LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1));
    SetClassLong(hwnd, GCL_HICON, hIcon);
    but I get this error:
    SetClassLongA' : cannot convert parameter 3 from 'struct HICON__ *' to 'long'

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Have you tried to typecast the icon pointer to a long?

    SetClassLong(hwnd, GCL_HICON, (long)hIcon);
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    nope, that just doesn't do anything

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    This code works for me:
    Code:
    SetClassLong(MainWindow, GCL_HICON, (LONG)LoadIcon(CurInst, MAKEINTRESOURCE(ProgramIcon)));
    ShowWindow(MainWindow, SW_HIDE);
    ShowWindow(MainWindow, SW_SHOW);
    (You have to hide then show the window again, or the icon will be misplaced, appearing inside the window caption)

    I noticed that, when you load the icon, you don't handle the return-value from LoadIcon. Is this a typo?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing icon for Borland C++ apps
    By spank in forum Windows Programming
    Replies: 0
    Last Post: 07-21-2006, 08:10 AM
  2. Changing the Icon on your exe...
    By Ranedhel in forum Windows Programming
    Replies: 11
    Last Post: 07-28-2003, 03:49 PM
  3. Icon problem
    By mkyong in forum Windows Programming
    Replies: 0
    Last Post: 02-17-2003, 05:39 PM
  4. Icon? help!
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2001, 06:21 PM
  5. icon in title bar?
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2001, 06:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21