BorderIcons中的biHelp

I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
实现“这是什么?”的功能
实现“这是什么?”的功能
  常常看到有些窗口上有个?号,也就“这是什么?”的功能,,如果自已编程实现则就不一样了。比如:点击"帮助"按钮。。刚出现这是什么?”的功能。。这就要用到api了,其实 通过 postmessage ,可以实现。
  postmessage(handle, wm_syscommand, sc_contexthelp, 0);
是不是简单,哎,想当初,为了它,我找呀找。。。。。。
***********************************************************
如果标题栏上有问号按钮的时候,只要点一下,然后用‘?光标’点击带有helpcontext
的控件就能调出pophelp。
现在,midchild窗体上无法设置问号按钮。请问如何达到点击控件调出对应pophelp的目的?
下面的代码可以在任何地方Popup一个弹出式Help对话框:
请指定Application的HelpFile。
var
Pt: TSmallPoint;
ContextID: Integer;
begin
Pt := PointToSmallPoint(ClientToScreen(Point(0, 0)));
ContextID:=1;
Application.HelpCommand(HELP_SETPOPUP_POS, Longint(Pt));
Application.HelpCommand(HELP_CONTEXTPOPUP, ContextID);
end;
具体的可以使用GetCursorPos获得坐标,然后再获得ContextID,这个稍微复杂一点。
可以找到Cursor所在的控件的句柄,使用FindControl获得控件,然后执行Control.HelpContext;获得ID。
********************
设置了biHelp为true后,如果将form的BorderStyle设为bsDialog,或者BorderIcons的
biMinimize and biMaximize都设为false,那么在form的标题栏就会有个问号图标,点击后form的光标变为crHelp.
在你的每个控件的属性里都有一个叫做HelpContext的,这是和你的帮助文件相关联的。如果你制作的帮助文件,并指明了一种帮助风格,则当你使用这个HELP光标点击相应控件时,它会从你的帮助文件中取出帮助来显示。
********************
show my own help dialog when user clicks the biHelp border icon?
type
TForm1 = class(TForm)
private
procedure wmNCLButtonDown(var Msg: TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
procedure wmNCLButtonUp(var Msg: TWMNCLButtonUp); message WM_NCLBUTTONUP;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.wmNCLButtonDown(var Msg: TWMNCLButtonDown);
begin
if Msg.HitTest = HTHELP then
begin
Msg.Result := 0; // swallow mouse down on biHelp border icon
end
else
inherited;
end;
procedure TForm1.wmNCLButtonUp(var Msg: TWMNCLButtonUp);
begin
if Msg.HitTest = HTHELP then
begin
Msg.Result := 0;
ShowMessage('Hi!'); // Show your help here
end
else
inherited;
end;
**********************************************
然而有一个问题,如果是TSpeedButton之类的控件,根本无法使用这个功能,因为只要一按按钮,就会相当于点击了按钮一样,那么如何解决这个问题呢?
//去掉 WS_EX_CONTROLPARENT,这样一般窗体的控件才能响应上下文帮助
procedure FixContextHelp(Form: TCustomForm);
var
Loop, OldExStyle: Integer;
Handle: HWnd;
Control: TControl;
begin
for Loop := 0 to Form.ControlCount - 1 do
begin
Control := Form.Controls[Loop];
if (csAcceptsControls in Control.ControlStyle) and
(Control is TWinControl) then
begin
Handle := TWinControl(Control).Handle;
OldExStyle := GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE,
OldExStyle and not WS_EX_CONTROLPARENT)
end
end
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FixContextHelp(Self)
end;
 

Similar threads

S
回复
0
查看
794
SUNSTONE的Delphi笔记
S
S
回复
0
查看
797
SUNSTONE的Delphi笔记
S
S
回复
0
查看
625
SUNSTONE的Delphi笔记
S
顶部