A
Avalon
Unregistered / Unconfirmed
GUEST, unregistred user!
当在标题栏上点击鼠标左键后,能收到WM_NCLBUTTONDOWN(按下的消息),但是不一定能收到WM_NCLBUTTONUP的消息(释放左键的消息)。Google了一下,发现Windows的确有这个问题(MSDN干脆完全就没说明)。当在非客户区点击鼠标左键并释放时,系统会发送窗口的WM_LBUTTONUP 不是WM_NCLBUTTONUP系统会发送WM_NCLBUTTONUP的时刻:1. 双击标题栏2. 在客户区按住鼠标左键,但是在非客户区释放鼠标左键有找到了一个C++的例子 于是打算把它转成DELPHI的 但发现PostMessage伪造WM_NCLBUTTONUP无响应 不知道问题在哪里unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; private { Private declarations } public { Public declarations } end;var Form1: TForm1; HMsgHook: HHook; FCLButtonDown: Boolean;implementation{$R *.dfm}function GetMsgProc(Code: Integer; WPARAMS: WPARAM; LPARAMS: LPARAM): LRESULT; stdcall;var MHS: PMOUSEHOOKSTRUCT;begin if Code = HC_ACTION then begin if WPARAMS = WM_NCLBUTTONDOWN then begin MHS := PMOUSEHOOKSTRUCT(LPARAMS); if (MHS.wHitTestCode = HTCAPTION) and (Form1.Handle = MHS.hwnd) then begin FCLButtonDown := True; SystemParametersInfo(SPI_SETDRAGFULLWINDOWS,1,nil,SPIF_UPDATEINIFILE); end; end; if WPARAMS = WM_NCLBUTTONUP then begin SystemParametersInfo(SPI_SETDRAGFULLWINDOWS,0,nil,SPIF_UPDATEINIFILE); FCLButtonDown := False; MessageBeep(0); end; if WPARAMS = WM_LBUTTONUP then begin MHS := PMOUSEHOOKSTRUCT(LPARAMS); if (FCLButtonDown = True) and (Form1.Handle = MHS.hwnd) then begin SendMessage(Form1.Handle, WM_NCLBUTTONUP, HTCAPTION, MAKELONG(mhs.pt.x, mhs.pt.y)); SystemParametersInfo(SPI_SETDRAGFULLWINDOWS,0,nil,SPIF_UPDATEINIFILE); FCLButtonDown := False; end; end; end; Result := CallNextHookEx(HmsgHOOK, Code, WPARAMS, LPARAMS);end;initialization FCLButtonDown := False; HMsgHOOK := SetWindowsHookEx(WH_MOUSE, GetMsgProc, HInstance, GetCurrentThreadId);finalization if HMsgHOOK <> 0 then begin UnhookWindowsHookEx(HmsgHOOK); end;end.