Uninitialized ented Windows message 0 × 0313 & ttaskbarmenu

Source: Internet
Author: User

When you right-click on a taskbar button, Windows sends an unordered ented 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 wocould use e.g. spy ++ to check whether possibly it generates generated ented 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.

 

 

Note: refer:

1. http://stackoverflow.com/questions/10430377/winapi-undocumented-windows-message-0x0313-stable

2. http://delphi.about.com/od/vclwriteenhance/a/ttaskbarmenu.htm

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.