c++ - 设置 Windows 问题的图标(WinXP 和 Win7)

标签 c++ firefox-addon icons user32 jsctypes

我正在使用 js-ctypes 制作一个 Firefox 插件,并使用 user32.dll 函数来设置配置文件所有窗口的图标。

我计划针对 Mac OS 和 Linux 执行此操作,但首先尝试淘汰 Windows。

所以我设置的图标是这样的:GitHub - Gist :: Noitidart / _ff-addon-snippet-ChangeWindowIcon.js - Rev2

该代码已简化。我用来应用于所有窗口的代码:

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

问题如下:

WinXP 上的问题

  • 当按下 Alt + Tab 时图标是正常的
  • 如果窗口被归为一组(由于任务栏溢出)并且所有图标都已更改,则归为一组的图标仍然不是更改的图标。如图所示:

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

Win7 上的问题

  • 如果应用程序已固定并且即使所有窗口图标都更改为相同,它仍然不会更改固定图标
  • 如果应用程序未固定然后如果更改所有窗口的图标它会更改任务栏上的图标但是如果您右键单击任务栏中的图标它会恢复到正常状态,再次运行上面的代码片段不会将其设置回来,要将其恢复为您设置的图标,您必须固定和取消固定

最佳答案

你真的不应该把这么多问题放在一个问题中......

When press Alt + Tab the icon is the normal one

您正在尝试加载和设置 256x256 图标。 XP 不支持此类图标。你真的应该添加一些错误检查;) IIRC 你应该为大图标设置 32x32 图标。或者更准确地说 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:

我认为你运气不好。 XP 将采用任何图标作为 .exe IIRC 中的主要资源图标。

无论如何 XP 已经死了......

Issues On Win 7

IIRC 你必须使用 System.AppUserModel.RelaunchIcon ...

编辑 实际上,关于 XP 分组的内容我可能是错误的。上次在 win32 上弄乱图标是很久以前的事了。 GCLP_HICON/GCLP_HICONSM 可能有效。

关于c++ - 设置 Windows 问题的图标(WinXP 和 Win7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24028715/

相关文章:

java - 仅通过命令行创建 native android Activity (makefile)

c++ - 为什么从 int 到 char 的 memcpy 不起作用?

c++ - 如何在 Visual C++ 中截断文件?

c++ - 子类的类型

javascript - 切换多个 jQuery 图标

在 Web 应用程序中将页面打印到不同的打印机

javascript - 在 Firefox 中显示小部件

firefox-addon - 在与安装的 firefox 插件相同的文件夹中运行打包的 exe

android - 应用程序图标未显示在操作栏上

javascript - meteor 按钮上的切换图标