Why ToolTip's Title shows duplicate ?

Just starting out? Need help? Post your questions and find answers here.
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

Why ToolTip's Title shows duplicate ?

Post by hoangdiemtinh »

I am new to PB.
My primary language is not US/UK. I am using Google Translate.

Why ToolTip's Title shows duplicate ?
Is there any solution to fix this problem ?

Code: Select all

EnableExplicit

DeclareModule TOOLS
  ;- ==========================================================================
  ;- DeclareModule "TOOLS"
  ;- ==========================================================================
  Global hToolTip.l
  Global ti_ToolTip.TOOLINFO
  Declare CreateTip(window_ID.i)
  Declare.i ReleaseTip(GadGet_ID.i)
  Declare AddTip(GadGet_ID.i, Title.s, subTitle.s, hIcon.i)
EndDeclareModule

Module TOOLS
  Procedure CreateTip(window_ID.i)
    ; https://www.purebasic.fr/english/viewtopic.php?t=44867
    ; https://www.purebasic.fr/english/viewtopic.php?t=67420
    ; https://www.purebasic.fr/english/viewtopic.php?t=82818&start=15
    Protected.w null
    Protected rrr.RECT
    #TTS_BUBBLE = $40
    hToolTip = CreateWindowEx_(#WS_EX_TOPMOST, #TOOLTIPS_CLASS, #Null,
      #TTS_ALWAYSTIP|#TTS_NOPREFIX|#WS_POPUP|#TTS_BALLOON|#TTS_BUBBLE,
      #CW_USEDEFAULT,#CW_USEDEFAULT, #CW_USEDEFAULT,
      #CW_USEDEFAULT,WindowID(window_ID), #Null, #Null, #Null)
    SetWindowTheme_(hToolTip, @null, @null)
    SendMessage_(hToolTip,#TTM_SETDELAYTIME,#TTDT_INITIAL,0)
    SendMessage_(hToolTip,#TTM_SETTIPBKCOLOR,#White,0)                    ;BackColor Tooltip
    SendMessage_(hToolTip,#TTM_SETTIPTEXTCOLOR,#Blue,0)                   ;TextColor Tooltip
    SendMessage_(hToolTip,#TTM_SETMAXTIPWIDTH,0,360)                      ;Max Tooltip width
    SetRect_(rrr,5,0,5,0)                                                 ;Tooltip Margins - left/top/right/bottom
    SendMessage_(hToolTip,#TTM_SETMARGIN,0,rrr)
    SendMessage_(hToolTip,#TTM_ACTIVATE,#False,0)                          ;DeActivate
    SendMessage_(hToolTip,#TTM_ACTIVATE,#True,0)                           ;Activate
    LoadFont(999, "Arial",12,#PB_Font_HighQuality)
    SendMessage_(hToolTip,#WM_SETFONT,FontID(999),0)
  EndProcedure
  
  Procedure.i ReleaseTip(GadGet_ID.i)
    Protected hwnd.i
    Protected ti_ToolTip.TOOLINFO
    If IsGadget(GadGet_ID)
      ti_ToolTip\cbSize = SizeOf(TOOLINFO)
      ti_ToolTip\hWnd = GadgetID(GadGet_ID)
      hwnd = FindWindow_(#TOOLTIPS_CLASS,Str(ti_ToolTip\hWnd))
      If hwnd
        SendMessage_(hToolTip,#TTM_DELTOOL,#Null,@ti_ToolTip)
        SendMessage_(hToolTip,#WM_CLOSE,#Null,#Null)
      EndIf
    EndIf
    ProcedureReturn #Null
  EndProcedure
  
  Procedure AddTip(GadGet_ID.i, Title.s, subTitle.s, hIcon.i)
    SendMessage_(hToolTip,#TTM_SETTITLE,hIcon,@Title)
    ti_ToolTip\lpszText = @subTitle
    ti_ToolTip\cbSize = SizeOf(TOOLINFO)
    ti_ToolTip\uFlags = #TTF_SUBCLASS|#TTF_IDISHWND
    ti_ToolTip\hwnd = GadgetID(GadGet_ID)
    ti_ToolTip\uId = GadgetID(GadGet_ID)
    SendMessage_(hToolTip,#TTM_ADDTOOL,0,@ti_ToolTip);
  EndProcedure
EndModule

DeclareModule MAIN_WIN
  ;- ==========================================================================
  ;- DeclareModule "MAIN_WIN"
  ;- ==========================================================================
  Declare create_main_win()
  Declare main_win_loop()
EndDeclareModule

Module MAIN_WIN
  UseModule TOOLS
  Procedure create_main_win()
    OpenWindow(999,0,0,300,200, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
    ButtonGadget(11,50,50,80,25,"Button 1")
    ButtonGadget(12,150,50,80,25,"Button 2")
  EndProcedure
  Procedure main_win_loop()
    create_main_win()
    CreateTip(999)
    ReleaseTip(11)
    AddTip(11,"my Title 1","* my subtitle 1 - blabla1 bla1111." + #CR$ + "* maaaaa1 maaa1.", #TOOLTIP_INFO_ICON)
    AddTip(12,"my Title 2","* my subtitle 2 - blabla2 bla2222." + #CR$ + "* maaaaa2 maaa2.", #TOOLTIP_INFO_ICON)
    Repeat
      EventID.l = WaitWindowEvent()
      If EventID = #PB_Event_CloseWindow
        Quit = 1
      EndIf
    Until Quit = 1
    End
  EndProcedure
EndModule

UseModule MAIN_WIN
main_win_loop()
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Why ToolTip's Title shows duplicate ?

Post by spikey »

See About Tooltip Controls

There's an instance of the 'subtitle' for each registered control via TTM_ADDTOOL, but there's only one instance of the window title for the tip window itself, via TTM_SETTITLE. Each time you call AddTip you replace the title text overall. So you're seeing the title from the last call to AddTip made.

You could:
1) Use a generic title for the toolip such as "Information", you'll see that all the examples on learn.microsoft.com do something like this.
2) Create more than one tooltip window, each having a generic title for the subject item they tip. For example one for controls labelled "Control information", one for menu items or toolbar buttons labelled "Menu information"...
3) Create a separate tooltip window for each gadget you want to have a tip, this way they can all have their own title instance.
4) Intercept the TTN_SHOW or TTN_GETDISPINFO notifications in a window callback procedure, work out which tooltip subtitle message is about to be displayed and update the title each time the tip window is displayed.
Post Reply