|
Author
|
Topic: Balloon style ToolTips - popup help
|
William Burns Member
|
posted December 02, 2003 03:15 PM
A simple include file so you can easily add the fancy looking balloon style tooltips also known as "pop-up help" to your programs.It is very easy to use. The syntax is SetToolTip CbHndl, %CTLID, "Help Text" Here is the file: (feel free to use/update in any way to want) 'o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o-- ' ToolTips.inc by William Burns Last revised on 9/25/04 ' ' Used to add balloon style tooltips to your dialog items. Free to use as you see fit. ' ' Example Usage: 'CallBack Function DLGPROC ' Select Case CbMsg ' Case %WM_INITDIALOG ' SetToolTip hWnd, %IDCANCEL, "Press this to close without saving" '<--- this will add tooltip to a control ' SetToolTip hWnd, 0, "Program made by Me Inc." '<--- this will add tooltip to the main dialog background '... 'o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o-- ' NOTE: This include file uses the CommCtrl.Inc file too. So if you also need to use CommCtrl.Inc ' in your program, you will need to place the #Include "CommCtrl.Inc" line before inlcuding ' this file, and make sure you do not use the %NOTOOLTIPS 'o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o-- #If Not %Def(%WINAPI) #Include "win32api.inc" 'add win32api if not already added #EndIf #If Not %Def(%COMMCTRL_INC) %NOANIMATE = 1 %NOBUTTON = 1 %NOCOMBO = 1 %NOCOMBOEX = 1 %NODATETIMEPICK = 1 %NODRAGLIST = 1 %NOEDIT = 1 %NOFLATSBAPIS = 1 %NOHEADER = 1 %NOHOTKEY = 1 %NOIMAGELIST = 1 %NOIPADDRESS = 1 %NOLIST = 1 %NOLISTVIEW = 1 %NOMENUHELP = 1 %NOMONTHCAL = 1 %NOMUI = 1 %NONATIVEFONTCTL = 1 %NOPAGESCROLLER = 1 %NOPROGRESS = 1 %NOREBAR = 1 %NOSTATUSBAR = 1 %NOSYSLINK = 1 %NOTABCONTROL = 1 %NOTOOLBAR = 1 ' %NOTOOLTIPS = 1 ' Tool tips %NOTRACKBAR = 1 %NOTRACKMOUSEEVENT = 1 %NOTREEVIEW = 1 %NOUPDOWN = 1 #Include "CommCtrl.Inc" 'add if not already added #EndIf Type DLLVERINFO cbSize As Dword dwMajorVersion As Dword dwMinorVersion As Dword dwBuildNumber As Dword dwPlatformID As Dword End Type Declare Function DllVer(DVI As DLLVERINFO) As Long 'o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o-- Function SetToolTip(ByVal hDlg As Long, ByVal CtlID As Long, ByVal sText As String) As Long Static hWnd_ToolTip As Long Local TI As TOOLINFO 'Does tooltipclass window already exist? If not create one. If IsWindow(hWnd_ToolTip) = 0 Then Local iRet As Long Local iStyle As Long Local DVI As DLLVERINFO Local hDll As Dword Local dProcAddr As Dword InitCommonControls iStyle = %TTS_NOPREFIX 'default in case common control ver is too old 'the following ver check was suggested by MCM. Thanks hDll = GetModuleHandle("COMCTL32.DLL") 'get the handle for the loaded common control DLL If IsTrue hDll Then dProcAddr = GetProcAddress(hDll, "DllGetVersion") 'get the procedure address from the DLL If IsTrue dProcAddr Then DVI.CbSize = SizeOf (DVI) Call Dword dProcAddr Using DllVer(DVI) To iRet If iRet = %NOERROR Then 'MsgBox "Common Controls Ver " + Format$(DVI.dwMajorVersion) + "." + Format$(DVI.dwMinorVersion),,"Testing" If DVI.dwMajorVersion > 5 Or (DVI.dwMajorVersion = 5 And DVI.dwMinorVersion => 80) Then iStyle = %TTS_ALWAYSTIP Or %TTS_BALLOON 'new enough version, so use fancy ballon type End If End If End If End If hWnd_ToolTip = CreateWindowEx( 0, "tooltips_class32", "", iStyle, 0, 0, 0, 0, hDlg, ByVal 0&, GetModuleHandle(ByVal 0&), ByVal 0&) Dialog Send hWnd_ToolTip, %TTM_SETMAXTIPWIDTH, 0, 300 'suggested by Fred Buffington. Thanks Dialog Send hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOPOP, 15000 'Set Tooltip time 15 sec End If 'Do we have a good handle? If hWnd_ToolTip Then TI.cbSize = SizeOf(TI) TI.uFlags = %TTF_SUBCLASS Or %TTF_IDISHWND TI.hWnd = hDlg If CtlID = 0 Then TI.uId = hDlg 'if CtrlID = 0 then add tooltip to main dialog area Else TI.uId = GetDlgItem(hDlg, CtlID) 'add tooltip to control End If If SendMessage(hWnd_ToolTip, %TTM_GETTOOLINFO, 0, ByVal VarPtr(TI)) Then 'remove old tip first? Call SendMessage(hWnd_ToolTip, %TTM_DELTOOL, 0, ByVal VarPtr(TI)) End If sText = sText + Chr$(0) 'zero terminate the string TI.lpszText = StrPtr(sText) Function = SendMessage(hWnd_ToolTip, %TTM_ADDTOOL, 0, ByVal VarPtr(TI)) End If End Function 'o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--o-o--
------------------ "I haven't lost my mind... its backed up on tape... I think??"
[This message has been edited by William Burns (edited September 25, 2004).] IP: Logged |
William Burns Member
|
posted December 02, 2003 03:17 PM
And to show how to use it... here is a simple example program. 
#Compile Exe #Include "win32api.inc" #Include "ToolTips.inc" %MYBUTTON = 500 %MYTEXT = 510 '================================================== CallBack Function DLGPROC Select Case CbMsg Case %WM_INITDIALOG SetToolTip CbHndl, %MYBUTTON, "Click this to close the window" SetToolTip CbHndl, %MYTEXT, "This is the popup help for the textbox" SetToolTip CbHndl, 0, "This is the popup help for the dialog area" Case %WM_CLOSE Case %WM_COMMAND Select Case CbCtl Case %MYBUTTON If CbCtlMsg = %BN_CLICKED Then Dialog End CbHndl End Select Case Else End Select End Function '================================================== Function PbMain Local hDlg As Dword Local hMenu2 As Long Dialog New 0, "Test PopUp window", 0, 0, 170, 100, %WS_POPUP Or %DS_MODALFRAME Or %WS_CAPTION Or %WS_MINIMIZEBOX Or %WS_SYSMENU Or %DS_CENTER, 0 To hDlg Control Add "Button", hDlg, %MYBUTTON, "&Close", 50, 45, 50, 15, %WS_CHILD Or %WS_VISIBLE Or %BS_PUSHBUTTON Or %WS_TABSTOP Control Add TextBox, hDlg, %MYTEXT, "Point mouse here", 5, 20, 150, 12, %WS_CHILD Or %WS_VISIBLE Or %ES_AUTOHSCROLL Or %WS_TABSTOP, %WS_EX_CLIENTEDGE Dialog Show Modal hDlg, Call DLGPROC End Function '==================================================
------------------ "I haven't lost my mind... its backed up on tape... I think??" IP: Logged |
Fred Buffington Member
|
posted December 02, 2003 06:34 PM
Will, after the line
hWnd_ToolTip = CreateWindowEx( 0, "tooltips_class32", "", %TTS_ALWAYSTIP Or %TTS_BALLOON, 0, 0, _ 0, 0, 0, ByVal 0&, GetModuleHandle
I added.
DIALOG SEND hWnd_ToolTip, %TTM_SETMAXTIPWIDTH, 0, 200 DIALOG SEND hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOPOP, 5000 'Set Tooltip time
in order to keep a long text without $CRLF from making one long line
------------------
IP: Logged |
Bob Scott Member
|
posted November 28, 2004 01:11 PM
The ToolTips2.inc file source code has been moved to eliminate confusion. http://www.powerbasic.com/support/forums/Forum7/HTML/002878.html ~Bob [This message has been edited by Bob Scott (edited February 15, 2006).] IP: Logged |
Bernhard Fomm Member
|
posted July 22, 2005 02:28 AM
How can tips be called by SendMessage?If yes, how?
IP: Logged |