WM_GETICON not working (Windows)
WM_GETICON not working (Windows)
如果我不首先使用WM_SETICON来设置图标,那么WM_GETICON总是返回0。这太奇怪了。请帮助。
这是我的代码,可以复制粘贴到记事本上运行。
当做SendMessage(targetWindow_handle, WM_GETICON , ICON_SMALL, ctypes.voidptr_t(0))
, hIconSmall_orig
和hIconBig_orig
总是返回0,我不知道为什么。如果你先在窗口上执行WM_SETICON,那么它会正确地获得HICON,但整个目的是获得默认图标。
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.voidptr_t,
ctypes.unsigned_int,
ctypes.int32_t,
ctypes.voidptr_t
);
var WM_GETICON = 0x007F;
var WM_SETICON = 0x0080;
var ICON_SMALL = 0;
var ICON_BIG = 1;
var ICON_SMALL2 = 2; //for use with WM_GETICON only, not applicable to WM_SETICON
// 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 = ctypes.voidptr_t(ctypes.UInt64(nativeHandle));
var hIconSmall_orig = SendMessage(targetWindow_handle, WM_GETICON , ICON_SMALL, ctypes.voidptr_t(0));
var hIconBig_orig = SendMessage(targetWindow_handle, WM_GETICON , ICON_BIG, ctypes.voidptr_t(0));
Services.wm.getMostRecentWindow(null).alert('hIconSmall_orig = ' + hIconSmall_orig + 'nhIconBig_orig = ' + hIconBig_orig);
user32.close();
既然你从我这里得到了WM_GETICON
的东西(在另一个问题的另一个答案中),让我先说:已经有一段时间了……所以我忘记了WM_GETICON
将返回null当窗口没有特定的窗口图标分配,而是图标从注册的窗口类。
所以你应该:
- 检查
WM_GETICON
,查看窗口是否有指定的特定图标。 - 检查
GetClassLongPtr(hwnd, GCLP_HICON /* or GCLP_HICONSM */)
的类 - 如果失败,你可以尝试从
.exe
加载主图标 - 如果失败,你可以尝试加载一个股票图标。
下面是一些c++代码,我用它来从我的"mintrayr"扩展的窗口中实际获取一个图标:
// Get the window icon
HICON icon = reinterpret_cast<HICON>(::SendMessageW(hwnd, WM_GETICON, ICON_SMALL, 0));
if (icon == 0) {
// Alternative method. Get from the window class
icon = reinterpret_cast<HICON>(::GetClassLongPtrW(hwnd, GCLP_HICONSM));
}
// Alternative method: get the first icon from the main module (executable image of the process)
if (icon == 0) {
icon = ::LoadIcon(GetModuleHandleW(0), MAKEINTRESOURCE(0));
}
// Alternative method. Use OS default icon
if (icon == 0) {
icon = ::LoadIcon(0, IDI_APPLICATION);
}
有一种非常简单(而且是跨平台的)的方法来检索Firefox的默认图标。
var foxexe = FileUtils.getFile("XREExeF", []);
var iconurl = "moz-icon:" + Services.io.newFileURI(foxexe).spec;
您可以像对待任何其他指向图像的url一样对待iconurl
。默认大小为16x16,添加?size=32
以获得更大的图标。似乎这两个值是Windows上唯一支持的。对于其他操作系统可能不是这样。
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux for Windows上编译C++代码时出错
- 在Windows上用C++裁剪HBITMAP
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- Windows/Cygwin - 不能使用 pybind11 - 犯错误
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 在Windows中以.exe的形式运行c++
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 无法在windows控制台中为C++程序提供必要的输入
- 在Windows中查找扬声器输出的当前音量级别
- Windows.h与GLFW.h的接口
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 在Linux和C++中的Windows上,散列字符串值会产生不同的输出
- Active Directory:从网络服务帐户下运行的Windows服务调用ADsOpenObject时失败
- PyCharm CE 2017.2.2:APPCRASH 在 Windows 7 上随机"Python has stopped working"
- WM_GETICON not working (Windows)