Tooltip () -> schnell und einfach ein Tooltip anzeigen

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
SBond
Beiträge: 266
Registriert: 22.05.2013 20:35
Computerausstattung: armseliger Laptop, mit wenig RAM und noch weniger CPU-Leistung. ...und die Grafikkarte.... ....naja.. da male ich doch lieber selber.
Wohnort: nahe Wolfsburg

Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von SBond »

Hi Leute,

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 :D

viele Grüße,
SBond
Zuletzt geändert von SBond am 24.02.2014 22:45, insgesamt 1-mal geändert.
41 6c 73 6f 20 77 65 6e 6e 20 64 75 20 73 6f 20 76 69 65 6c 20 4c 61 6e 67 65 77 65 69 6c 65 20 68 61 73 74 2c 20 64 61 6e 6e 20 6b 61 6e 6e 73 74 20 64 75 20 61 75 63 68 20 67 6c 65 69 63 68 20 7a 75 20 6d 69 72 20 6b 6f 6d 6d 65 6e 20 75 6e 64 20 61 62 77 61 73 63 68 65 6e 2e

:D
SBond
Beiträge: 266
Registriert: 22.05.2013 20:35
Computerausstattung: armseliger Laptop, mit wenig RAM und noch weniger CPU-Leistung. ...und die Grafikkarte.... ....naja.. da male ich doch lieber selber.
Wohnort: nahe Wolfsburg

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von SBond »

ein kleines Problem hat diese Funktion noch...

das Tooltip wird falsch positioniert, wenn der Anwender mit 2 Monitoren arbeitet und sich der Hauptbildschirm rechts befindet.
Der Grund dafür liegt an der horitontalen Mauskoordinate, die im linken Bildschirm negativ wird (so wie bei mir).

Normalerweise wird die Position folgendermaßen angegeben:

X_Pos: 2Byte (word)
Y_Pos: 2Byte (word)
Position: 4Byte (long)

Position = iX_Pos | (iY_Pos << 16)

