I hate writing help files, in fact detest it, so i went looking for a way to use tooltip to do it as i wrote my apps, i got a few ideas from here and there and put the following Demo together which i now use in Every Application that uses a Gui. It has some error checking for Illegal chars eg : . \ etc and can detect any Control that has text (except a static). It is also GUI sensitive and you can have the same named buttons on any Gui displaying different Tooltips, you will see this in the demo.
The best thing is not having any more help files to write, and tooltip is flexible enough to be NOT in anybodys way when using the programs.
If anybody with more experience can go over my code and shorten and tighten it a little more, i would appreciate it.
Code:
; Language: English
; Platform: Win9x/NT
; Author: T. Gowshall <trubbleguy@optusnet.com.au>
; MouseOver and display Tooltip Demo
#NoEnv
#SingleInstance,Force
Gosub buttoninfo ;get the tooltip info for the mouseover
;this is sample Gui replace with your Gui
Gui, Add, Button, x16 y7 w90 h40 gshowgui2, Show Gui 2`nMore examples
Gui, Add, Edit,x16 y57 w90 L1 ,text
Gui, Add, Button, x126 y7 w90 h40 , Button2
Gui, Add, CheckBox, x126 y48 w90 h40 , funny box
Gui, Add, Button, x236 y7 w90 h40 , Button3
Gui, Add, Button, x346 y7 w90 h40 , Button4
Gui, Add, Button, x456 y7 w90 h40 gGuiClose , exit
Gui, Add, Button, x456 y57 w90 h20 ,small exit
Gui, 2:Add, Button, x16 y7 w90 h40 gclosegui2, Close Gui 2
Gui, 2:Add, Edit,x16 y57 w90 L1 ,text
Gui, 2:Add, Button, x126 y7 w90 h40 , Button2`nThree lines`nand still tooltips
Gui, 2:Add, CheckBox, x126 y48 w90 h40 , funny box
Gui, 2:Add, Button, x236 y7 w90 h40 , Click for`n C:\-.
Gui, 2:Add, Button, x346 y7 w90 h40 , Button4
Gui, 2:Add, Button, x456 y7 w90 h40 gGuiClose , exit
Gui, 2:Add, Button, x456 y57 w90 h20 ,Small Exit
Gui, Show, x131 y91 h90 w575, First GUI Window
;the next line is a must and must be placed before Return in the main loop.
;usually after GUI SHOW
OnMessage(0x200,"MOUSEOVER")
Return
;###############################################
buttoninfo:
;define the tooltips for the Control here, the number 1 is for Gui 1:
;If the Control has spaces in the name eg. word1 word2,
;make the variable word1word2 without spaces
;all spaces in the Controls name are removed for the variable,
TT_1_ShowGui2MoreExamples=this button turns on`nthe other Gui
TT_2_CloseGui2=this button will close`nthis second Gui
TT_1_text=ooh look its text`nIt will only Display like this while it displays 'text'`nChange the word text in the box and see what happens`n after you move the mouse away and then back to this control
TT_1_funnybox=ooh look its funny box on GUI 1
TT_1_Button2=this is button two`nIt used to popup "BUTTON 2"
TT_2_Button2Threelinesandstilltooltips =three lines of text, and Tooltips work
TT_1_Button3=this is button three`nOR Button 3
TT_2_clickforC=this button has`nlots of bad stuff like`n: \ - and . in it
TT_1_Button4=this is button four `nOn Gui 1
TT_2_Button4=this is button four `nOn Gui 2
TT_1_exit=exit by clicking here`nOr you can just`nKeep Playing`nThis is Gui 1 `nAnother message line `nAnother message line `nAnother message line `nAnother message line `nAnother message line `nAnother message line
TT_2_exit=exit by clicking here`nThis button works the same as the one on Gui 1`nBut we are over Gui 2
TT_2_SmallExit=This Control has spaces in the name but it works`nSmallExit is how its assigned to the Variable`nNot Small Exit`nand its displaying on Gui 2
Return
;###############################################
;The bit that does all the work
MOUSEOVER()
{
If A_Gui<=0 ;check if mouse is not on any gui
{
Tooltip ;clear before return
Return
}
{
MouseGetPos, X,Y,,, ;get the mouse co-ordinates
X:=X+20 ;move it over a bit
_tword=%A_GuiControl% ;make A_GuiControl a modifyable variable
StringReplace,_tword,_tword,%A_Space%,,all ;remove the spaces so it can find the tooltip
StringReplace,_tword,_tword,-,,all ;remove -
StringReplace,_tword,_tword,:,,all ;remove :
StringReplace,_tword,_tword,\,,all ;remove \
StringReplace,_tword,_tword,.,,all ;remove .
StringReplace,_tword,_tword,`n,,all ;remove any line returns
_tip:=TT_%A_Gui%_%_tword% ;get the tooltip to display
Tooltip,%_tip%,%X%,%Y% ;display it
}
}
Return
;###############################################
;Stuff below here is just code #################
showgui2:
Gui, 2:Show, x131 y220 h90 w575, Second GUI Window
Return
;###############################################
closegui2:
Gui, 2:cancel
Return
GuiClose:
ExitApp