Mega Code Archive

 
Categories / Delphi / Forms
 

Execute a Custom Action on the Forms Help button Click (biHelp in Delphi)

Title: Execute a Custom Action on the Form's Help button Click (biHelp in Delphi) If the form's BorderStyle property is bsDialog and biHelp is included in BorderIcons, a question mark appears in the form's title bar and when clicked, the cursor changes to crHelp. If you want to execute some custom code when the user clicks the Help button, you need to handle two Windows messages: WM_NCLBUTTONUP and WM_NCLBUTTONDOWN. Those messages are posted to the window when the user presses and releases the left mouse button while the cursor is within the non-client area of a window. Here's a simple implementation of the custom biHelp-click action: type THelpForm = class(TForm) private procedure WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ; message WM_NCLBUTTONDOWN; procedure WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ; message WM_NCLBUTTONUP; end; var HelpForm: THelpForm; implementation {$R *.dfm} procedure THelpForm.WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ; begin if Msg.HitTest = HTHELP then Msg.Result := 0 // "eat" the message else inherited; end; procedure THelpForm.WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ; begin if Msg.HitTest = HTHELP then begin Msg.Result := 0; ShowMessage('Need help?') ; end else inherited; end;