SendMessage_(iTooltip_ID, #TTM_TRACKPOSITION, 0, Position)


...eventuell kann es jemand korrigieren, aber ich habe keine Ahnung wie :(
41 6c 73 6f 20 77 65 6e 6e 20 64 75 20 73 6f 20 76 69 65 6c 20 4c 61 6e 67 65 77 65 69 6c 65 20 68 61 73 74 2c 20 64 61 6e 6e 20 6b 61 6e 6e 73 74 20 64 75 20 61 75 63 68 20 67 6c 65 69 63 68 20 7a 75 20 6d 69 72 20 6b 6f 6d 6d 65 6e 20 75 6e 64 20 61 62 77 61 73 63 68 65 6e 2e

:D
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 6999
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von STARGÅTE »

Probier mal:
Position = (iX_Pos & $FFFF) | ((iY_Pos & $FFFF) << 16)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
SBond
Beiträge: 266
Registriert: 22.05.2013 20:35
Computerausstattung: armseliger Laptop, mit wenig RAM und noch weniger CPU-Leistung. ...und die Grafikkarte.... ....naja.. da male ich doch lieber selber.
Wohnort: nahe Wolfsburg

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von SBond »

du bist ein Gott :praise:

Schande über mich.
41 6c 73 6f 20 77 65 6e 6e 20 64 75 20 73 6f 20 76 69 65 6c 20 4c 61 6e 67 65 77 65 69 6c 65 20 68 61 73 74 2c 20 64 61 6e 6e 20 6b 61 6e 6e 73 74 20 64 75 20 61 75 63 68 20 67 6c 65 69 63 68 20 7a 75 20 6d 69 72 20 6b 6f 6d 6d 65 6e 20 75 6e 64 20 61 62 77 61 73 63 68 65 6e 2e

:D
Marty2PB
Beiträge: 16
Registriert: 14.03.2014 00:00

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von Marty2PB »

Das ist super aber da ich soviele Tooltips auf den gadgets (50+) habe nutze ich ne Structure um den inhalt aktuell zu ändern. Alternativen. kleineren Code ging nicht .
Bin nocht nicht so bewandert mit PB.

Code: Alles auswählen



;################################################################################################################ 
;                                                                                                 Windows ToolTip
     Structure WINDOWS_TOOLTIP
        iPBGD_num.l                 ;PB Gagget ID
        iCLSS_num.l                 ;ToolTips_Class32
     EndStructure
     Global NewList LHTTI.WINDOWS_TOOLTIP()   
     
;################################################################################################################ 
;                                                                                                     Tooltip Set
    Procedure Set_ToolTip_EX(WindowID, Gadget, Text$ , Title$, Icon)
  
        iToolTipEx = CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP|#TTS_NOPREFIX|#TTS_BALLOON,0,0,0,0,WindowID,0,GetModuleHandle_(0),0)
   
    
        SendMessage_(iToolTipEx,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
        SendMessage_(iToolTipEx,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
        SendMessage_(iToolTipEx,#TTM_SETMAXTIPWIDTH,0,200)
    
        Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
    
        Balloon\uFlags  = #TTF_IDISHWND | #TTF_SUBCLASS
        Balloon\hWnd    = GadgetID(Gadget)
        Balloon\uId     = GadgetID(Gadget)
        Balloon\lpszText= @Text$
  
        SendMessage_(iToolTipEx, #TTM_ADDTOOL, 0, Balloon)
        If Title$ > ""
            SendMessage_(iToolTipEx, #TTM_SETTITLE,Icon,@Title$)
        EndIf
    
        AddElement(LHTTI())
            LHTTI()\iCLSS_num = iToolTipEx
            LHTTI()\iPBGD_num = Gadget    
    EndProcedure
    
;################################################################################################################ 
;                                                                                                  Tooltip Change
    Procedure Chg_ToolTip_EX(iGadget,Text$, Title$, Icon,iToolTipWidth = 200)
   
    ResetList(LHTTI())
    While NextElement(LHTTI())
        If (iGadget = LHTTI()\iPBGD_num)
            
            Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
            
            Balloon\hWnd    = GadgetID(iGadget)
            Balloon\uId     = GadgetID(iGadget)
            Balloon\lpszText= @Text$
            SendMessage_(LHTTI()\iCLSS_num, #TTM_UPDATETIPTEXT, 0, @Balloon)
            SendMessage_(LHTTI()\iCLSS_num, #TTM_SETMAXTIPWIDTH,0, iToolTipWidth)
            If Title$ > ""
                SendMessage_(LHTTI()\iCLSS_num, #TTM_SETTITLE,Icon,@Title$)
            EndIf
            ProcedureReturn
        EndIf
    Wend
EndProcedure


Window erstellen und so etc.......

Set_ToolTip_EX(WindowID(#UIWINDOW1),Gadget(iGadget), "Moin",":..",1)
Chg_ToolTip_EX(#String_01,"Viele grüsse an das PB Board","Purebasic ist Super",1,500)

Andreas21
Beiträge: 390
Registriert: 30.08.2004 09:05
Computerausstattung: Desktop
Windows 10 Pro x64
CPU: AMD Ryzen 5 2600 3.40 GHz
Ram: 16GB RAM
Grafik: NVIDA Geforce 1060
PB: 5.72 X86/X64
Wohnort: Heidelberg

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von Andreas21 »

z.b.:

Mit Maps muss man nicht beim ändern die ganze liste durch suchen.

Code: Alles auswählen

;################################################################################################################ 
;                                                                                                         Declare
Declare Set_ToolTip_EX(WindowID, Gadget, Text$, Title$, Icon, iToolTipWidth = 200)
Declare Chg_ToolTip_EX(         iGadget, Text$, Title$, Icon, iToolTipWidth = 200)

;################################################################################################################ 
;                                                                                                 Windows ToolTip 
Global NewMap LHTTI.l() ;ToolTips_Class32

;################################################################################################################ 
;                                                                                                     Tooltip Set
Procedure Set_ToolTip_EX(WindowID, Gadget, Text$, Title$, Icon, iToolTipWidth = 200)
  Protected iToolTipEx, Balloon.TOOLINFO
  
  If FindMapElement(LHTTI(), Str(Gadget))
    Chg_ToolTip_EX(Gadget, Text$, Title$, Icon, iToolTipWidth)
    ProcedureReturn
  EndIf
  
  iToolTipEx = CreateWindowEx_(0, "ToolTips_Class32", "", #WS_POPUP|#TTS_NOPREFIX|#TTS_BALLOON, 0, 0, 0, 0, WindowID, 0, GetModuleHandle_(0), 0)
  
  SendMessage_(iToolTipEx, #TTM_SETTIPTEXTCOLOR, GetSysColor_(#COLOR_INFOTEXT), 0)
  SendMessage_(iToolTipEx, #TTM_SETTIPBKCOLOR,   GetSysColor_(#COLOR_INFOBK),   0)
  SendMessage_(iToolTipEx, #TTM_SETMAXTIPWIDTH,  0,                           200)
  
  Balloon\cbSize   = SizeOf(TOOLINFO)
  Balloon\uFlags   = #TTF_IDISHWND | #TTF_SUBCLASS
  Balloon\hWnd     = GadgetID(Gadget)
  Balloon\uId      = GadgetID(Gadget)
  Balloon\lpszText = @Text$
  
  SendMessage_(  iToolTipEx, #TTM_ADDTOOL,     0, Balloon)
  If Title$ > ""
    SendMessage_(iToolTipEx, #TTM_SETTITLE, Icon, @Title$)
  EndIf
  
  LHTTI(Str(Gadget)) = iToolTipEx 
EndProcedure

;################################################################################################################ 
;                                                                                                  Tooltip Change
Procedure Chg_ToolTip_EX(iGadget, Text$, Title$, Icon, iToolTipWidth = 200)
  Protected Balloon.TOOLINFO, iCLSS_num.l
  
  If FindMapElement(LHTTI(), Str(iGadget))
    iCLSS_num = LHTTI(Str(iGadget))
    If iCLSS_num
      Balloon\cbSize   = SizeOf(TOOLINFO)
      Balloon\hWnd     = GadgetID(iGadget)
      Balloon\uId      = GadgetID(iGadget)
      Balloon\lpszText = @Text$
      SendMessage_(iCLSS_num, #TTM_UPDATETIPTEXT,  0, @Balloon)
      SendMessage_(iCLSS_num, #TTM_SETMAXTIPWIDTH, 0, iToolTipWidth)
      If Title$ > ""
        SendMessage_(iCLSS_num, #TTM_SETTITLE, Icon, @Title$)
      EndIf
    EndIf
  EndIf
EndProcedure


Window erstellen und so etc.......

Set_ToolTip_EX(WindowID(#UIWINDOW1), Gadget(iGadget), "Moin",":..", 1)
Chg_ToolTip_EX(#String_01, "Viele grüsse an das PB Board","Purebasic ist Super", 1, 500)
Windows 10 x64 Pro - PB 5.61 X64 / x32 - PB 4.6 x32
SBond
Beiträge: 266
Registriert: 22.05.2013 20:35
Computerausstattung: armseliger Laptop, mit wenig RAM und noch weniger CPU-Leistung. ...und die Grafikkarte.... ....naja.. da male ich doch lieber selber.
Wohnort: nahe Wolfsburg

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von SBond »

hier ist eine aktuellere Version der Prozedur. Diese vermindert das flackern bei häufigen Aktualisierungen:

Code: Alles auswählen

;{ #PRIVATE# ;===========================================================================
;
; Name...........:  Tooltip
;
; Beschreibung ..:  erzeugt ein Tooltip oder ein Ballon-Tipp
;
; Syntax.........:  Tooltip (sText.s , sTitel.s = "", sSymbol.s = "kein", iX_Pos.i = #PB_Default, iY_Pos.i = #PB_Default, iMax_Breite.i = #PB_Default, iBallon.i = #False, iSchliessen.i = #False)
;
; Parameter .....:   sText.s            - der anzuzeigende Text (oder "", um das Tooltip zu löschen)
;                    sTitel.s           - der anzuzeigende Titel (optional)
;                    sSymbol.s          - das Symbol, das angezeigt werden soll
;                                       | "kein":    zeigt kein Symbol an
;                                       | "Info":    zeigt ein Infosymbol
;                                       | "Warnung": zeigt ein Warnsymbol    
;                                       | "Fehler":  zeigt ein Fehlersymbol
;
;                    iX_Pos.i           - die X-Koordinate des Tooltips (absolute Koordinate; bezogen auf dem Desktop)
;                                       | #PB_Default: positioniert das Tooltip neben dem Mauszeiger
;
;                    iY_Pos.i           - die Y-Koordinate des Tooltips (absolute Koordinate; bezogen auf dem Desktop)
;                                       | #PB_Default: positioniert das Tooltip neben dem Mauszeiger
;
;                    iMax_Breite.i      - die Breite, die das Tooltip maximal haben darf
;                                       | #PB_Default: Standardbreite = 400 Pixel
;
;                    iBallon.i          - Bool: zeigt bei #True einen Ballon-Tipp anstatt eines Tooltips an
;                    iSchliessen.i      - Bool: zeigt bei #True einen Schließen-Button an (nur, wenn iBallon = #True)
;                                                
; Rückgabewerte .:   Erfolg              |  0: Prozedur erfolgreich ausgeführt
;                                        |  1: das aktuelle Tooltip wurde gelöscht
;
;                    Fehler              | -1: es existiert kein Tooltip
;                                                
;
; Bemerkungen ...:   diese Prozedur lädt und speichert die Tooltip-IDs automatisch. Erhält eine Tooltip-ID einen leeren String als Text, so wird das Tooltip gelöscht.
;                    Ansonsten bleibt es bis zum Programmende bestehen.
;
;} ======================================================================================
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.i    = 0
    Static        iX_Pos_aktuell.i    = 0
    Static        iY_Pos_aktuell.i    = 0    
    Static        sText_aktuell.s     = ""
    Static        sTitel_aktuell.s    = ""
    Static        sSymbol_aktuell.s   = ""

    Protected     iUpdate_Inhalt.i    = #False
    Protected     iUpdate_Position.i  = #False
    
    Protected    iSymbol.i            = 0
    Protected    iStyle.i             = #WS_POPUP | #TTS_NOPREFIX | #TTS_ALWAYSTIP | #TTS_NOFADE
    Protected    iExStyle.i           = #WS_EX_TOPMOST
    Protected     iWindowID.i         = 0    ; experimentell: WindowID angeben, falls es Probleme mit der Darstellung gibt
    Protected    iInstanz.i           = GetModuleHandle_(0)
    Protected    lPosition.l          = 0
    
    Protected    Parameter.TOOLINFO
    
    
    ; Tooltip löschen, wenn kein Text angegeben wurde
    If sText = "" And iTooltip_ID <> 0
        DestroyWindow_(iTooltip_ID)
        iTooltip_ID        = 0
        iStyle_aktuell     = 0
        iX_Pos_aktuell     = 0
        iY_Pos_aktuell     = 0
        sText_aktuell      = ""
        sTitel_aktuell     = ""
        sSymbol_aktuell    = ""
        ProcedureReturn 1
        
    ElseIf sText = "" And iTooltip_ID = 0
        iTooltip_ID        = 0
        iStyle_aktuell     = 0
        iX_Pos_aktuell     = 0
        iY_Pos_aktuell     = 0
        sText_aktuell      = ""
        sTitel_aktuell     = ""
        sSymbol_aktuell    = ""
        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

    
    ; 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)
    
    
    ; prüfen, ob die Position oder der Inhalt geändert wurde
    If (sText <> sText_aktuell) Or (sTitel <> sTitel_aktuell) Or (sSymbol <> sSymbol_aktuell) Or (sText_aktuell = "")
        iUpdate_Inhalt          = #True
        iUpdate_Position        = #True
    Else
        iUpdate_Inhalt          = #False
        
        If (iX_Pos <> iX_Pos_aktuell) Or (iY_Pos <> iY_Pos_aktuell)
            iUpdate_Position    = #True
        Else
            iUpdate_Position    = #False
        EndIf
        
    EndIf
    
    
    ; aktuelle Daten speichern
    iStyle_aktuell    = iStyle
    sText_aktuell     = sText
    sTitel_aktuell    = sTitel
    sSymbol_aktuell   = sSymbol
    iX_Pos_aktuell    = iX_Pos
    iY_Pos_aktuell    = iY_Pos
    
    
    ; Tooltip-Inhalt übernehmen und darstellen
    If iUpdate_Inhalt = #True

        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_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)        
        
    EndIf
    
    
    If iUpdate_Position = #True
        SendMessage_    (iTooltip_ID,    #TTM_TRACKPOSITION,     0, lPosition)
    EndIf

    ProcedureReturn 0
    
EndProcedure

OpenWindow   (0, 0, 0, 100, 100, "Tooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Repeat
    
    Text$ = "aktuelle Mausposition:" + #TAB$ + Str(DesktopMouseX()) + "x" + Str(DesktopMouseY()) + #CRLF$
    Text$ + "CPU-Name:" + #TAB$ + #TAB$ + CPUName() + #CRLF$
    Text$ + "Computer-Name:" + #TAB$ + #TAB$ + ComputerName() + #CRLF$
    Text$ + "RAM verfügbar:" + #TAB$ + #TAB$ + StrF(MemoryStatus(#PB_System_FreePhysical)/1048576,3) + " MB" + #CRLF$
    Tooltip(Text$, "aktuelle Daten", "Info", -1, -1 ,600)

Until WaitWindowEvent(20) =  #PB_Event_CloseWindow
Noch so eine Frage nebenbei...
Kann man die Größe des Tooltipps auslesen? Ich möchte gerne verhindern, dass das Tooltip den Desktop verlässt. Statt dessen soll das Tooltip woanders hin plaziert werden.

Laut MSDN, geht es wohl über TTM_GETBUBBLESIZE. Dieser gibt ein word zurück, in dem die Breite und die Höhe ausgelesen werden kann.
Parameters
-------------------
wParam: Must be zero.
lParam: Pointer to the tooltip TOOLINFO structure.


Return value
------------------
Returns the width of the tooltip in the low word and the height in the high word if successful. Otherwise, it returns FALSE.


Remarks
------------------
If the TTF_TRACK and TTF_ABSOLUTE flags are set in the uFlags member of the tooltip TOOLINFO structure, this message can be used to help position the tooltip accurately.
bezogen auf meine Prozedur wäre es also so:

Code: Alles auswählen

Protected wTooltipSize.w
Protected iWidth.i
Protected iHeight.i

wTooltipSize = SendMessage_ (iTooltip_ID, #TTM_GETBUBBLESIZE, 0, @Parameter)	
iWidth = wTooltipSize & $00FF
iHeight = wTooltipSize & $FF00
...allerdings bekomme ich entweder 256 oder 0 bei iWidth und 0 bei iHeight. Mache ich was falsch?


viele Grüße,
SBond
41 6c 73 6f 20 77 65 6e 6e 20 64 75 20 73 6f 20 76 69 65 6c 20 4c 61 6e 67 65 77 65 69 6c 65 20 68 61 73 74 2c 20 64 61 6e 6e 20 6b 61 6e 6e 73 74 20 64 75 20 61 75 63 68 20 67 6c 65 69 63 68 20 7a 75 20 6d 69 72 20 6b 6f 6d 6d 65 6e 20 75 6e 64 20 61 62 77 61 73 63 68 65 6e 2e

:D
Benutzeravatar
Kiffi
Beiträge: 10621
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von Kiffi »

SBond hat geschrieben:...allerdings bekomme ich entweder 256 oder 0 bei iWidth und 0 bei iHeight. Mache ich was falsch?
mh, ich bekomme 256 * 142 Pixel.

Wo rufst Du denn die Maße ab?

Grüße ... Kiffi
Hygge
SBond
Beiträge: 266
Registriert: 22.05.2013 20:35
Computerausstattung: armseliger Laptop, mit wenig RAM und noch weniger CPU-Leistung. ...und die Grafikkarte.... ....naja.. da male ich doch lieber selber.
Wohnort: nahe Wolfsburg

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von SBond »

hier:

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.i    = 0
    Static        iX_Pos_aktuell.i    = 0
    Static        iY_Pos_aktuell.i    = 0   
    Static        sText_aktuell.s     = ""
    Static        sTitel_aktuell.s    = ""
    Static        sSymbol_aktuell.s   = ""

    Protected     iUpdate_Inhalt.i    = #False
    Protected     iUpdate_Position.i  = #False
   
    Protected    iSymbol.i            = 0
    Protected    iStyle.i             = #WS_POPUP | #TTS_NOPREFIX | #TTS_ALWAYSTIP | #TTS_NOFADE
    Protected    iExStyle.i           = 0; #WS_EX_TOPMOST
    Protected     iWindowID.i         = 0    ; experimentell: WindowID angeben, falls es Probleme mit der Darstellung gibt
    Protected    iInstanz.i           = GetModuleHandle_(0)
    Protected    lPosition.l          = 0
   
    Protected    Parameter.TOOLINFO
   
   
    ; Tooltip löschen, wenn kein Text angegeben wurde
    If sText = "" And iTooltip_ID <> 0
        DestroyWindow_(iTooltip_ID)
        iTooltip_ID        = 0
        iStyle_aktuell     = 0
        iX_Pos_aktuell     = 0
        iY_Pos_aktuell     = 0
        sText_aktuell      = ""
        sTitel_aktuell     = ""
        sSymbol_aktuell    = ""
        ProcedureReturn 1
       
    ElseIf sText = "" And iTooltip_ID = 0
        iTooltip_ID        = 0
        iStyle_aktuell     = 0
        iX_Pos_aktuell     = 0
        iY_Pos_aktuell     = 0
        sText_aktuell      = ""
        sTitel_aktuell     = ""
        sSymbol_aktuell    = ""
        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

   
    ; 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)
   
   
    ; prüfen, ob die Position oder der Inhalt geändert wurde
    If (sText <> sText_aktuell) Or (sTitel <> sTitel_aktuell) Or (sSymbol <> sSymbol_aktuell) Or (sText_aktuell = "")
        iUpdate_Inhalt          = #True
        iUpdate_Position        = #True
    Else
        iUpdate_Inhalt          = #False
       
        If (iX_Pos <> iX_Pos_aktuell) Or (iY_Pos <> iY_Pos_aktuell)
            iUpdate_Position    = #True
        Else
            iUpdate_Position    = #False
        EndIf
       
    EndIf
   
   
    ; aktuelle Daten speichern
    iStyle_aktuell    = iStyle
    sText_aktuell     = sText
    sTitel_aktuell    = sTitel
    sSymbol_aktuell   = sSymbol
    iX_Pos_aktuell    = iX_Pos
    iY_Pos_aktuell    = iY_Pos
   
   
    ; Tooltip-Inhalt übernehmen und darstellen
    If iUpdate_Inhalt = #True

        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_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)
        
        ; ############# TEMP ###################
        Protected wTooltipSize.w
		Protected iWidth.i
		Protected iHeight.i
		
		wTooltipSize = SendMessage_ (iTooltip_ID, #TTM_GETBUBBLESIZE, 0, @Parameter)   
		iWidth = wTooltipSize & $00FF
		iHeight = wTooltipSize & $FF00
		
		Debug "Größe: " + Str(iWidth) + " x " + Str(iHeight)
		; ############# TEMP ###################
       
    EndIf
   
   
    If iUpdate_Position = #True
        SendMessage_    (iTooltip_ID,    #TTM_TRACKPOSITION,     0, lPosition)
    EndIf

    ProcedureReturn 0
   
EndProcedure

OpenWindow   (0, 0, 0, 100, 100, "Tooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Repeat
   
    Text$ = "aktuelle Mausposition:" + #TAB$ + Str(DesktopMouseX()) + "x" + Str(DesktopMouseY()) + #CRLF$
    Text$ + "CPU-Name:" + #TAB$ + #TAB$ + CPUName() + #CRLF$
    Text$ + "Computer-Name:" + #TAB$ + #TAB$ + ComputerName() + #CRLF$
    Text$ + "RAM verfügbar:" + #TAB$ + #TAB$ + StrF(MemoryStatus(#PB_System_FreePhysical)/1048576,3) + " MB" + #CRLF$
    Tooltip(Text$, "aktuelle Daten", "Info", -1, -1 ,600)

Until WaitWindowEvent(20) =  #PB_Event_CloseWindow

...jetzt bekomme ich eine Größe von 181x256. Das passt aber nicht. Das dargestellte Tooltip hat bei mir eine Abmaße von 435x79 Pixeln.
Ich verstehe auch nicht genau, ob das so möglich ist, da ein Word nur 2 Byte groß ist. Und bei 1 Byte pro Dimension wäre max. 255x255 darstellbar.

gibt es noch eine andere Möglichkeit?

viele Grüße,
SBond
41 6c 73 6f 20 77 65 6e 6e 20 64 75 20 73 6f 20 76 69 65 6c 20 4c 61 6e 67 65 77 65 69 6c 65 20 68 61 73 74 2c 20 64 61 6e 6e 20 6b 61 6e 6e 73 74 20 64 75 20 61 75 63 68 20 67 6c 65 69 63 68 20 7a 75 20 6d 69 72 20 6b 6f 6d 6d 65 6e 20 75 6e 64 20 61 62 77 61 73 63 68 65 6e 2e

:D
SBond
Beiträge: 266
Registriert: 22.05.2013 20:35
Computerausstattung: armseliger Laptop, mit wenig RAM und noch weniger CPU-Leistung. ...und die Grafikkarte.... ....naja.. da male ich doch lieber selber.
Wohnort: nahe Wolfsburg

Re: Tooltip () -> schnell und einfach ein Tooltip anzeigen

Beitrag von SBond »

jo..... ich habe es

Code: Alles auswählen

GetWindowRect_	(iTooltip_ID, @Parameter\rect)
Debug PeekL(@Parameter\rect\right) - PeekL(@Parameter\rect\left)
Debug PeekL(@Parameter\rect\bottom) - PeekL(@Parameter\rect\top)
damit kann ich die Größe auslesen ;) *gg*
41 6c 73 6f 20 77 65 6e 6e 20 64 75 20 73 6f 20 76 69 65 6c 20 4c 61 6e 67 65 77 65 69 6c 65 20 68 61 73 74 2c 20 64 61 6e 6e 20 6b 61 6e 6e 73 74 20 64 75 20 61 75 63 68 20 67 6c 65 69 63 68 20 7a 75 20 6d 69 72 20 6b 6f 6d 6d 65 6e 20 75 6e 64 20 61 62 77 61 73 63 68 65 6e 2e

:D
Antworten