tooltil

Just starting out? Need help? Post your questions and find answers here.
NewMan
User
User
Posts: 11
Joined: Sun Jul 25, 2004 9:54 am

tooltil

Post by NewMan »

is it possible to show tooltip in the whole window rather than just gadgets? i tried it but it didnt work. and is it possible to show tooltip on gadgets which have been hidden(hidegadget)?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

How about something like this...

Code: Select all

; --> Constant for finding hidden gadget(s)
#CWP_ALL = 0

; --> POINT structure for mouse position
mPos.POINT

; --> Tooltip info structure
ti.TOOLINFO
ti\cbSize = SizeOf(TOOLINFO) 

; --> Tooltip text
buttonTT$ = "My Button Tooltip"
windowTT$ = "My Window Tooltip"

; --> Globals for Tooltip info
Global ti, hToolTip

; --> Create tooltip for entire window
Procedure myWindowToolTip(hWnd, ttText$) 
  If hToolTip = 0
    hToolTip = CreateWindowEx_(#WS_EX_TOPMOST, "ToolTips_Class32","", #WS_POPUP | #TTS_NOPREFIX | #TTS_ALWAYSTIP, 0, 0, 0, 0, WindowID(0), 0, GetModuleHandle_(0), 0) 
    SetWindowPos_(hToolTip, #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOACTIVATE)
  EndIf
  GetClientRect_(hWnd, @winRect.RECT)
  ti\uFlags = #TTF_SUBCLASS 
  ti\hWnd = hWnd
  ti\hinst = GetModuleHandle_(0)
  ti\uId = 0
  ti\lpszText = @ttText$
  ti\rect\left = winRect\left
  ti\rect\top = winRect\top
  ti\rect\right = winRect\right
  ti\rect\bottom = winRect\bottom
  SendMessage_(hToolTip, #TTM_ADDTOOL, 0, ti) 
EndProcedure 

If OpenWindow(0, 0, 0, 270, 100, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Hidden Gadget Tooltip") And CreateGadgetList(WindowID(0))
  myWindowToolTip(WindowID(), windowTT$)
  ButtonGadget(0, 10, 10, 250, 30, "Button Zero")
  GadgetToolTip(0, buttonTT$)
  ButtonGadget(1, 10, 70, 100, 20, "Hide Button Zero")
  buttonVisible = #True
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_EventGadget
        Select EventGadgetID()
          Case 1
            If GetGadgetText(1) = "Hide Button Zero"
              SetGadgetText(1, "Show Button Zero")
              HideGadget(0, 1)
              buttonVisible = #False
            Else
              SetGadgetText(1, "Hide Button Zero")
              HideGadget(0, 0)
              buttonVisible = #True
            EndIf
        EndSelect
      Case #WM_MOUSEMOVE
        ; --> Get current mouse location
        mPos\x = WindowMouseX()
        mPos\y = WindowMouseY()
        ; --> Determine if our ButtonGadget is under mouse
        childGadget = ChildWindowFromPointEx_(WindowID(0), WindowMouseX(), WindowMouseY(), #CWP_ALL)
        ; --> If it is, change text for Window Tooltip
        If childGadget = GadgetID(0) And buttonVisible = #False And ttChange = 0
          Debug "Changing To Hidden Button Tooltip"
          ttText$ = buttonTT$ + " (hidden)"
          ti\lpszText = @ttText$
          SendMessage_(hToolTip, #TTM_UPDATETIPTEXT, 0, ti)
          ttChange = 1
          ; --> If it isn't, change text for Window Tooltip back to original text
        ElseIf childGadget = WindowID(0) And buttonVisible = #False And ttChange = 1
          Debug "Changing To Original Window Tooltip"
          ti\lpszText = @windowTT$
          ; --> Send the change
          SendMessage_(hToolTip, #TTM_UPDATETIPTEXT, 0, ti)
          ttChange = 0
        EndIf
    EndSelect
  Until event = #PB_Event_CloseWindow
EndIf
End

What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply