User Tools

Site Tools


hyperlinks_20in_20text_20boxes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
hyperlinks_20in_20text_20boxes [2018/03/31 13:19] – external edit 127.0.0.1hyperlinks_20in_20text_20boxes [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 //by Richard Russell, January 2007//\\ \\ **The code in this article is not applicable to Windows 9x, Windows Me or Windows NT4.**\\ \\  On occasion you may want to incorporate clickable //hyperlinks// in some text displayed in a dialogue box or elsewhere. For example you may want to incorporate a web or email address in a page of help text. One way of doing that would be to write the text in HTML and display it using your browser (for example in an [[/Using%20an%20ATL%20container%20control|ATL container control]]) but a simpler method is described in this article. This method also gives you control over the action to be taken when the link is clicked.\\ \\  You must initially prepare the text to be displayed, where the hyperlinks are delimited using **<A>** and **</A>** tags as in the following example:\\ \\  //by Richard Russell, January 2007//\\ \\ **The code in this article is not applicable to Windows 9x, Windows Me or Windows NT4.**\\ \\  On occasion you may want to incorporate clickable //hyperlinks// in some text displayed in a dialogue box or elsewhere. For example you may want to incorporate a web or email address in a page of help text. One way of doing that would be to write the text in HTML and display it using your browser (for example in an [[/Using%20an%20ATL%20container%20control|ATL container control]]) but a simpler method is described in this article. This method also gives you control over the action to be taken when the link is clicked.\\ \\  You must initially prepare the text to be displayed, where the hyperlinks are delimited using **<A>** and **</A>** tags as in the following example:\\ \\ 
 +<code bb4w>
         linktext$ = "For details of the full version of BBC BASIC for Windows email "+ \         linktext$ = "For details of the full version of BBC BASIC for Windows email "+ \
         \       "<A>info@rtrussell.co.uk</A> or visit <A>http://www.bbcbasic.co.uk/</A>"         \       "<A>info@rtrussell.co.uk</A> or visit <A>http://www.bbcbasic.co.uk/</A>"
 +</code>
 Here two hyperlinks are included in the text string, but there can be as many as you like. You can also incorporate **line breaks** using the usual CRLF sequence (**"CHR$13+CHR$10"**).\\ \\  You can display the text either in a dialogue box or on your main output window. The method used differs slightly between these options, and will be described separately.\\ \\  Here two hyperlinks are included in the text string, but there can be as many as you like. You can also incorporate **line breaks** using the usual CRLF sequence (**"CHR$13+CHR$10"**).\\ \\  You can display the text either in a dialogue box or on your main output window. The method used differs slightly between these options, and will be described separately.\\ \\ 
 ===== Dialogue box ===== ===== Dialogue box =====
 \\  Firstly some initialisation:\\ \\  \\  Firstly some initialisation:\\ \\ 
 +<code bb4w>
         INSTALL @lib$+"WINLIB2B"         INSTALL @lib$+"WINLIB2B"
  
Line 15: Line 18:
         SYS "GetProcAddress", shell32%, 258 TO LinkWindow_RegisterClass%         SYS "GetProcAddress", shell32%, 258 TO LinkWindow_RegisterClass%
         SYS LinkWindow_RegisterClass%         SYS LinkWindow_RegisterClass%
 +</code>
 Note that in this application you must use **WINLIB2B** (rather than WINLIB2 or WINLIB2A) so that the **WM_NOTIFY** messages are forwarded and can be intercepted using **ON SYS**.\\ \\  The next step is to create the dialogue box. In this example it contains only the link window, but you can of course incorporate any of the normal dialogue box controls:\\ \\  Note that in this application you must use **WINLIB2B** (rather than WINLIB2 or WINLIB2A) so that the **WM_NOTIFY** messages are forwarded and can be intercepted using **ON SYS**.\\ \\  The next step is to create the dialogue box. In this example it contains only the link window, but you can of course incorporate any of the normal dialogue box controls:\\ \\ 
 +<code bb4w>
         lwid% = 101         lwid% = 101
         dlg% = FN_newdialog("Hyperlink control", 200, 20, 150, 140, 8, 1000)         dlg% = FN_newdialog("Hyperlink control", 200, 20, 150, 140, 8, 1000)
Line 22: Line 27:
         WS_VISIBLE = &10000000         WS_VISIBLE = &10000000
         PROC_dlgctrl(dlg%, "", lwid%, 20, 20, 96, 40, WS_CHILD + WS_VISIBLE, "Link Window")         PROC_dlgctrl(dlg%, "", lwid%, 20, 20, 96, 40, WS_CHILD + WS_VISIBLE, "Link Window")
 +</code>
 Note that the link window has been allocated the ID number **101**. Refer to the documentation for [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#dlgitem|PROC_dlgitem]] for the meaning of the other parameters.\\ \\  Now you can display the dialogue box and load the required link text:\\ \\  Note that the link window has been allocated the ID number **101**. Refer to the documentation for [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#dlgitem|PROC_dlgitem]] for the meaning of the other parameters.\\ \\  Now you can display the dialogue box and load the required link text:\\ \\ 
 +<code bb4w>
         PROC_showdialog(dlg%)         PROC_showdialog(dlg%)
         SYS "SetDlgItemText", !dlg%, lwid%, linktext$         SYS "SetDlgItemText", !dlg%, lwid%, linktext$
 +</code>
 Note the use of the control's ID number **lwid%**.\\ \\  Finally you need to be able to detect when one of the links is clicked, so that you can take the appropriate action. You do that in a similar way to responding to menu and button clicks, using **ON SYS**:\\ \\  Note the use of the control's ID number **lwid%**.\\ \\  Finally you need to be able to detect when one of the links is clicked, so that you can take the appropriate action. You do that in a similar way to responding to menu and button clicks, using **ON SYS**:\\ \\ 
 +<code bb4w>
         *SYS 1         *SYS 1
         WM_NOTIFY = &4E         WM_NOTIFY = &4E
         ON SYS PROCsys(@msg%, @wparam%, @lparam%) : RETURN         ON SYS PROCsys(@msg%, @wparam%, @lparam%) : RETURN
 +</code>
 The **PROCsys** routine is listed at the end of the article.\\ \\  The **PROCsys** routine is listed at the end of the article.\\ \\ 
 ===== Main output window ===== ===== Main output window =====
 \\  Firstly some initialisation:\\ \\  \\  Firstly some initialisation:\\ \\ 
 +<code bb4w>
         INSTALL @lib$+"WINLIB5"         INSTALL @lib$+"WINLIB5"
  
Line 40: Line 51:
         SYS "GetProcAddress", shell32%, 258 TO LinkWindow_RegisterClass%         SYS "GetProcAddress", shell32%, 258 TO LinkWindow_RegisterClass%
         SYS LinkWindow_RegisterClass%         SYS LinkWindow_RegisterClass%
 +</code>
 You can alternatively use the **WINLIB5A** library, in which case remember to pass the window handle **@hwnd%** as the first parameter of **FNcreatewindow**.\\ \\  The link window is created, with the required text, as follows:\\ \\  You can alternatively use the **WINLIB5A** library, in which case remember to pass the window handle **@hwnd%** as the first parameter of **FNcreatewindow**.\\ \\  The link window is created, with the required text, as follows:\\ \\ 
 +<code bb4w>
         lwid% = 101         lwid% = 101
         WS_BORDER = &800000         WS_BORDER = &800000
         hlink% = FN_createwindow("Link Window", linktext$, 50, 100, 400, 80, \         hlink% = FN_createwindow("Link Window", linktext$, 50, 100, 400, 80, \
         \                        lwid%, WS_BORDER, 0)         \                        lwid%, WS_BORDER, 0)
 +</code>
 Refer to the documentation for [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#fnwindow|FN_createwindow]] for the meaning of the parameters. \\ \\  Finally you need to be able to detect when one of the links is clicked, so that you can take the appropriate action. You do that in a similar way to responding to menu and button clicks, using **ON SYS**:\\ \\  Refer to the documentation for [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#fnwindow|FN_createwindow]] for the meaning of the parameters. \\ \\  Finally you need to be able to detect when one of the links is clicked, so that you can take the appropriate action. You do that in a similar way to responding to menu and button clicks, using **ON SYS**:\\ \\ 
 +<code bb4w>
         *SYS 1         *SYS 1
         WM_NOTIFY = &4E         WM_NOTIFY = &4E
         ON SYS PROCsys(@msg%, @wparam%, @lparam%) : RETURN         ON SYS PROCsys(@msg%, @wparam%, @lparam%) : RETURN
 +</code>
 The **PROCsys** routine is listed below.\\ \\  The **PROCsys** routine is listed below.\\ \\ 
 ===== PROCsys ===== ===== PROCsys =====
 \\  The //interrupt service routine// listed below responds the **WM_NOTIFY** messages received from the link window when one of the hyperlinks is clicked:\\ \\  \\  The //interrupt service routine// listed below responds the **WM_NOTIFY** messages received from the link window when one of the hyperlinks is clicked:\\ \\ 
 +<code bb4w>
         DEF PROCsys(M%, W%, L%)         DEF PROCsys(M%, W%, L%)
         CASE M% OF         CASE M% OF
Line 63: Line 80:
         ENDCASE         ENDCASE
         ENDPROC         ENDPROC
 +</code>
 If there is more than one hyperlink in the text you can determine which was clicked from the **nmlink.item.iLink%** value (0 corresponds to the first hyperlink, 1 to the second etc.). For the purposes of demonstration the value is printed to the screen; in a real application you will want to take a different action.\\ \\  Note that the usual [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#interrupts|precautions]] related to interrupt service routines apply, and you may wish to set a global flag which is tested elsewhere rather than process the action within **PROCsys**.\\ \\  If, as is likely, your program needs to respond to other **ON SYS** events, such as menu selections and button presses, you will need to extend the **PROCsys** routine by adding a **WHEN** clause to intercept the **WM_COMMAND** (&111) messages. If there is more than one hyperlink in the text you can determine which was clicked from the **nmlink.item.iLink%** value (0 corresponds to the first hyperlink, 1 to the second etc.). For the purposes of demonstration the value is printed to the screen; in a real application you will want to take a different action.\\ \\  Note that the usual [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#interrupts|precautions]] related to interrupt service routines apply, and you may wish to set a global flag which is tested elsewhere rather than process the action within **PROCsys**.\\ \\  If, as is likely, your program needs to respond to other **ON SYS** events, such as menu selections and button presses, you will need to extend the **PROCsys** routine by adding a **WHEN** clause to intercept the **WM_COMMAND** (&111) messages.
hyperlinks_20in_20text_20boxes.1522502364.txt.gz · Last modified: 2024/01/05 00:17 (external edit)