Undocumented windows message 0x0313 & TTaskBarMenu
来源:互联网 发布:佟大为演技 知乎 编辑:程序博客网 时间:2024/06/08 14:25
When you right-click on a taskbar button, Windows sends an undocumented message ($0313) to the corresponding application window. The WPARAM is unused (zero) and the LPARAM contains the mouse position in screen coordinates, in the usual format. By default, WindowProc handles this message by popping up the system menu at the given coordinates.Apparently you can use it to pop up your own custom menu, but before doing that I would use e.g. Spy++ to check whether possibly it generates documented messages that can be processed instead.
unit TaskBarMenu;interfaceuses SysUtils, Classes, Menus, Messages, Windows, Forms, Controls;type TTaskBarMenu = class(TPopupMenu) private hookHandle : THandle; oldWndProc: Pointer; newWndProc: Pointer; protected procedure Hook; procedure UnHook; procedure AppWndProc(var Msg: TMessage) ; public constructor Create(AOwner: TComponent) ; override; destructor Destroy; override; end;procedure Register;implementationconst WM_TASKBAR_MENU = $0313; // magic! WM_POPUP_MENU = WM_USER + 1; //custom messagevar thisOnce : TTaskBarMenu = nil;procedure Register;begin RegisterComponents('delphi.about.com', [TTaskBarMenu]) ;end;{ TTaskBarMenu }procedure TTaskBarMenu.AppWndProc(var Msg: TMessage) ;begin case Msg.Msg of WM_TASKBAR_MENU: PostMessage(hookHandle, WM_POPUP_MENU, 0, 0) ; WM_POPUP_MENU: Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y) ; else Msg.Result := CallWindowProc(oldWndProc, hookHandle, Msg.Msg, Msg.wParam, Msg.lParam) ; end;end; (*AppWndProc*)constructor TTaskBarMenu.Create(AOwner: TComponent) ;begin if Assigned(thisOnce) then begin raise Exception.Create('Only one instance of this component can be used per application!') ; end else begin inherited; thisOnce := self; hookHandle := Application.Handle; Hook; end;end; (*Create*)destructor TTaskBarMenu.Destroy;begin thisOnce := nil; UnHook; inherited;end; (*Destroy*)procedure TTaskBarMenu.Hook;begin oldWndProc := Pointer(GetWindowLong(hookHandle, GWL_WNDPROC)) ; newWndProc := Classes.MakeObjectInstance(AppWndProc) ; if not (csDesigning in ComponentState) then SetWindowLong(hookHandle, GWL_WNDPROC, longint(newWndProc)) ;end; (*Hook*)procedure TTaskBarMenu.UnHook;begin SetWindowLong(hookHandle, GWL_WNDPROC, longint(oldWndProc)) ; if Assigned(newWndProc) then Classes.FreeObjectInstance(newWndProc) ; NewWndProc := nil;end; (*UnHook*)end.
备注:本文参考自:
1、http://stackoverflow.com/questions/10430377/winapi-undocumented-windows-message-0x0313-stable
2、http://delphi.about.com/od/vclwriteenhance/a/ttaskbarmenu.htm
- Undocumented windows message 0x0313 & TTaskBarMenu
- Undocumented Windows 2000笔记之一:前言
- Undocumented Windows 2000 Secrets 第一章(1)
- Analysis of undocumented Windows function NhGetInterfaceNameFromDeviceGuid
- Windows Message
- windows message
- windows Message
- Windows Message
- Windows Message
- Undocumented Windows 2000笔记之二:Windows调试支持
- Undocumented Windows 2000笔记之三:本机API
- Undocumented Windows 2000笔记之四:编写内核模式驱动
- 《Undocumented Windows 2000 Secrets》翻译 --- 第一章(1)
- 《Undocumented Windows 2000 Secrets》翻译 --- 第一章(2)
- 《Undocumented Windows 2000 Secrets》翻译 --- 第一章(3)
- 《Undocumented Windows 2000 Secrets》翻译 --- 第二章(1)
- 《Undocumented Windows 2000 Secrets》翻译 --- 第二章(2)
- 《Undocumented Windows 2000 Secrets》翻译 --- 第三章(1)
- VB.NET 特殊字符
- C语言指针小结
- 32bit g++编译64位整数作为key的__gnu_cxx::hash_map的编译错误问题
- 100个最佳Linux站点收藏
- Java编程中“为了性能”尽量要做到的一些地方
- Undocumented windows message 0x0313 & TTaskBarMenu
- 浅谈android的selector,背景选择器
- DP总结..未完待续
- Bridge模式C++代码
- axis tomcat 下调用ws ,can't declare any more prefixes in this context解决
- 关于left join 查询的一个小误区
- struts2中包内的全局视图与整个应用程序范围的全局视图
- Oracle数据库中插入日期型数据
- 水果表达方式