Mega Code Archive

 
Categories / Delphi / Forms
 

Detecting Right Clicks on your forms title bar

Title: Detecting Right Clicks on your forms title bar Question: how do I detect a right click and/or kill the menu for my title bar? Answer: This is a relatively simple problem, you just need to know the correct windows message to trap. Here's how to do it: declaration: procedure WMNCRButtonDown(var Msg : TWMNCRButtonDown); message WM_NCRBUTTONDOWN; definition: procedure TMainFrm.WMNCRButtonDown(var Msg : TWMNCRButtonDown); begin if (Msg.HitTest = htCaption) then begin (your code here & the next line kills the menu) Msg.HitTest := 0; end else inherited; end; Additional Info: NC stands for non-client WMNCLButtonDown or WMNCMButtonDown may be used instead for left or middle button respectively No WM_NCRBUTTONUP message is generated, only a WM_RBUTTONUP when the mouse is release This has been tested with Delphi 5 on win2k, 95, 98 and NT4. It should work also fine with earlier versions of delphi, but these have not been tested.