0

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();
Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

1

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.

nmaier
  • 32,336
  • 5
  • 63
  • 78
  • But then what does the MSDN docs mean by setting `hinst` to `null` and omit the `LR_LOADFROMFILE` parameter? – Noitidart Jun 04 '14 at 06:23
  • 1
    Haha yeah man that `nativeHandle` is awesome thanks to @paa for that one: http://stackoverflow.com/a/21998929/1828637 Do you know if this documented anywhere on MDN? – Noitidart Jun 04 '14 at 06:23
  • OEM images are entirely different beasts. Those are default icons that come bundles with Windows. – nmaier Jun 04 '14 at 06:37
  • Ahh I got it! So if I had changed it to an OEM image than I could have used the null and omit technique correct? – Noitidart Jun 04 '14 at 06:46
  • To restore the original icon? No. You could use the MSDN stuff to replace the icon with an [OEM/bundled](http://sourceforge.net/p/mingw-w64/code/HEAD/tree/trunk/mingw-w64-headers/include/winuser.h#l4094) icon, but this is entirely not what you are asking for. – nmaier Jun 04 '14 at 06:54
  • Ohhh I seee now, I can just change it to another OEM icon but NOT restore it. Got it thanks man this was really such a fun night working on this with you. I passed up on a gym trip to experiment on this hahaha. – Noitidart Jun 04 '14 at 06:59