The general dialog box in windwos, such as search, replacement, and font selection, has a common feature: there is a "Question mark" button in the upper right corner of the screen. When you click this "Question mark, the current mouse changes to? Number. Use this? When you click the control in the dialog box, a shadow prompt box is displayed, showing prompt text.
This is "What is this ?" Function. What is this? "Function.
Principle: When? When you click the control in the dialog box, the clicked control generates the wm_help message. Delphi automatically checks the helpfile and helpcontext attributes of the form. If both attributes are set, the corresponding HLP help file is displayed (this should be prepared by yourself ). This method works below D6, but in Delphi7, it doesn't work...
Currently, the solution in D7 is to use the EC control. When using it, you need to place three controls in the one widgets control on the form, and then set the corresponding properties. The advantage of this method is that it provides powerful functions.
However, I am annoyed with the above method: the size of a dialog box is large. To solve this what is this problem, we need to put three controls to solve the problem. In addition, the above method should change the user's habit of making what is this in Delphi!
To solve the above problem, I made a twhat component by myself. As long as I drag this component to the form, a standard Windows Prompt box will pop up!
Twhat source code:
Unit what;
Interface
Uses
Sysutils, classes, windows, controls, messages, forms, dialogs;
Type
Twhat = Class (tcomponent)
Private
Oldwindowproc: twndmethod;
Fhelpfile: string;
Protected
{Protected Declarations}
Public
Constructor create (aowner: tcomponent); override;
Published
Procedure newwindowproc (VAR message: tmessage );
Property helpfile: String read fhelpfile write fhelpfile; // Special Purpose
End;
Procedure register;
Implementation
{$ R *. DCR}
Procedure register;
Begin
Registercomponents ('gencheng', [twhat]);
End;
{Twhat}
Constructor twhat. Create (aowner: tcomponent );
VaR
Fform: tform;
Begin
Inherited create (aowner );
If not (csdesigning in componentstate) Then // not executed during the design period
If aowner is tform then
Begin
Fform: = tform (aowner );
Oldwindowproc: = fform. windowproc;
Fform. windowproc: = newwindowproc;
Fhelpfile: = fform. helpfile;
End
Else
Showmessage ('"aowner" shocould be a "tform "! ');
End;
Procedure twhat. newwindowproc (VAR message: tmessage );
VaR
Control: twincontrol;
Begin
If message. MSG = wm_help then
Begin
Control: = findcontrol (twmhelp (Message). helpinfo. hitemhandle); // The result of findcontrol is twincontrol.
If assigned (Control) then
Begin
Windows. winhelp (control. Handle, pchar (helpfile), help_setpopup_pos, longint (pointtosmallpoint (control. clientorigin); // you can set the coordinates of the displayed Help window to the upper left corner of the control.
Windows. winhelp (control. Handle, pansichar (helpfile), help_contextpopup, Control. helpcontext); // a Help window is displayed.
End
End
Else
Oldwindowproc (Message );
End;
End.
In addition, you can add onhelp events to achieve more powerful functions!