* These define the "hit test" or "what's there at the coordinates the user did something" #define HTERROR (-2) #define HTTRANSPARENT (-1) #define HTNOWHERE 0 #define HTCLIENT 1 #define HTCAPTION 2 #define HTSYSMENU 3 #define HTGROWBOX 4 #define HTSIZE HTGROWBOX #define HTMENU 5 #define HTHSCROLL 6 #define HTVSCROLL 7 #define HTMINBUTTON 8 #define HTMAXBUTTON 9 #define HTLEFT 10 #define HTRIGHT 11 #define HTTOP 12 #define HTTOPLEFT 13 #define HTTOPRIGHT 14 #define HTBOTTOM 15 #define HTBOTTOMLEFT 16 #define HTBOTTOMRIGHT 17 #define HTBORDER 18 #define HTREDUCE HTMINBUTTON #define HTZOOM HTMAXBUTTON #define HTSIZEFIRST HTLEFT #define HTSIZELAST HTBOTTOMRIGHT #define HTOBJECT 19 #define HTCLOSE 20 #define HTHELP 21 #define WM_NCMOUSEMOVE 0x00A0 * Left button actions #define WM_NCLBUTTONDOWN 0x00A1 #define WM_NCLBUTTONUP 0x00A2 #define WM_NCLBUTTONDBLCLK 0x00A3 * Right button actions #define WM_NCRBUTTONDOWN 0x00A4 #define WM_NCRBUTTONUP 0x00A5 #define WM_NCRBUTTONDBLCLK 0x00A6 * Middle button actions #define WM_NCMBUTTONDOWN 0x00A7 #define WM_NCMBUTTONUP 0x00A8 #define WM_NCMBUTTONDBLCLK 0x00A9 * Other button actions #define WM_NCXBUTTONDOWN 0x00AB #define WM_NCXBUTTONUP 0x00A PUBLIC TitleBarController TitleBarController = CREATEOBJECT("TitleBarController") TitleBarController.Register() DEFINE CLASS TitleBarController AS Custom IsActive = .F. PROCEDURE Register * DECLARE INTEGER DefWindowProc IN WIN32API INTEGER hwnd, INTEGER msg, INTEGER wparam, INTEGER lparam * * Tell Windows to send thisForm.HWnd the messages related to the right-mouse-button-going-down * Use other BINDEVENT()s for other actions you'd like to track BINDEVENT(_VFP.HWnd, WM_NCLBUTTONDOWN, THIS, "non_client_mouse_down") BINDEVENT(_VFP.HWnd, WM_NCMOUSEMOVE, THIS, "non_client_mouse_move") BINDEVENT(_VFP.HWnd, WM_NCLBUTTONUP, THIS, "non_client_mouse_up") BINDEVENT(_VFP.HWnd, WM_NCLBUTTONDBLCLK, THIS, "non_client_mouse_dbl") * ENDPROC * * * PROCEDURE non_client_mouse_down * LPARAMETERS tnHwnd, tnMsg, tnHitTest, tnCoords * * See where they did it LOCAL llDefaultProc llDefaultProc = .T. * IF m.tnHitTest = HTCAPTION * You can check GetAsyncKeyState() here to see if it's a Shift+Right click, or Ctrl+, etc. llDefaultProc = ! THIS.OnLeftClickTitleBar() ENDIF * DefWindowProc(m.tnHwnd, m.tnMsg, m.tnHitTest, m.tnCoords) * ENDPROC * * * PROCEDURE non_client_mouse_Up * LPARAMETERS tnHwnd, tnMsg, tnHitTest, tnCoords * IF m.tnHitTest = HTCAPTION THIS.IsActive = .F. ENDIF * DefWindowProc(m.tnHwnd, m.tnMsg, m.tnHitTest, m.tnCoords) * ENDPROC * * * PROCEDURE non_client_mouse_dbl * LPARAMETERS tnHwnd, tnMsg, tnHitTest, tnCoords * IF m.tnHitTest = HTCAPTION THIS.IsActive = .F. ENDIF * DefWindowProc(m.tnHwnd, m.tnMsg, m.tnHitTest, m.tnCoords) * ENDPROC * * * PROCEDURE non_client_mouse_move * LPARAMETERS tnHwnd, tnMsg, tnHitTest, tnCoords * LOCAL llDefaultProc llDefaultProc = .T. * IF m.tnHitTest = HTCAPTION * You can check GetAsyncKeyState() here to see if it's a Shift+Right click, or Ctrl+, etc. llDefaultProc = THIS.OnMove() ENDIF * DefWindowProc(m.tnHwnd, m.tnMsg, m.tnHitTest, m.tnCoords) * ENDPROC * * * PROCEDURE OnLeftClickTitleBar LOCAL llRetVal IF _SCREEN.WindowState = 2 THIS.IsActive = .T. llRetVal = .T. ENDIF RETURN llRetVal ENDPROC * * * PROCEDURE OnMove * LOCAL llRetVal * IF _SCREEN.WindowState = 2 ; AND THIS.IsActive * THIS.IsActive = .F. llRetVal = .T. * *-- To position must be restored. lnTop = _SCREEN.Top * LOCAL lnX, lnY = getMousePos (@lnX, @lnY) && gets cursor absolute position * *-- Get relative position of mouse pointer on title bar. lnPos = 100/_SCREEN.Width * lnX _SCREEN.LockScreen = .T. _SCREEN.WindowState = 0 * *-- Move window in correct position. _SCREEN.Top = lnTop * *-- Reset _screen left position so that mouse is relative to original position. lnNewPos = _SCREEN.Width / 100 * lnPos _SCREEN.Left = lnX - lnNewPos _SCREEN.LockScreen = .F. * ENDIF * RETURN llRetVal * ENDPROC * * * ENDDEFINE * PROCEDURE getMousePos (x, y) LOCAL lcBuffer lcBuffer = Repli(Chr(0), 8) DECLARE SHORT GetCursorPos IN user32 STRING @ lpPoint = GetCursorPos (@lcBuffer) x = buf2dword(SUBSTR(lcBuffer, 1,4)) y = buf2dword(SUBSTR(lcBuffer, 5,4)) ENDPROC FUNCTION buf2dword (lcBuffer) RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ; Asc(SUBSTR(lcBuffer, 2,1)) * 256 +; Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +; Asc(SUBSTR(lcBuffer, 4,1)) * 16777216 ENDFUNC