=====Adding tooltips to a dialogue box===== //by Richard Russell and Howard Bolton, May 2006//\\ \\ Tooltips are small (usually light yellow) windows containing useful information, which pop up when you 'hover' the mouse over a particular control or region of the screen. This article describes how you can add tooltips to a dialogue box; there are other articles for adding tooltips to a [[/Adding%20tooltips%20to%20the%20status%20bar|status bar]] and to the [[/Tooltips%20on%20the%20main%20output%20window|main output window]] (the main Help documentation describes how to add tooltips to a [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#addtooltips|toolbar]]).\\ \\ Firstly we create and display a dialogue box in the usual way (see the main help documentation [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#winlib2|here]]). For the purpose of this example the dialogue box contains two editboxes, a combobox, a list box and two push buttons: INSTALL @lib$+"WINLIB2" INSTALL @lib$+"WINLIB5A" BS_DEFPUSHBUTTON = 1 CBS_DROPDOWNLIST = 3 ES_AUTOHSCROLL = &80 ES_NUMBER = &2000 WS_GROUP = &20000 dlg%=FN_newdialog("Dialogue box",20,20,160,128,8,504) PROC_groupbox(dlg%,"Group box",0,4,4,152,96,WS_GROUP) PROC_editbox(dlg%,"Text box",101,12,20,64,12,ES_AUTOHSCROLL) PROC_editbox(dlg%,"123456",102,82,20,64,12,ES_NUMBER) PROC_combobox(dlg%,"",103,12,40,64,60,CBS_DROPDOWNLIST) PROC_listbox(dlg%,"",104,82,40,64,48,0) PROC_pushbutton(dlg%,"OK",1,12,108,56,14,WS_GROUP+BS_DEFPUSHBUTTON) PROC_pushbutton(dlg%,"Cancel",2,92,108,56,14,0) PROC_showdialog(dlg%) Note the installation of the **WINLIB5A** library which is needed later.\\ \\ Next we perform any initialisation of the dialogue box required; in this case we enter some data into the combobox and the list box: CB_ADDSTRING = &143 CB_SETCURSEL = &14E LB_ADDSTRING = &180 SYS "SendDlgItemMessage",!dlg%,103,CB_ADDSTRING,0,"Combobox 1" SYS "SendDlgItemMessage",!dlg%,103,CB_ADDSTRING,0,"Combobox 2" SYS "SendDlgItemMessage",!dlg%,103,CB_ADDSTRING,0,"Combobox 3" SYS "SendDlgItemMessage",!dlg%,103,CB_ADDSTRING,0,"Combobox 4" SYS "SendDlgItemMessage",!dlg%,103,CB_SETCURSEL,0,0 SYS "SendDlgItemMessage",!dlg%,104,LB_ADDSTRING,0,"Listbox item 0" SYS "SendDlgItemMessage",!dlg%,104,LB_ADDSTRING,0,"Listbox item 1" SYS "SendDlgItemMessage",!dlg%,104,LB_ADDSTRING,0,"Listbox item 2" SYS "SendDlgItemMessage",!dlg%,104,LB_ADDSTRING,0,"Listbox item 3" So far everything has been conventional. Now comes the code for creating the tooltips: TTS_ALWAYSTIP = 1 TTS_NOPREFIX = 2 WS_CHILD = &40000000 WS_VISIBLE = &10000000 htt% = FN_createwindow(!dlg%,"tooltips_class32","",0,0,0,0,0, \ \ WS_CHILD+WS_VISIBLE+TTS_ALWAYSTIP+TTS_NOPREFIX,0) DIM ti{cbSize%, uFlags%, hwnd%, uId%, rect{l%,t%,r%,b%}, hinst%, lpszText%} PROC_CreateToolTip(!dlg%, htt%, 101, "This is a text-input box") PROC_CreateToolTip(!dlg%, htt%, 102, "This is a numeric-input box") PROC_CreateToolTip(!dlg%, htt%, 103, "This is a combo box") PROC_CreateToolTip(!dlg%, htt%, 104, "This is a list box") PROC_CreateToolTip(!dlg%, htt%, 1, "This is the default push button") PROC_CreateToolTip(!dlg%, htt%, 2, "This is another push button") Finally we need the procedure to send the Tooltip text to each dialogue item. This procedure can be used for any dialogue box in your program by passing appropriate values for the handles to the dialogue box and the Tooltip (note the important addition of CHR$0 to each of the strings): DEF PROC_CreateToolTip(hdlg%, htt%, id%, tip$) TTF_IDISHWND = 1 TTF_SUBCLASS = 16 TTM_ADDTOOL = &404 tip$ += CHR$0 SYS "GetDlgItem", hdlg%, id% TO ti.uId% ti.cbSize% = DIM(ti{}) ti.uFlags% = TTF_SUBCLASS + TTF_IDISHWND ti.hwnd% = hdlg% ti.lpszText% = !^tip$ SYS "SendMessage", htt%, TTM_ADDTOOL, 0, ti{} ENDPROC Now all you need to do is hover the mouse over the controls and see the effect.