hier ist mal eine Prozedur, mit der man schnell und einfach einen Tooltip anzeigen lassen kann.
Es ist bestimmt noch optimierbar, aber es erfüllt seinen Zweck. Eventuell hilft es jemandem.
PB v5.21
Code: Alles auswählen
Procedure Tooltip (sText.s , sTitel.s = "", sSymbol.s = "kein", iX_Pos.i = #PB_Default, iY_Pos.i = #PB_Default, iMax_Breite.i = #PB_Default, bBallon.i = #False, bSchliessen.i = #False)
#TTF_ABSOLUTE = $0080
#TTF_TRACK = $0020
#TTS_CLOSE = $80
#TTS_NOFADE = $20
Static iTooltip_ID.i = 0
Static iStyle_aktuell = 0
Protected iSymbol.i = 0
Protected iStyle.i = #WS_POPUP | #TTS_NOPREFIX | #TTS_ALWAYSTIP | #TTS_NOFADE
Protected iExStyle.i = #WS_EX_TOPMOST
Protected iInstanz.i = GetModuleHandle_(0)
Protected lPosition.l = 0
Protected iWindowID.i = 0 ;experimentell
Protected Parameter.TOOLINFO
; Tooltip löschen, wenn kein Text angegeben wurde
If sText = "" And iTooltip_ID <> 0
DestroyWindow_(iTooltip_ID)
iTooltip_ID = 0
ProcedureReturn 1
ElseIf sText = "" And iTooltip_ID = 0
ProcedureReturn -1
EndIf
; darzustellendes Symbol
If sSymbol = "kein"
iSymbol = #TOOLTIP_NO_ICON
ElseIf sSymbol = "Info"
iSymbol = #TOOLTIP_INFO_ICON
ElseIf sSymbol = "Warnung"
iSymbol = #TOOLTIP_WARNING_ICON
ElseIf sSymbol = "Fehler"
iSymbol = #TOOLTIP_ERROR_ICON
Else
iSymbol = #TOOLTIP_NO_ICON
EndIf
; X-Position bestimmen (Standard: aktuelle Mausposition)
If (iX_Pos = #PB_Default) And (bBallon = #True)
iX_Pos = DesktopMouseX()
ElseIf (iX_Pos = #PB_Default) And (bBallon = #False)
iX_Pos = DesktopMouseX() +16
EndIf
; Y-Position bestimmen (Standard: aktuelle Mausposition)
If iY_Pos = #PB_Default
iY_Pos = DesktopMouseY()
EndIf
; maximale Breite festlegen
If (iMax_Breite = #PB_Default) Or (iMax_Breite < 10)
iMax_Breite = 400
EndIf
; ggf. Ballonform aktivieren
If bBallon = #True
iStyle | #TTS_BALLOON
EndIf
; ggf. den Schließen-Button anzeigen (Ballonform muss aktiviert sein)
If bSchliessen = #True
iStyle | #TTS_CLOSE
EndIf
; prüfen, ob schon ein Tooltip existiert
If iTooltip_ID = 0
iTooltip_ID = CreateWindowEx_(iExStyle, #TOOLTIPS_CLASS, #Null, iStyle, 0, 0, 0, 0, iWindowID, 0, iInstanz, 0)
Else
If iStyle_aktuell <> iStyle
DestroyWindow_(iTooltip_ID)
iTooltip_ID = CreateWindowEx_(iExStyle, #TOOLTIPS_CLASS, #Null, iStyle, 0, 0, 0, 0, iWindowID, 0, iInstanz, 0)
EndIf
EndIf
; iStyle speichern
iStyle_aktuell = iStyle
; Eigenschaften übernehmen und anzeigen
Parameter.TOOLINFO\cbSize = SizeOf(TOOLINFO)
Parameter\uFlags = #TTF_IDISHWND | #TTF_ABSOLUTE | #TTF_TRACK
Parameter\hWnd = iWindowID
Parameter\uId = iWindowID
Parameter\lpszText = @sText
Parameter\hInst = iInstanz
lPosition = (iX_Pos & $FFFF) | ((iY_Pos & $FFFF) << 16)
SendMessage_(iTooltip_ID, #TTM_SETTIPTEXTCOLOR, GetSysColor_(#COLOR_INFOTEXT), 0)
SendMessage_(iTooltip_ID, #TTM_SETTIPBKCOLOR, GetSysColor_(#COLOR_INFOBK), 0)
SendMessage_(iTooltip_ID, #TTM_SETMAXTIPWIDTH, 0, iMax_Breite)
SendMessage_(iTooltip_ID, #TTM_TRACKPOSITION, 0, lPosition)
SendMessage_(iTooltip_ID, #TTM_SETTITLE, iSymbol, @sTitel)
GetWindowRect_ (iWindowID, @Parameter\rect)
SendMessage_ (iTooltip_ID, #TTM_ADDTOOL, 0, @Parameter)
SendMessage_ (iTooltip_ID, #TTM_TRACKACTIVATE, 1, @Parameter)
SendMessage_ (iTooltip_ID, #TTM_UPDATETIPTEXT, 0, @Parameter)
ProcedureReturn 0
EndProcedure
OpenWindow (0, 0, 0, 100, 100, "Tooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 100, 80, "Klick mich")
Repeat
MausPos$ = "aktuelle Mausposition: " + Str(DesktopMouseX()) + "x" + Str(DesktopMouseY())
Tooltip(MausPos$)
Select WaitWindowEvent(10)
Case #PB_Event_Gadget
If EventGadget() = 1
Tooltip("Ich bin ein Text")
Delay (1000)
Tooltip("Ich bin ein Text", "ein Titel")
Delay (1000)
Tooltip("Ich bin ein Text", "ein Titel", "Fehler")
Delay (1000)
Tooltip("Ich bin ein Text", "ein Titel", "Warnung")
Delay (1000)
Tooltip("Ich bin ein Text", "ein Titel", "Info")
Delay (1000)
For i=1 To 10
Tooltip("Ich bin ein Text", "ein Titel", "Info", Random(500), Random(500))
Delay (500)
Next
For i=1 To 10
Tooltip("Ich bin ein Text", "ein Titel", "Warnung", Random(500), Random(500), -1, 1, 1)
Delay (500)
Next
Tooltip("")
Delay (2000)
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
*ist jetzt korrigiert*
Danke STARGÅTE
viele Grüße,
SBond