It is currently Wed Jun 19, 2013 5:46 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Tooltip handle
PostPosted: Tue Mar 17, 2009 3:53 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6466
You can create an API tooltip control and make it any way you want, but I thought it would be fun to make customized changes to native PB tooltips. To do this, you need the handle of the tooltip but GadgetToolTip() doesn't return that. I don't know what it is returning, but it isn't the handle. So I made a couple of solutions, pick whichever you like (if any :wink: )

ToolTipID version:
Code:
Procedure EnumProc(hwnd, lparam)
  Shared ctrl
  cn$ = Space(100)
  GetClassName_(hwnd, @cn$, 99)
  If UCase(cn$) = "TOOLTIPS_CLASS32"
    With ti.TOOLINFO
      \cbSize = SizeOf(TOOLINFO)
      \hwnd = GetParent_(ctrl)
      \uid = ctrl
    EndWith
    If SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti)
      PokeI(lparam, hwnd)
      ProcedureReturn 0
    Else
      ProcedureReturn 1
    EndIf
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

ProcedureDLL.i ToolTipID(gadget)
  Shared ctrl
  ctrl = gadget
  EnumWindows_(@EnumProc(),@TTID)
  ProcedureReturn TTID
EndProcedure

; test program
OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
GadgetToolTip(1, "This is a tooltip")
ttid = ToolTipID(GadgetID(1))
SetWindowLong_(ttid,#GWL_STYLE,GetWindowLong_(ttid,#GWL_STYLE)|#TTS_BALLOON &~#WS_BORDER)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

GadgetToolTipEx version:
Code:
Procedure TT_CBTHookProc(nCode, wParam, lParam)
  Shared _Hook, TT_HWND
  Select nCode
    Case #HCBT_CREATEWND
      *pcbt.CBT_CREATEWND = lParam
      *pcs.CREATESTRUCT = *pcbt\lpcs
      Select PeekS(*pcs\lpszClass)
        Case "tooltips_class32"
          TT_HWND = wParam
      EndSelect
  EndSelect
  ProcedureReturn CallNextHookEx_(_Hook, nCode, wParam, lParam)
EndProcedure

Procedure GadgetToolTipEx(gadget_number, tooltip_text$)
  Shared _Hook, TT_HWND
  _Hook = SetWindowsHookEx_(#WH_CBT, @TT_CBTHookProc(), #Null, GetCurrentThreadId_())
  GadgetToolTip(gadget_number, tooltip_text$)
  UnhookWindowsHookEx_(_Hook)
  ProcedureReturn TT_HWND
EndProcedure

; Test

OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
ttid = GadgetToolTipEx(1, "This is a tooltip")
SetWindowLong_(ttid,#GWL_STYLE,GetWindowLong_(ttid,#GWL_STYLE) | #TTS_BALLOON &~ #WS_BORDER ) ; Will be a balloontip if we succeeded
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Note that the border has to come off if you're changing to a balloon.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 17, 2009 8:53 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1720
Thanks,

these functions should find a way to get into the next PB versions :!:

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 17, 2009 3:05 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Sep 12, 2003 10:40 pm
Posts: 677
Location: Tallahassee, Florida
you can also add gadgets like an imagegadget to a tooltip for image preview purposes!!!


I have almost perfected this, and it works like a charm. No need to create additional popup windows with callbacks. Just use the existing tooltip and an an imagegadget to it and use the window properties of the htooltip to store the PB ID of the imagegadget and the displayed image. The OS ten manages its display, position ect.

As soon as I extract the source from the large program I am writing and get it working as a standalone, I will post an example.

_________________
Code:
!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 4:42 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4740
Location: Berlin - Germany
here another version :wink:
Code:
Structure GadgetGlobals
  CurrentWindow.i
  FirstOptionGadget.i
  DefaultFont.i
  *PanelStack
  PanelStackIndex.l
  PanelStackSize.l
  ToolTipWindow.i
EndStructure

Import ""
  PB_Object_GetThreadMemory(*Mem)
  PB_Gadget_Globals
EndImport

Procedure ToolTipID() 
  Protected *gg.GadgetGlobals 
  *gg = PB_Object_GetThreadMemory(PB_Gadget_Globals) 
  ProcedureReturn *gg\ToolTipWindow 
EndProcedure

; test program
OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
GadgetToolTip(1, "This is a tooltip")
ttid = ToolTipID()
SetWindowLongPtr_(ttid,#GWL_STYLE,GetWindowLongPtr_(ttid,#GWL_STYLE)|#TTS_BALLOON &~#WS_BORDER)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

for x86 and x64

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Linux Mint 15 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 7:28 pm 
Offline
User
User
User avatar

Joined: Sun Mar 22, 2009 2:53 pm
Posts: 47
Location: GER, Saxony
@netmaestro & ts-soft:
Thanks, i can just use it.


Top
 Profile  
 
 Post subject: Re: Tooltip handle
PostPosted: Sat Jun 02, 2012 1:52 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 1587
Location: Berlin, Germany
This is exactly what I was looking for. Many thanks to you, netmaestro and ts-soft!
Many tips here on the forum about Tooltips are unnecessarily complicated.
And customizing several aspects of native PB tooltips is easy, once we have the handle.

I needed the handle for increasing the timeout. The default setting of 5 seconds often isn't enough, and it's annoying when a tooltip disappears while reading it.

Code:
Macro SetTooltipTimeout (_hTooltip_, _msec_)
   ; -- Set timeout for all tooltips in the program
   ;    (GadgetToolTip() must have been called before at least once)
   ; in: _hTooltip_: Tooltip-ID (Handle)
   ;     _msec_    : Timeout in milliseconds (max. 32767)
   SendMessage_(_hTooltip_, #TTM_SETDELAYTIME, #TTDT_AUTOPOP, _msec_)
EndMacro


Michael Vogel wrote:
these functions should find a way to get into the next PB versions :!:

Yes :!:

Regards, Little John

_________________
Math problems?
Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x].


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: jack and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye