Tooltips and Panes

Just starting out? Need help? Post your questions and find answers here.
GenRabbit
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Dec 31, 2014 5:41 pm

Tooltips and Panes

Post by GenRabbit »

I found some code here which I modified to work with my project.
But I run into a problem with Panelgadgets and Panes/Tab. How can I use tooltip with the independent Tabs/panes [Tab1, Tab2] etc

the Structure PB_Globals seems to have support for it, but I have no idea how to use it with Tooltip as It doesnt seem to have a way to tell exact Pane ID.

Code: Select all

EnableExplicit
#gadgets  = 1
#Panes    = 2
Structure PB_Globals
  CurrentWindow.i
  FirstOptionGadget.i
  DefaultFont.i
  *PanelStack
  PanelStackIndex.l
  PanelStackSize.l
  ToolTipWindow.i
EndStructure

Import ""
  PB_Object_GetThreadMemory(*Mem)
  PB_Gadget_Globals
EndImport

Procedure ToolTipHandle(Flag.w)
  Protected *PB_G.PB_Globals
  *PB_G = PB_Object_GetThreadMemory(PB_Gadget_Globals)
  Select Flag
    Case #Gadgets
        ProcedureReturn *PB_G\ToolTipWindow
    Case #Panes
        ProcedureReturn *PB_G\PanelStackIndex
  EndSelect
EndProcedure
Define Null.i
Define ttip.i
If OpenWindow(0, 0, 0, 270, 200, "GadgetTooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  PanelGadget(2,0,0,270,200)  
  AddGadgetItem(2, -1, "Tab1")  
  ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip-1")
 
  GadgetToolTip(0, "Tooltip for Button and Now with More Lines 1")
  ttip = ToolTipHandle(#gadgets)
 
  SetWindowLongPtr_(ttip, #GWL_STYLE, GetWindowLongPtr_(ttip, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON &~ #WS_BORDER)
  SetWindowTheme_(ttip, @null, @null)

  SendMessage_(ttip,#TTM_SETMAXTIPWIDTH,0,100)                       ;Max tip width 
  AddGadgetItem(2, -1, "Tab2")  
  GadgetToolTip(2, "Tooltip for Button and Now with More Lines 3")
  ttip = ToolTipHandle(#panes)
 
  SetWindowLongPtr_(ttip, #GWL_STYLE, GetWindowLongPtr_(ttip, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON &~ #WS_BORDER)
  SetWindowTheme_(ttip, @null, @null)

  SendMessage_(ttip,#TTM_SETMAXTIPWIDTH,0,100)                       ;Max tip width 

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Tooltips and Panes

Post by IdeasVacuum »

Well, perhaps map the tabs so that if the mouse is hovered over one, your app displays the tooltip.
Not my code, but it works (Windows only):

Code: Select all

Global  TT

Procedure.l callback(hwnd, uMsg, wParam, lParam)
  Static text$
  Result = #PB_ProcessPureBasicEvents
  If uMsg = #WM_MOUSEMOVE
    msg.MSG
    msg\hwnd = hwnd
    msg\message = uMsg
    msg\wParam = wParam
    msg\lParam = lParam
    SendMessage_(TT, #TTM_RELAYEVENT, 0,msg)
  EndIf
  ProcedureReturn Result
EndProcedure

If OpenWindow(0, 0, 0, 300, 300, "Tooltips by area",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  TT = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
  SendMessage_(TT, #TTM_SETTITLE, 1, "HiYa")
  SendMessage_(TT, #TTM_SETMAXTIPWIDTH, 0, 250)
  ;Add two 'tools' by area; one in the top left of the window and one in the bottom right.
    ti.TOOLINFO\cbSize = SizeOf(TOOLINFO)
    ti\uFlags = #TTF_CENTERTIP
    ti\hwnd = WindowID(0)
    ;Top left.
      ti\lpszText = @"Tool 0"
      SetRect_(@ti\rect, 0,0,20,20)
      ;Register tooltip with the control
        SendMessage_(TT, #TTM_ADDTOOL, 0, ti)
    ;Bottom right.
      ti\lpszText = @"Tool 1"
      ti\uId = 1
      SetRect_(@ti\rect, 280,280,300,300)
      ;Register tooltip with the control
        SendMessage_(TT, #TTM_ADDTOOL, 0, ti)
    ;A callback is needed
      SetWindowCallback(@callback())
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow

Endif
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Tooltips and Panes

Post by RASHAD »

Hi

Code: Select all

Global  TT,oldCB

Procedure IsMouseOver(r)
  GetCursorPos_(p.POINT)
  ScreenToClient_ (WindowID(0), @p) 
  Result = PtInRect_(r,p\y << 32 + p\x) 
  ProcedureReturn Result 
EndProcedure 

Procedure.l callback(hWnd, uMsg, wParam, lParam)
  If uMsg = #WM_MOUSEMOVE
    msg.MSG
    msg\hwnd = hWnd
    msg\message = uMsg
    msg\wParam = wParam
    msg\lParam = lParam
    SendMessage_(TT, #TTM_RELAYEVENT, 0,msg)
  EndIf
  ProcedureReturn CallWindowProc_(oldCB,hWnd,uMsg,wParam,lParam)
EndProcedure

If OpenWindow(0, 0, 0, 270, 200, "GadgetTooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  PanelGadget(2,0,0,270,200) 
    AddGadgetItem(2, -1, "Tab1")    
    ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip-1")
    AddGadgetItem(2, -1, "Tab2")
  CloseGadgetList()
  
  SendMessage_(GadgetID(2),#TCM_GETITEMRECT,0,n1.RECT)
  SendMessage_(GadgetID(2),#TCM_GETITEMRECT,1,n2.RECT)
  
  GadgetToolTip(0, "Tooltip For Button 0"+#CR$+"With more than one line")
  GTT = FindWindow_("tooltips_class32",0)
  SetWindowLongPtr_(GTT, #GWL_STYLE, GetWindowLongPtr_(GTT, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON)    ;#TTS_BUBBLE
  SetWindowTheme_(GTT, @null.w, @null.w)
  SendMessage_(GTT,#TTM_SETMAXTIPWIDTH,0,200)
  SendMessage_(GTT,#TTM_SETTIPTEXTCOLOR,$00FF00,0)
  SendMessage_(GTT, #TTM_SETTITLE, #TOOLTIP_INFO_ICON, @"Tooltip for Button 0")
  
  ti.TOOLINFO
  ti\cbSize = SizeOf(ti) 
  ti\uFlags = #TTF_CENTERTIP 
  ti\hWnd = GadgetID(2)
  
  TT_1 = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
  SetWindowTheme_(TT_1, @null, @null)  
  SendMessage_(TT_1, #TTM_SETMAXTIPWIDTH, 0, 250) 
  SendMessage_(TT_1,#TTM_SETTIPTEXTCOLOR,$0000FF,0)
  SendMessage_(TT_1,#TTM_SETTIPBKCOLOR,$D1FFFF,0)
  
  ti\lpszText = @"Tool 0"
  SetRect_(@ti\rect, n1\left,n1\top,n1\right,n1\bottom)
  SendMessage_(TT_1, #TTM_ADDTOOL, 0, ti)
  SendMessage_(TT_1, #TTM_SETTITLE, #TOOLTIP_WARNING_ICON, @"TAB #1")
   
  TT_2 = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON &~ #WS_BORDER, 0, 0, 0, 0, 0, 0, 0, 0)
  SetWindowTheme_(TT_2, @null, @null)
  SendMessage_(TT_2, #TTM_SETMAXTIPWIDTH, 0, 100)
  SendMessage_(TT_2,#TTM_SETTIPTEXTCOLOR,$FF0000,0)
   
  ti\lpszText = @"Tooltip For TAB 2 With More Lines 3"
  SetRect_(@ti\rect, n2\left,n2\top,n2\right,n2\bottom)
  SendMessage_(TT_2, #TTM_ADDTOOL, 0, ti)
  SendMessage_(TT_2, #TTM_SETTITLE, #TOOLTIP_ERROR_ICON, @"TAB #2")
  
  oldCB = SetWindowLongPtr_(GadgetID(2),#GWL_WNDPROC,@callback())
  
Repeat  
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #WM_MOUSEMOVE
      If IsMouseOver(n1)
        TT = TT_1
      ElseIf IsMouseOver(n2)
        TT = TT_2
      EndIf
 EndSelect
Until Quit = 1
EndIf
Egypt my love
GenRabbit
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Dec 31, 2014 5:41 pm

Re: Tooltips and Panes

Post by GenRabbit »

Thanks for the tips both. IdeasVacuum, I dont know if its supposed to be this way, but your program tips gave me one large grey area. And that was it.

Nice code Rashad. It worked. Out of curiosity, can the;

Code: Select all

    Case #WM_MOUSEMOVE
      If IsMouseOver(n1)
        TT = TT_1
      ElseIf IsMouseOver(n2)
        TT = TT_2
      EndIf
Be moved into the callback?

Secondly, both; Shouldn't the callback routine use Integer, not Long, so to be safe with x64, or is a callback supposed to return 32bit value on both?
Last edited by GenRabbit on Tue Jan 10, 2017 1:14 am, edited 1 time in total.
GenRabbit
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Dec 31, 2014 5:41 pm

Re: Tooltips and Panes

Post by GenRabbit »

Got it working. :)

Code: Select all

EnableExplicit
Global.i TT,oldCB
Global.i TT_1, TT_2
Global.rect n1, n2
Procedure IsMouseOver(r.i)
    Protected p.Point
    GetCursorPos_(p)
    ScreenToClient_ (WindowID(0), @p)
    ProcedureReturn PtInRect_(r,p\y << 32 + p\x)
EndProcedure

Procedure.i callback(hWnd.i, uMsg.i, wParam.i, lParam.i)
    Protected msg.MSG
    If uMsg = #WM_MOUSEMOVE
        If IsMouseOver(n1)
            TT = TT_1
        ElseIf IsMouseOver(n2)
            TT = TT_2
        EndIf
        msg\hwnd = hWnd
        msg\message = uMsg
        msg\wParam = wParam
        msg\lParam = lParam
        SendMessage_(TT, #TTM_RELAYEVENT, 0,msg)
    EndIf
    ProcedureReturn CallWindowProc_(oldCB,hWnd,uMsg,wParam,lParam)
EndProcedure
Define gtt.i
Define ti.Toolinfo
Define null.i, Quit.i
If OpenWindow(0, 0, 0, 270, 200, "GadgetTooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    PanelGadget(2,0,0,270,200)
        AddGadgetItem(2, -1, "Tab1")   
        ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip-1")
        AddGadgetItem(2, -1, "Tab2")
    CloseGadgetList()
 
    SendMessage_(GadgetID(2),#TCM_GETITEMRECT,0,n1.RECT)
    SendMessage_(GadgetID(2),#TCM_GETITEMRECT,1,n2.RECT)
 
    GadgetToolTip(0, "Tooltip For Button 0"+#CR$+"With more than one line")
    GTT = FindWindow_("tooltips_class32",0)
    SetWindowLongPtr_(GTT, #GWL_STYLE, GetWindowLongPtr_(GTT, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON)    ;#TTS_BUBBLE
    SetWindowTheme_(GTT, @null, @null)
    SendMessage_(GTT,#TTM_SETMAXTIPWIDTH,0,200)
    SendMessage_(GTT,#TTM_SETTIPTEXTCOLOR,$00FF00,0)
    SendMessage_(GTT, #TTM_SETTITLE, #TOOLTIP_INFO_ICON, @"Tooltip for Button 0")
 
    ti\cbSize = SizeOf(ti)
    ti\uFlags = #TTF_CENTERTIP
    ti\hWnd = GadgetID(2)
 
    TT_1 = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
    SetWindowTheme_(TT_1, @null, @null) 
    SendMessage_(TT_1, #TTM_SETMAXTIPWIDTH, 0, 250)
    SendMessage_(TT_1,#TTM_SETTIPTEXTCOLOR,$0000FF,0)
    SendMessage_(TT_1,#TTM_SETTIPBKCOLOR,$D1FFFF,0)
 
    ti\lpszText = @"Tool 0"
    SetRect_(@ti\rect, n1\left,n1\top,n1\right,n1\bottom)
    SendMessage_(TT_1, #TTM_ADDTOOL, 0, ti)
    SendMessage_(TT_1, #TTM_SETTITLE, #TOOLTIP_WARNING_ICON, @"TAB #1")
   
    TT_2 = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON &~ #WS_BORDER, 0, 0, 0, 0, 0, 0, 0, 0)
    SetWindowTheme_(TT_2, @null, @null)
    SendMessage_(TT_2, #TTM_SETMAXTIPWIDTH, 0, 100)
    SendMessage_(TT_2,#TTM_SETTIPTEXTCOLOR,$FF0000,0)
   
    ti\lpszText = @"Tooltip For TAB 2 With More Lines 3"
    SetRect_(@ti\rect, n2\left,n2\top,n2\right,n2\bottom)
    SendMessage_(TT_2, #TTM_ADDTOOL, 0, ti)
    SendMessage_(TT_2, #TTM_SETTITLE, #TOOLTIP_ERROR_ICON, @"TAB #2")
 
    oldCB = SetWindowLongPtr_(GadgetID(2),#GWL_WNDPROC,@callback())
 
    Repeat 
        Select WaitWindowEvent()
            Case #PB_Event_CloseWindow
                Quit = 1
     
        EndSelect
    Until Quit = 1
EndIf
Post Reply