Undocumented windows message 0×0313 & TTaskBarMenu

來源:互聯網
上載者:User

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

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.