Setting Icon of Windows Issues (WinXP and Win7)
Asked Answered
M

1

0

I'm making a Firefox addon with js-ctypes and was using user32.dll functions to set the icons of all windows of a profile.

I plan to do this for Mac OS and Linux but trying to knock out Windows first.

So I'm setting the icons like this: GitHub - Gist :: Noitidart / _ff-addon-snippet-ChangeWindowIcon.js - Rev2

That code is simplified. This code I use to apply to all windows:

Cu.import('resource://gre/modules/ctypes.jsm');

var user32 = ctypes.open('user32.dll');

var SendMessage = user32.declare('SendMessageW', ctypes.winapi_abi, ctypes.uintptr_t,
    ctypes.int32_t,
    ctypes.unsigned_int,
    ctypes.int32_t,
    ctypes.voidptr_t
);

var LoadImage = user32.declare('LoadImageA', ctypes.winapi_abi, ctypes.voidptr_t,
    ctypes.int,
    ctypes.char.ptr,
    ctypes.unsigned_int,
    ctypes.int,
    ctypes.int,
    ctypes.unsigned_int
);

var IMAGE_BITMAP = 0;
var IMAGE_ICON = 1;
var LR_LOADFROMFILE = 16;


// RUNNING STUFF BELOW - ABVOE WAS JUST DEFINING STUFF
var DOMWindows = Services.wm.getEnumerator(null);
while (DOMWindows.hasMoreElements()) {
    var aDOMWindow = DOMWindows.getNext();
    var basewindow = aDOMWindow.QueryInterface(Ci.nsIInterfaceRequestor)
        .getInterface(Ci.nsIWebNavigation)
        .QueryInterface(Ci.nsIDocShellTreeItem)
        .treeOwner
        .QueryInterface(Ci.nsIInterfaceRequestor)
        .nsIBaseWindow;
    var nativeHandle = basewindow.nativeHandle;

    var targetWindow_handle = parseInt(nativeHandle);

    var hIconBig = LoadImage(targetWindow_handle, 'C:\\Documents and Settings\\SONY VAIO\\My Documents\\Downloads\\puzzle.ico', IMAGE_ICON, 256, 256, LR_LOADFROMFILE); //MUST BE A FILEPATH TO A ICO!!!
    var hIconSmall = LoadImage(targetWindow_handle, 'C:\\Documents and Settings\\SONY VAIO\\My Documents\\Downloads\\puzzle.ico', IMAGE_ICON, 16, 16, LR_LOADFROMFILE); //MUST BE A FILEPATH TO A ICO!!!

    var successSmall = SendMessage(targetWindow_handle, 0x0080 /** WM_SETICON **/ , 0 /** ICON_SMALL **/ , hIconSmall); //if it was success it will return 0? im not sure. on first time running it, and it was succesful it returns 0 for some reason
    var successBig = SendMessage(targetWindow_handle, 0x0080 /** WM_SETICON **/ , 1 /** ICON_BIG **/ , hIconBig); //if it was success it will return 0? im not sure. on first time running it, and it was succesful it returns 0 for some reason   

}

user32.close();

The issues are as follows:

Issues On WinXP

  • When press Alt + Tab the icon is the normal one
  • If windows are lumped into one group (because of taskbar overflow) and ALL icons are changed, the lumped group icon is still not the changed one. As seen in image here:

    _ff-addon-snippet-ChangeWindowIcon.js - Rev1 -- WinXP lumped icon issue.PNG

Issues On Win7

  • If the application IS PINNED and even if all windows icons are changed to be the same, it still does not changed the pin icon
  • If the application is NOT PINNED then if change the icon for all windows it will change the icon on the taskbar HOWEVER if you right click on the icon in the taskbar it reverts to what it was normally and running the snippet above again won't set it back, to get it back to icon you set you have to pin and unpin
Melvamelvena answered 4/6, 2014 at 3:54 Comment(0)
F
1

You really shouldn't put so much questions into a single question...

When press Alt + Tab the icon is the normal one

You're trying to load and set 256x256 icons. XP does not support such icons. You should really add some error checking ;) IIRC you should set 32x32 icons for the big one. Or more precisely SM_CXICON and/or SM_CXSMICON

If windows are lumped into one group (because of taskbar overflow) and ALL icons are changed, the lumped group icon is still not the changed one. As seen in image here:

I think you're out of luck for this one. XP will take whatever icon is the main resource icon in the .exe IIRC.

XP is dead anyway...

Issues On Win 7

IIRC you'll have to work with System.AppUserModel.RelaunchIcon...

Edit Actually I might be wrong regarding the XP grouping stuff. Last messed around with icons on win32 quite a while ago. GCLP_HICON/GCLP_HICONSM might work.

Fundamental answered 4/6, 2014 at 5:26 Comment(5)
Ah I'll split out future ones, there was just so much I wanted to ask all here. Thanks man. About the lumped xp icon, is it possible to change the main resource icon? (I use XP :P )Melvamelvena
I was thinking of copy pasting a shortcut of the firefox.exe then modding it to be "firefox.exe -P -profileName" so it will be an icon per profile. Then setting that icon per those shortcuts should make it take that icon in taskbar on xp correct? It works in Win7. And added bonus in Win7 is if they pin that icon then it will launch straight up into that profile. :) btw do you know if this method would work on mac os and linux?Melvamelvena
and oooooohhhh noooo wayyyy!!! setting big to 32 by 32 fixed the alt tab thing!!!!! thanks mannnn!!Melvamelvena
Linux (what Desktop enviroment anyway? KDE, Gnome, Unity, XFCE, LXDE, ...) and OSX do not really use .lnk (Well, .desktop on some Linux might be similar)Fundamental
Hey man I don't understand the GLCP/HICON/GCLP_HICONSM can you please elaborate on a test I can do for that please.Melvamelvena

© 2022 - 2024 — McMap. All rights reserved.