CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Posts
    14

    Changing the icon of a window

    Hi Gurus

    I'trying to make an exe to change the icon of the window of an other application.

    Here my code :

    #include "stdafx.h"
    #include <winbase.h>
    #include <windows.h>



    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {

    HWND hWnd;
    HICON hIcon;

    // AUDROS (5.5) is the title of the window of I want to change the icon

    hWnd = FindWindow(NULL, "AUDROS (5.5)");

    if (hWnd)
    {
    hIcon = (HICON)LoadImage(NULL, "ico00001.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);

    SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
    }

    return(0);
    }



    It really change the icon but as soon as the window is activate, the new icon is lost and it's replace with a defaut icon !!!

    Any helps
    Thanks
    Chris

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Changing the icon of a window

    It is because your app loaded that icon, and when it quits the handle is no longer valid.

    In order to really change the icon, you would need to force the other application to call LoadImage itself. This is complicated, but there is something called thread injection that could be useful to you.

    http://www.codeproject.com/threads/winspy.asp

    Regards / Z

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Changing the icon of a window

    Please don't create identical threads in the future. If you were unsatisfied with your post, you should have used Edit, to change it. Any post can be re-edited by the original poster, or the forum moderators.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: Changing the icon of a window

    Quote Originally Posted by Chris ZANARDI
    It really change the icon but as soon as the window is activate, the new icon is lost and it's replace with a defaut icon !!!
    what window should be "activate" (active?)? Does the icon restores when target application's window reactivates (seting focus)? Or when your programm closes?
    "Programs must be written for people to read, and only incidentally for machines to execute."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured