Page 1 of 1

Bubble help over an area

Posted: Sat Jan 12, 2008 11:04 am
by PeterGams
Last question for a while.
Is it possible to have a help bubble come up over a certain area when the mouse pointer has been moved over it?
Either RMB or just move over the area.
Bit tough this one.

Posted: Sat Jan 12, 2008 11:07 am
by Derek
Try "ToolBarToolTip()"

Mmmm not quite

Posted: Sat Jan 12, 2008 11:17 am
by PeterGams
Having trouble getting "ToolBarToolTip()" to work.
Sorry only a Newbie.

Posted: Sat Jan 12, 2008 2:42 pm
by netmaestro
Try GadgetTooltip, which will let you assign a tooltip to any gadget on your window. The ToolbarTooltip is only for toolbars.

Posted: Sat Jan 12, 2008 2:48 pm
by srod
The following creates a tooltip control (Windows only) and adds two tools corresponding to a 20x20 pixel area at the top left of the window and another one at the bottom right etc.

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
  If uMsg = #WM_NOTIFY
    *nmh.NMHDR=lParam
    If *nmh\code = #TTN_NEEDTEXT
      *tt.TOOLTIPTEXT=lParam
      text$="From tool "+Str(*tt\hdr\idFrom)
      *tt\lpszText=@text$
    EndIf
  EndIf
  ProcedureReturn Result
EndProcedure

OpenWindow(0, 0, 0, 300, 300, "Tooltips by area",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
  CreateGadgetList(WindowID(0)) 
    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) 
      ti\lpszText = #LPSTR_TEXTCALLBACK
      ;Top left.
        SetRect_(@ti\rect, 0,0,20,20)
        ;Register tooltip with the control 
          SendMessage_(TT, #TTM_ADDTOOL, 0, ti) 
      ;Bottom right.
        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 

End 

Posted: Sat Mar 08, 2008 3:55 pm
by Michael Vogel
What a cool example - thanks srod :!:

But that's not all I want to say :twisted:... of course, I have also a small problem with the code:

What have to be done to keep the tooltips at top - I am using it in a window which is also on the top (StickyWindows) and this lousy window is in front of the tooltip frame.

Any idea what I did wrong?

Posted: Sat Mar 08, 2008 6:52 pm
by srod
Any idea what I did wrong?
Aye, using StickyWindow() ! :wink:

You may have to use SetWindowPos_() on the tooltip control just after it is shown. There's probably some notification somewhere which will help out. Failing that - do you really need a sticky window? You can use SetWindowPos_() instead on the window with the #HWND_TOP flag, it is not quite as severe as StickyWindow() which utilises the #HWND_TOPMOST flag.


**EDIT : here you are. When creating the tooltip control specify the parent window to be the sticky window etc.

Code: Select all

TT = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, WindowID(0), 0, 0, 0) 

Posted: Sun Mar 09, 2008 12:34 am
by Michael Vogel
srod wrote:

Code: Select all

TT = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, WindowID(0), 0, 0, 0) 
Thanks, srod!

Now it works nice (deleted my SetWindowPos_ already, see below :roll:) and is a fine, short - and working - code!

I thought, StickyWindows will do exactly the same like SetWindowPos, so I didn't feal bad :?

A feel a little bit more uncomfortable with my SendMessage() line in the Callback routine, can you give me a nice hint for that as well?

Code: Select all

Global InfoText.s
Global InfoID
Global InfoMessage.MSG
Global *InfoStruct.NMHDR
Global *InfoText.TOOLTIPTEXT

Global Callback
Global OnTop=#True


Procedure Callback(WindowID,Message,wParam,lParam)

	Select Message

	Case #WM_SYSCOMMAND
		If wParam=#SC_MAXIMIZE
			Callback=1
			ProcedureReturn 0
		EndIf

	Case #WM_MOUSEMOVE
		InfoMessage\hwnd=WindowID
		InfoMessage\message=Message
		InfoMessage\wParam=wParam
		InfoMessage\lParam=lParam
		SendMessage_(InfoID,#TTM_RELAYEVENT,0,InfoMessage)

	Case #WM_NOTIFY
		*InfoStruct=lParam
		If *InfoStruct\code=#TTN_NEEDTEXT
			*InfoText=lParam
			z=*InfoText\hdr\idFrom
			SendMessage_(InfoID,#TTM_SETTITLE,z%4,"Icon")
			InfoText="Text "+Str(z)

			*InfoText\lpszText=@InfoText
		EndIf
	EndSelect

	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

xsize=300
ysize=200
Anzahl=8

OpenWindow(0,40,40,xsize,ysize," Michael Vogel's Ping Utility ",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget |#PB_Window_MaximizeGadget)

InfoID=CreateWindowEx_(0,"Tooltips_Class32","",#TTS_ALWAYSTIP|#WS_EX_TOPMOST,0,0,0,0,WindowID(0),0,0,0);#TTS_BALLOON
;InfoID=CreateWindowEx_(0,"Tooltips_Class32","",#TTS_ALWAYSTIP|#WS_EX_TOPMOST|#TTS_BALLOON,0,0,0,0,0,0,0,0)
SendMessage_(InfoID,#TTM_SETMAXTIPWIDTH,0,200)
SendMessage_(InfoID,#TTM_SETTITLE,1,"SNMP Informationen")

InfoTool.TOOLINFO
InfoTool\cbSize=SizeOf(TOOLINFO)
InfoTool\uFlags=#TTF_CENTERTIP
InfoTool\hwnd=WindowID(0)
InfoTool\lpszText=#LPSTR_TEXTCALLBACK

CreateGadgetList(WindowID(0))
For i=1 To Anzahl
	TextGadget(i,0,20*i,200,18,"Icon "+Str(i%4)+", Text "+Str(i),#PB_Text_Border)
	InfoTool\uId=i
	SetRect_(@InfoTool\rect,0,20*i,200,20*i+18)
	SendMessage_(InfoID,#TTM_ADDTOOL,0,InfoTool)
Next i

StickyWindow(0,OnTop)
;SetWindowPos_(InfoID,#HWND_TOPMOST,0,0,0,0,#SWP_NOREDRAW|#SWP_NOMOVE|#SWP_NOSIZE); ****

SetWindowCallback(@callback(),0)

Define event.l
Repeat

	Event=WaitWindowEvent()

	Select Event

	Case #PB_Event_CloseWindow
		exit=99


	Case #WM_PAINT
		;			WriteAll()

	EndSelect

	If Callback
		Callback=0
		OnTop=1-OnTop
		StickyWindow(0,OnTop); ****
	EndIf

Until exit

Huiii - checked the program on an old notebook (WinXP) and a tooltip starts from transparent to not so transparent and before anything is really readable it fades away slowly, whats going on here :?:

At least, the fade in is gone (with the following change) - but the fade out effect is still present :cry:

Code: Select all

#TTS_NOFADE=$20
#TTS_NOANIMATE=$10

	InfoID=CreateWindowEx_(0,"Tooltips_Class32","",#TTS_ALWAYSTIP|#TTS_NOFADE|#TTS_NOANIMATE|#WS_EX_TOPMOST,0,0,0,0,0,0,0,0);#TTS_BALLOON

Added:
The actual state of my small Ping utility is here: http://sudokuprogram.googlepages.com/vping.zip
On the left side (IP-addresses) I use the tooltip to see the name and type of the device (if available)...
Still fighting with some issues: fading is still present (and slow) and changing the title with sendmessage means wrong titles from time to time...

Posted: Sun Mar 09, 2008 11:07 am
by srod
Sorry Michael, all works fine here on my old P3 laptop with XP pro.

Posted: Sun Mar 09, 2008 9:13 pm
by Michael Vogel
srod wrote:Sorry Michael, all works fine here on my old P3 laptop with XP pro.
Thanks for testing - the fading problem seems to be seen only on one notebook, and the title issue is maybe an error of the programmer (and writer of these lines)...

Michael