Use Onhelp () to achieve context-sensitive HTML HELP in BCB

zhaozj2021-02-11  226

About HTML HELP, the most recommended on 9CBS is how to use Shellexecute () or htmlhelp () to open the corresponding help file and help topics. I have found some of the data after the test success of a method of simple and easy display context-sensitive HTML HELP in BCB, the effects of the old-style context-sensitive WinHelp () are identical. This method is small, and how scalability is good. When you add the subject in the help file, you don't need to change your code at all, just modify the HelpContext attribute value of each control on the form. .

There are three topic files 1.HTM, 2.HTM, 3.HTM, 3 TEDIT controls on the form of the program, and the purpose to achieve is: when pressing the F1 button on the first TEDIT control Displays the contents of the 1.HTM, press the contents of the 2.HTM when pressing the F1 buttons on the second TEDIT control, and push it according to the class. This is the so-called context sensitive help. Of course, you can pass which TEDIT control has input focus by intercepting the F1 key, thereby calling shellexecute () or htmlhelp () to display the corresponding HTML topic. But this method is scalable, and the program code needs to be modified when adding an HTML file. The practice is as follows: 1. Use the text editor to edit the HTML HELP's Project file * .hp, add the following. You can also join through the interface of HTML HELP WORKSHOP. This is equivalent to mapping 3 HTML files into 3 context IDs. Then recompile your Project. [Alias] IDH_CHAPTER1 = 1.htmidh_chapter2 = 2.htmidh_chapter3 = 3.htm

[Map] #define IDH_CHAPTER1 1001 # define IDH_Chapter2 1002 # define IDH_CHAPTER3 10032, setting 3 TEDIT controls on the form of the form is 1001, 1002, 1003.3, modify the program code, overload Tapplication-> onhelp (of course You can also overload each Form's onhelp, using htmlhelp () to display the corresponding context sensitive help. When the Command is assigns to Help_Context, Data is the HelpContext attribute value of the control of the control of the input focus when you press the F1 key. __fastcall tform1 :: tFORM1 (TComponent * Owner: tform (ooner) {Application-> HelpFile = "main.chm"; Application-> onhelp = apphelp;} // ------------- -------------------------------------------------- ----------- BOOL __FASTCALL TFORM1 :: AppHELP (Word Command, Int Data, Bool & Callhelp) {Switch (CASE HELP_CONTEXT:

Htmlhelp (GetDeskTopWindow (), Application-> HOLPFILE.C_STR (), HH_HELP_CONTEXT, DATA); CallHelp = FALSE

Break;

DEFAULT:

Callhelp = true;}

转载请注明原文地址:https://www.9cbs.com/read-4335.html

New Post(0)