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

    changing the icon of a window

    hi gurus

    I try to make an exe to change the icon of a 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 change the icon but as soon as the window is activate, my icon is replace with a defaut one !!!!

    any help ?
    thanks
    chris

  2. #2
    Join Date
    Apr 2000
    Location
    San Francisco, California, USA
    Posts
    4,467

    Re: changing the icon of a window

    The problem is that the icon handle gets destroyed as soon as your application terminates. You need to inject some code into the target process and execute LoadImage in the context of the target process. This way the icon handle will be accounted for that process and will remain valid as long as the target process exists.
    Russian Software Development Network -- http://www.rsdn.ru

  3. #3
    Join Date
    Mar 2002
    Posts
    14

    Re: changing the icon of a window

    Yes, it's the problem.
    What I do now is I keep my exe alive as long as my AUDROS application is alive. So the icons stay correct.

    Thanks.

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