1. Icons and exe files

Using the following command, I can inject a desktop icon into an exe file compiled with Watcom:

wrc -q -ad myrcfile.rc myexefile.exe

The myrdfile.rc has a single line:

MYEXEFILE ICON MYICONFILE.ICO

This works fine for the desktop icon. However, the icon at the top left of each window in the application itself remains "unassigned" or at least it appears that way.

What is the accepted method for setting the icon in the application (as opposed to the desktop icon)?

Thanks

Mike

new topic     » topic index » view message » categorize

2. Re: Icons and exe files

Mike777 said...

Using the following command, I can inject a desktop icon into an exe file compiled with Watcom:

wrc -q -ad myrcfile.rc myexefile.exe

The myrdfile.rc has a single line:

MYEXEFILE ICON MYICONFILE.ICO

This works fine for the desktop icon. However, the icon at the top left of each window in the application itself remains "unassigned" or at least it appears that way.

What is the accepted method for setting the icon in the application (as opposed to the desktop icon)?

Thanks

Mike

You could do something like this, assuming you're using Win32Lib:

sequence cmd 
atom icon 
 
    cmd = command_line() 
    icon = loadIconFromFile( cmd[1] ) 
    setIcon( window, icon ) 

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Icons and exe files

Mike777 said...

Using the following command, I can inject a desktop icon into an exe file compiled with Watcom:

wrc -q -ad myrcfile.rc myexefile.exe

The myrdfile.rc has a single line:

MYEXEFILE ICON MYICONFILE.ICO

This works fine for the desktop icon. However, the icon at the top left of each window in the application itself remains "unassigned" or at least it appears that way.

What is the accepted method for setting the icon in the application (as opposed to the desktop icon)?

Thanks

Mike

I don't know about win32lib but with direct win32 API the following should work.
Modify your .RC file to put and identifier for the icon before compiling and binding it to the binary. That way you'll know which id to use in the call.

MYEXEFILE ICON MYICONFILE.ICO 100
You should check for the correct .rc file syntax.

-- setting a windows icon from an icon resource in binary file 
-- icon_id is an integer that identify the icon inside the binary file. 
-- all resources in windows binaries have an identifier. 
include dll.e 
constant user32=open_dll("user32.dll") 
constant iSetClassLong=define_c_func(user32,"SetClassLong",{C_ULONG,C_INT,C_ULONG},C_ULONG) 
constant GCL_HICON = -14 
constant ID_ICON = 100 
 
object void 
 
 
sequence cmd_line 
cmd_line = command_line() 
if equal(cmd_line[1],cmd_line[2]) then -- check if it is a binary file 
  void = c_func(iSetClassLong,{hWnd,--window handle 
                               GCL_HICON, 
                               ID_ICON -- icon resource identifier 
                               }) 
else -- load resource from .ico file 
...   
end if 
 


Jacques

new topic     » goto parent     » topic index » view message » categorize

4. Re: Icons and exe files

jacquesd said...
Mike777 said...

Using the following command, I can inject a desktop icon into an exe file compiled with Watcom:

wrc -q -ad myrcfile.rc myexefile.exe

The myrdfile.rc has a single line:

MYEXEFILE ICON MYICONFILE.ICO

This works fine for the desktop icon. However, the icon at the top left of each window in the application itself remains "unassigned" or at least it appears that way.

What is the accepted method for setting the icon in the application (as opposed to the desktop icon)?

Thanks

Mike

I don't know about win32lib but with direct win32 API the following should work.
Modify your .RC file to put and identifier for the icon before compiling and binding it to the binary. That way you'll know which id to use in the call.

MYEXEFILE ICON MYICONFILE.ICO 100
You should check for the correct .rc file syntax.

-- setting a windows icon from an icon resource in binary file 
-- icon_id is an integer that identify the icon inside the binary file. 
-- all resources in windows binaries have an identifier. 
include dll.e 
constant user32=open_dll("user32.dll") 
constant iSetClassLong=define_c_func(user32,"SetClassLong",{C_ULONG,C_INT,C_ULONG},C_ULONG) 
constant GCL_HICON = -14 
constant ID_ICON = 100 
 
object void 
 
 
sequence cmd_line 
cmd_line = command_line() 
if equal(cmd_line[1],cmd_line[2]) then -- check if it is a binary file 
  void = c_func(iSetClassLong,{hWnd,--window handle 
                               GCL_HICON, 
                               ID_ICON -- icon resource identifier 
                               }) 
else -- load resource from .ico file 
...   
end if 
 


Jacques

made a mistake should be

constant iLoadIcon=define_c_func(user32,"LoadIcon",{C_POINTER,C_INT},C_POINTER) 
  void = c_func(iSeClassLong,{hWnd,GCL_HICON,c_func(iLoadIcon,{instance(),ID_ICON})}) 


jacques

new topic     » goto parent     » topic index » view message » categorize

5. Re: Icons and exe files

ghaberek said...
Mike777 said...

Using the following command, I can inject a desktop icon into an exe file compiled with Watcom:

wrc -q -ad myrcfile.rc myexefile.exe

The myrdfile.rc has a single line:

MYEXEFILE ICON MYICONFILE.ICO

This works fine for the desktop icon. However, the icon at the top left of each window in the application itself remains "unassigned" or at least it appears that way.

What is the accepted method for setting the icon in the application (as opposed to the desktop icon)?

Thanks

Mike

You could do something like this, assuming you're using Win32Lib:

sequence cmd 
atom icon 
 
    cmd = command_line() 
    icon = loadIconFromFile( cmd[1] ) 
    setIcon( window, icon ) 

-Greg

Works quite nicely. By setting the icon on the main window, all other windows pick up that icon without having to separately run the code for each window. Nice.

Thanks

Mike

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu