问题是,我希望鼠标不受控制,甚至超出窗体,但是当鼠标离开控件时,它不再捕获鼠标事件.有没有一种方法可以处理WM_MOUSEMOVE和WM_LbuttonUP消息,而鼠标不在控件之上?
解决方法 Releasecapture适用于Wincontrols,另一种方式可能是Mousehook.那只是一个演示….unit MouseHook;// 2012 by Thomas Wassermanninterfaceuses windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs;type TForm3 = class(TForm) procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end;var Form3: TForm3;implementationvar HookHandle: Cardinal;Type tagMsllHOOKSTRUCT = record POINT: TPoint; mouseData: DWORD; flags: DWORD; time: DWORD; DWExtraInfo: DWORD; end; TMsllHOOKSTRUCT = tagMsllHOOKSTRUCT; PMsllHOOKSTRUCT = ^TMsllHOOKSTRUCT;{$R *.dfm}function LowLevelMouseProc(nCode: Integer; wParam: wParam; lParam: lParam): LRESulT; stdcall;var Delta:Smallint;begin if (nCode >= 0) then begin Form3.Caption := Format('X: %d Y: %d ',[PMsllHOOKSTRUCT(lParam)^.Point.X,PMsllHOOKSTRUCT(lParam)^.Point.Y]); if wParam = WM_LbuttonDOWN then Form3.Caption := Form3.Caption + ' LD'; if wParam = WM_LbuttonUP then Form3.Caption := Form3.Caption + ' LU'; if wParam = WM_RbuttonDOWN then Form3.Caption := Form3.Caption + ' RD'; if wParam = WM_RbuttonUP then Form3.Caption := Form3.Caption + ' RU'; if wParam = WM_MOUSEMOVE then Form3.Caption := Form3.Caption + ' Move'; Delta := PMsllHOOKSTRUCT(lParam)^.mouseData shr 16; if wParam = WM_MOUSEWHEEL then begin Form3.Caption := Form3.Caption + ' Wheel ' ; if Delta=120 then Form3.Caption := Form3.Caption + ' KliCK' else if Delta > 0 then Form3.Caption := Form3.Caption +' UP' else if Delta < 0 then Form3.Caption := Form3.Caption +' DOWN' end; if wParam = WM_MOUSEHWHEEL then begin Form3.Caption := Form3.Caption + ' HWheel'; if Delta=120 then Form3.Caption := Form3.Caption + ' KliCK' else if Delta > 0 then Form3.Caption := Form3.Caption +' UP' else if Delta < 0 then Form3.Caption := Form3.Caption +' DOWN' end; Form3.Caption := Form3.Caption +' >> '+ IntToStr(Delta) end; Result := CallNextHookEx(HookHandle,nCode,wParam,lParam);end;function InstallMouseHook: Boolean;begin Result := False; if HookHandle = 0 then begin HookHandle := SetwindowsHookEx(WH_MOUSE_LL,@LowLevelMouseProc,hInstance,0); Result := HookHandle <> 0; end;end;procedure TForm3.FormCreate(Sender: TObject);begin InstallMouseHook;end;procedure TForm3.FormDestroy(Sender: TObject);begin if HookHandle <> 0 then UnhookwindowsHookEx(HookHandle);end;end.总结
以上是内存溢出为你收集整理的delphi – 鼠标拖出边界后,控件如何接收鼠标事件?全部内容,希望文章能够帮你解决delphi – 鼠标拖出边界后,控件如何接收鼠标事件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)