-
September 7th, 2004, 09:08 AM
#1
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
-
September 7th, 2004, 12:38 PM
#2
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.
-
September 8th, 2004, 01:28 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|