-
-
Save Noitidart/33b6d28ebf4ff5ebdff6 to your computer and use it in GitHub Desktop.
Cu.import('resource://gre/modules/ctypes.jsm'); | |
var user32 = ctypes.open('user32.dll'); | |
/* http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29.aspx | |
* LRESULT WINAPI SendMessage( | |
* __in HWND hWnd, | |
* __in UINT Msg, | |
* __in WPARAM wParam, | |
* __in LPARAM lParam | |
* ); | |
*/ | |
var SendMessage = user32.declare('SendMessageW', ctypes.winapi_abi, ctypes.uintptr_t, | |
ctypes.int32_t, | |
ctypes.unsigned_int, | |
ctypes.int32_t, | |
ctypes.voidptr_t | |
); | |
/* http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045%28v=vs.85%29.aspx | |
* HANDLE WINAPI LoadImage( | |
* __in_opt_ HINSTANCE hinst, | |
* __in_ LPCTSTR lpszName, | |
* __in_ UINT uType, | |
* __in_ int cxDesired, | |
* __in_ int cyDesired, | |
* __in_ UINT fuLoad | |
* ); | |
*/ | |
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 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(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 | |
var me = Services.wm.getMostRecentWindow(null); | |
me.alert(successSmall); | |
me.alert(successBig); | |
user32.close(); |
Grouping/Pinned icon: http://msdn.microsoft.com/en-us/library/windows/desktop/dd391573%28v=vs.85%29.aspx IIRC
I would actually change the title to some uuid and only then find the window in production code, to avoid running into problems when two windows have the same name.
PS: Here is the old patch I mentioned: https://bug595462.bugzilla.mozilla.org/attachment.cgi?id=490837 via. https://bugzilla.mozilla.org/show_bug.cgi?id=595462
Thanks man, this is the code I'm using to set it on all windows. But I'm running into problems. If I uncomment the Services.wm.getMostRecentWindow(null).alert(aDOMWindow.document.documentElement.getAttribute('title'));
then it doesn't work. It's so weird.
Here's the code:
Cu.import('resource://gre/modules/ctypes.jsm');
var user32 = ctypes.open('user32.dll');
var FindWindow = user32.declare('FindWindowW', ctypes.winapi_abi, ctypes.int32_t,
ctypes.jschar.ptr,
ctypes.jschar.ptr
);
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 targetWindow_title = aDOMWindow.document.documentElement.getAttribute('title');
var targetWindow_titleOriginal = targetWindow_title;
targetWindow_title += ' - Profilist Iconing Proc';
aDOMWindow.document.documentElement.setAttribute('title', targetWindow_title);
Services.wm.getMostRecentWindow(null).alert(aDOMWindow.document.documentElement.getAttribute('title'));
var targetWindow_handle = FindWindow(null, targetWindow_title);
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
aDOMWindow.document.documentElement.setAttribute('title', targetWindow_titleOriginal);
}
user32.close();
Oh I think I know the problem with what I just posted. After I do setAttribute on the window title it takes a little while before it registers with windows?
Committed Rev2
Hey man it was definitely the problem where when I set the title of the window, then ran FindWindow
right after that, it was not finding the window because it takes a little bit after the setting of title for it to register on OS. I updated in Rev2 to use nativeHandle
so that's fixed now. :)
Committed Rev3
Committed Rev4
README
Rev1
C:\Documents and Settings\SONY VAIO\My Documents\Downloads\puzzle.ico
(or you have to change this path)LoadImage
must be a path to a.ico
alert
andvar me = Services.wm.getMostRecent...
Alt
+Tab
the icon is the normal oneRev2
FindWindow
made it usenativeHandle
nowSetForegroundWindow
debug part as that was to test if I had got the right window but withnativeHandle
I now know for sure I got the right handleRev3
nsIWindowsMediator
to apply to all windowsRev4
parseInt
onnativeHandle
is wrong becausenativeHandle
might be a 64-bit pointer. Also js numbers are floats.