I have a VCL form that is set for bsDialog
with biHelp
enabled ("?" icon in application bar).
I am following this example: http://delphi.about.com/od/adptips2006/qt/custom_bihelp.htm
However I cannot get the WMNCLBUTTONDOWN
Windows Message to appear when I click the "?" button. It only seems to fire when I click on the title bar (like I was going to drag the window around.
Code:
procedure TMainFrm.WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown);
begin
ShowMessage('WMNCLBUTTONDOWN Pre-Help') ;
if Msg.HitTest = HTHELP then
Msg.Result := 0 // "eat" the message
else
inherited;
end;
procedure TMainFrm.WMNCLBUTTONUP(var Msg: TWMNCLButtonUp);
begin
if Msg.HitTest = HTHELP then
begin
Msg.Result := 0;
ShowMessage('Need help?') ;
end
else
inherited;
end;
Again, I see the "Pre-Help" message when I click on the title bar, but not when I click on the "?" button. Why is this? I'm trying to show a separate form when that button is clicked.
The modal message loop of ShowMessage
interferes with the message processing. Use OutputDebugString
, for example, to see that the messages fire as your expect:
type
TMainFrm = class(TForm)
protected
procedure WMNCLButtonDown(var Msg: TWMNCLButtonDown);
message WM_NCLBUTTONDOWN;
procedure WMNCLButtonUp(var Msg: TWMNCLButtonUp);
message WM_NCLBUTTONUP;
end;
....
procedure TMainFrm.WMNCLButtonDown(var Msg: TWMNCLButtonDown);
begin
if Msg.HitTest = HTHELP then
begin
OutputDebugString('Help button down');
Msg.Result := 0;
end
else
inherited;
end;
procedure TMainFrm.WMNCLButtonUp(var Msg: TWMNCLButtonUp);
begin
if Msg.HitTest = HTHELP then
begin
OutputDebugString('Help button up');
Msg.Result := 0;
end
else
inherited;
end;
Remember that buttons are not pressed until they are released. So you should not be taking action like showing dialogs when the button goes down. Wait until WM_NCLBUTTONUP
before showing another dialog.