Question

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045%28v=vs.85%29.aspx

tells me that:

If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies the OEM image to load. The OEM image identifiers are defined in Winuser.h and have the following prefixes.

But I'm having a hard time figuring it out.

I'm trying this but it's throwing all kinds of errors on the var hIconBig = LoadImage... and var hIconSmall = LoadImage... lines.

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;

var basewindow = window.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(null, 'C:\\Documents and Settings\\SONY VAIO\\My Documents\\Downloads\\puzzle.ico', IMAGE_ICON, 256, 256);
var hIconSmall = LoadImage(null, 'C:\\Documents and Settings\\SONY VAIO\\My Documents\\Downloads\\puzzle.ico', IMAGE_ICON, 16, 16);

var successSmall = SendMessage(targetWindow_handle, 0x0080 /** WM_SETICON **/ , 0 /** ICON_SMALL **/ , hIconSmall);
var successBig = SendMessage(targetWindow_handle, 0x0080 /** WM_SETICON **/ , 1 /** ICON_BIG **/ , hIconBig);

var me = Services.wm.getMostRecentWindow(null);
me.alert(successSmall);
me.alert(successBig);

user32.close();
Was it helpful?

Solution

To restore the correct icons you'll have to WM_GETICON the HICONs prior to setting your own ones and keeping them around. Then when you want to restore icons, WM_SETICON with those saved ones.

Same for GCLP_HICON.

Aside: nsIBaseWindow has a scriptable nativeHandle now? Yay! I didn't know that yet. Time to throw out my old title-hack from when there wasn't a nativeHandle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top