Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile in PBWin10. To compile in PBWin9, split pt into
'pt.x,pt..x whereve the PtInRect() API is used (4 places). Also, add this line:
#Include "commctrl.inc"
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_Graphic = 500
Global hDlg,hToolTip,hGraphic As Dword, RUL,RUR,RLL,RLR As Rect
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,200,200,%SS_Notify or %WS_Border
Control Handle hDlg, %IDC_Graphic To hGraphic
hToolTip = CreateWindowEx(ByVal 0, "tooltips_class32", "", %TTS_ALWAYSTIP, _
0, 0, 0, 0, ByVal hDlg, ByVal 0, GetModuleHandle(ByVal %NULL), ByVal 0)
SetTooltip(GetDlgItem(hDlg, %IDC_Graphic), "UL . LL . UR . LR")
Graphic Attach hDlg, %IDC_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local pt As Point
Select Case Cb.Msg
Case %WM_InitDialog
RUL.nLeft = 0 : RUL.nTop = 0 : RUL.nRight = 100 : RUL.nBottom = 100
RUR.nLeft = 100 : RUR.nTop = 0 : RUR.nRight = 200 : RUR.nBottom = 100
RLL.nLeft = 0 : RLL.nTop = 100 : RLL.nRight = 100 : RLL.nBottom = 200
RLR.nLeft = 100 : RLR.nTop = 100 : RLR.nRight = 200 : RLR.nBottom = 200
Case %WM_SetCursor
GetCursorPos pt 'pt has xy screen coordinates
ScreenToClient hDlg, pt 'pt now has dialog client coordinates
If PtInRect(RUL,pt) Then SetTooltip(GetDlgItem(hDlg, %IDC_Graphic), "RUL")
If PtInRect(RUR,pt) Then SetTooltip(GetDlgItem(hDlg, %IDC_Graphic), "RUR")
If PtInRect(RLL,pt) Then SetTooltip(GetDlgItem(hDlg, %IDC_Graphic), "RLL")
If PtInRect(RLR,pt) Then SetTooltip(GetDlgItem(hDlg, %IDC_Graphic), "RLR")
Dialog Set Text hDlg, "SetCursor: " + Str$(pt.x) + ":" + Str$(pt.y)
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)
' SendMessage hToolTip, %TTM_SetDelayTime, %TTDT_Initial, Mak(Dword, 250,250)
SendMessage hToolTip, %TTM_SetDelayTime, %TTDT_Reshow, Mak(Dword, 250,250)
SendMessage hToolTip, %TTM_SetDelayTime, %TTDT_AutoPop, Mak(Dword, 250,250)
End Sub
'gbs_00824
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm