How to change the icon of application for Windows 
Author Message
 How to change the icon of application for Windows

Hi:
  This is the second time I ask the question.
  I want to change the icon of my application for Windows,
and I used the command "wm iconbitmap . MyIconFile".But it
didn't work at all,the application still had the icon of
TK.
  Is there anyone can help me?
  Thanks for any help.
  Best regards.
  Kevin

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 15 Dec 2002 03:00:00 GMT  
 How to change the icon of application for Windows

Quote:

> Hi:
>   This is the second time I ask the question.
>   I want to change the icon of my application for Windows,
> and I used the command "wm iconbitmap . MyIconFile".But it
> didn't work at all,the application still had the icon of
> TK.
>   Is there anyone can help me?
>   Thanks for any help.
>   Best regards.
>   Kevin

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Are you using the winico package?

L

--
Laurent Duperval                 "Montreal winters are an intelligence test,

                                                              -Doug Camilli
Penguin Power!         ***Nothing I say reflects the views of my employer***



Sun, 15 Dec 2002 03:00:00 GMT  
 How to change the icon of application for Windows

Quote:

> Are you using the winico package?

 No,I didn't use the winico package.
 I want to know whether I must use it to
change the icon of my appliction.
 Thanks

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 16 Dec 2002 03:00:00 GMT  
 How to change the icon of application for Windows

Quote:



> > Are you using the winico package?

>  No,I didn't use the winico package.
>  I want to know whether I must use it to
> change the icon of my appliction.
>  Thanks

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Yes, you have to use the winico extension.


Mon, 16 Dec 2002 03:00:00 GMT  
 How to change the icon of application for Windows
Hi,

I didn't use the winico extension but I've changed the icon :)

But You have to have C++ program which starts Your script, which I think is
necessary to introduce new commands. OK, to the point.
1. create .rc file in VisualStudio with Your icon (32x32 16colors is
enough), we need only the .ico file, .rc file and resource.h file (we don't
need StdAfx.h file),
2. add to Your makefile compilation of .rc file (using rc.exe from
VisualStudio) like this:
$(EXEDIR)/file_name.res : $(SRCDIR)/file_name.rc $(IMGDIR)/file_name.ico

where RSC = rc.exe, You can alse export from VS makefile and see how it's
done there.
3. link res file to Your project,
4. in Your C program include function like shown below:

#include <winuser.h>
#include <winbase.h>
#include "resource.h"

int setMyIcon(ClientData, Tcl_Interp,int, char*)
{
   HWND       winHandle;
   HANDLE   hIcon;
   LPVOID     lpMsgBuf;
   HINSTANCE hInst     = 0;

   char cmd[] = "wm frame .";

   //get main window handle
   Tcl_GlobalEval(interp,cmd);
   //convert main window handle to Windows HWND
   sscanf(interp->result,"0x%x",(int*)&winHandle);
   //get application instance (executable not Tk's DLL)
   //appName is a string which contains your exe file name and path, I have
a global
   //variable which I set using argv[0] in my main() function - you can also
hardcode
   //your exe file name (but it's not the best way to do this)
   hInst = LoadLibrary(appName.c_str());
   if (hInst != NULL)
   {
      //load icon - IDI_ICON1 is icon name from the resource file
      hIcon = LoadImage(hInst,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,0,0,0);

      if (hIcon != NULL)
      {
         //set icon
         //SendMessage(winHandle,WM_SETICON,0,(LPARAM)hIcon); - another way
         // to do it
         SetClassLong(winHandle,GCL_HICON,(LPARAM)hIcon);
      }
      else
      {
         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                       NULL,GetLastError(),
                       MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
                       (LPTSTR)&lpMsgBuf,
                       0,
                       NULL);
    // print out error
    cout << lpMsgBuf << endl;
         LocalFree(lpMsgBuf);
      }
   }
   else
   {
      FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                    NULL,GetLastError(),
                    MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
                    (LPTSTR)&lpMsgBuf,
                    0,
                    NULL);
    // print out error
    cout << lpMsgBuf << endl;
      LocalFree(lpMsgBuf);
   }

   return TCL_OK;

Quote:
}

5. Make new Tcl command from shown above function, like this:
    Tcl_CreateCommand(interp,"setMyIcon",setMyIcon,
                                     (ClientData) NULL,
                                     (Tcl_CmdDeleteProc*) NULL);
6. Call it from Your Tk application somewhere at the beginning...

If You do it succesfully Your application will have Your icon, when You
press Alt+Tab Your icon will be shown, Your .exe file will have Your icon
and when You create shortcut to Your .exe it will also have Your icon...

This is very simple solution and I don't do much error checking here nor do
I care of different icon sizes. But it works fine for me :))

Do You want to know also how to get rid of Tcl\Tk console window (if You
don't know it already)?

Any questions or comments are welcome :)

Good luck,
/-------------------------------------------------------/
 Bartlomiej Ziolkowski
 Software Engineer
 Vertel Poland

 phone: +48.61.86.49.443 (444)
/-------------------------------------------------------/



Tue, 17 Dec 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Change Application Icon in MS Windows TCL/Tk application

2. Change Application Icon in Windows OS

3. Change STD Icon on unassigned windows Globaly ??

4. Some icons in LabView windows changed

5. Changing Icon for mktclapp generated executable on windows

6. application icon on Windows

7. Windows XP Group Application Name / TaskManager Icon

8. using windows icons in tk application

9. Removing the TK icon from application windows...

10. Changing root window icon in Python on Windows

11. Cannot change Windows icon with iconbitmap

12. Application Icons under Windows

 

 
Powered by phpBB® Forum Software