Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile in PBWin10. To compile in PBWin9, add this line:
#Include "commctrl.inc"
'Primary Code:
'A tooltip control must be created using CreateWindowEx (not CONTROL ADD)
hToolTip = CreateWindowEx(ByVal 0, "tooltips_class32", "", %TTS_ALWAYSTIP, _ '%%%S_Balloon
0, 0, 0, 0, ByVal hDlg, ByVal 0, GetModuleHandle(ByVal %NULL), ByVal 0)
'Then, a message is sent to the tooltip, passing on needed information in a
'TOOLINFO structure.
Sub SetToolTip(hControl As DWord, TipText As Asciiz*256)
Local TI As TOOLINFO
TI.cbSize = Len(TI)
TI.uFlags = %TTF_SUBCLASS Or %TTF_IDISHWND
TI.hWnd = GetParent(hToolTip)
TI.uId = hControl
TI.lpszText = VarPTR(TipText)
SendMessage hToolTip, %TTM_ADDTOOL, 0, VarPTR(ti)
' SendMessage hToolTip, %TTM_DELTOOL, 0, ByVal VarPTR(TI) 'use to remove a tooltip if needed
End Sub
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
'%Unicode=1
#Include "win32api.inc"
%IDC_Button = 500
Global hDlg, hToolTip, hButton As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20
Control Handle hDlg, %IDC_Button To hButton
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
hToolTip = CreateWindowEx(ByVal 0, "tooltips_class32", "", %TTS_ALWAYSTIP, _
0, 0, 0, 0, ByVal hDlg, ByVal 0, GetModuleHandle(ByVal %NULL), ByVal 0)
SetToolTip(hButton, "My Button")
End Select
End Function
Sub SetToolTip(hControl As Dword, TipText As AsciiZ*256)
Local TI As TOOLINFO
TI.cbSize = SizeOf(TI)
TI.uFlags = %TTF_SUBCLASS Or %TTF_IDISHWND
TI.hWnd = GetParent(hToolTip)
TI.uId = hControl
TI.lpszText = VarPtr(TipText)
SendMessage hToolTip, %TTM_ADDTOOL, 0, VarPtr(ti)
End Sub
'gbs_00553
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm