WM_GETICON不工作(Windows) [英] WM_GETICON not working (Windows)
问题描述
如果我不使用WM_SETICON首先设置图标,那么WM_GETICON总是返回0.这很奇怪。请帮助。
If I don't use WM_SETICON first to set the icon then WM_GETICON is always returning 0. This is weird. Please help.
这是我的代码,可以复制粘贴到便笺本并运行。
This is my code, can copy paste into scratchpad and run.
c $ c> SendMessage(targetWindow_handle,WM_GETICON,ICON_SMALL,ctypes.voidptr_t(0)), hIconSmall_orig
和 hIconBig_orig
总是返回0我不知道为什么。如果你先在窗口中打开WM_SETICON,那么它会正确地获取HICON,但是整个目的是获得默认图标。
When doing SendMessage(targetWindow_handle, WM_GETICON , ICON_SMALL, ctypes.voidptr_t(0))
, hIconSmall_orig
and hIconBig_orig
is always returning 0 I have no idea why. IF you go WM_SETICON on the window first then it properly gets the HICON but the whole purpose is to get the default icon.
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 c>
我会(另一个答案另一个问题)让我先说:这已经一段时间...所以我忘了, WM_GETICON
当窗口没有指定特定的窗口图标时返回null,而是从注册的窗口类中获取图标。
Since you got the WM_GETICON
stuff from me (in another answer to another question) let me first say: It has been a while... So I forgot that WM_GETICON
will return null when the window has no particular window icon assigned, but instead the icon is taken from the registered window class.
所以你应该:
- 检查
WM_GETICON
以查看窗口是否分配了特定图标。 - 通过
GetClassLongPtr(hwnd,GCLP_HICON / *或GCLP_HICONSM * /)检查类
- 如果失败,从
.exe
- 加载主图标如果失败,您可以随时尝试加载股票图标。
- Check
WM_GETICON
to see if the window has a specific icon assigned. - Check the class by
GetClassLongPtr(hwnd, GCLP_HICON /* or GCLP_HICONSM */)
- If that fails, you can always try to load the main icon from the
.exe
- If that fails, you can always try to load a stock icon.
这里是一些C ++代码,我用来从我的mintrayrextension :
Here is some C++ code which I use to actually get an icon from a window in my "mintrayr" extension:
// 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);
}
这篇关于WM_GETICON不工作(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!