如何恢复默认图标? (WinXP和Win7)

时间:2014-06-04 05:39:21

标签: c++ firefox-addon icons user32 jsctypes

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

告诉我:

  

如果hinst参数为NULL并且fuLoad参数省略了LR_LOADFROMFILE值,则lpszName指定要加载的OEM映像。 OEM映像标识符在Winuser.h中定义,并具有以下前缀。

但我很难搞清楚。

我尝试过此操作,但它会在var hIconBig = LoadImage...var hIconSmall = LoadImage...行上抛出各种错误。

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();

1 个答案:

答案 0 :(得分:1)

要恢复正确的图标,您必须先WM_GETICON HICON s设置自己的图标并保留它们。然后,当您想要恢复图标时,WM_SETICON将保存这些图标。

GCLP_HICON相同。

除此之外:nsIBaseWindow现在有一个脚本nativeHandle?好极了!我还不知道。是时候在没有nativeHandle的情况下抛弃我的老头衔。