PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Douglas McDonald on June 26, 2010, 11:07:12 AM

Title: ToolTips
Post by: Douglas McDonald on June 26, 2010, 11:07:12 AM
I searched on tooltips and found a few threads and some cool code samples from 2009. Before I try and add the code samples to my project I wonder if FF3 supports or is going to add tooltips to buttons,lables, textboxes ect...

I see that some, very few controls have a tooltips but I have not been able to make it work. There is nothing I can find in the manual on the subject.
My current version is 3.09
Title: Re: ToolTips
Post by: José Roca on June 26, 2010, 12:32:26 PM
If you use my include files, add #INCLUDE "WinCtrl.inc" to your program and call a function named Window_AddTooltip.

Usage:


' ========================================================================================
' Adds a tooltip control to the window
' Parameters:
' - hParent = Parent window handle
' - hwnd = Handle of the window
' - strTooltipText = Tooltip text
' - dwStyle = Tooltip window style(s) [pass -1 for default styles]
' - dwExStyle = Tooltip window extended style(s) [pass -1 for default styles]
' - bCentered = Centered (TRUE or FALSE)
' Note: If you want balloon tooltips, pass the following values in the dwStyle parameter:
' %WS_POPUP OR %WS_BORDER OR %WS_CLIPSIBLINGS OR %TTS_BALLOON
' Return Value:
'   The handle of the tooltip control
' ========================================================================================


hParent is the handle of the form and hwnd the handle of the control.
Title: Re: ToolTips
Post by: Douglas McDonald on June 26, 2010, 04:42:09 PM
Jose,

Once again you wrote the tool make things look easy. I'm grateful.

Thank you
Doug
Title: Re: ToolTips
Post by: José Roca on June 26, 2010, 05:32:10 PM
One of the biggest advantages of using the Windows API instead of DDT is that you don't have to wait for years to see if Mr. Zale will add CONTROL ADD TOOLTIP to the language. You simply write your wrapper function or use an existing one. There are so many in my include files that even I have a hard time to remember them.
Title: Re: ToolTips
Post by: Douglas McDonald on June 30, 2010, 02:18:57 PM
Jose,

I've used your Window_AddTooltip and it works well in XP but it doesn't work in win7 x64. I get a handle returned but no tool tip shows up.


Function MAIN_BUTTON_WM_MOUSEMOVE ( _
                                  ControlIndex  As Long,  _  ' index in Control Array
                                  hWndForm      As Dword, _  ' handle of Form
                                  hWndControl   As Dword, _  ' handle of Control
                                  MouseFlags    As Long,  _  ' virtual keys that are pressed
                                  xPos          As Long,  _  ' x-coordinate of cursor
                                  yPos          As Long   _  ' y-coordinate of cursor
                                  ) As Long
Local retval As Dword
'ztrace Str$(MouseFlags)
retval = Window_AddTooltip(HWND_MAIN,HWND_MAIN_BUTTON(0),"TIP",-1,-1)',%false,%TTS_BALLOON)
'ztrace Str$(retval)
End Function




Thank you
Doug
Title: Re: ToolTips
Post by: Douglas McDonald on June 30, 2010, 05:27:09 PM
It works in win7 x64. At least a program compiled on XP shows tooltips when run on a win7 x64 PC.

now i can't get it to compile on the win7 x64 Pc do to a resource file error

Thanks
Title: Re: ToolTips
Post by: José Roca on June 30, 2010, 08:21:54 PM
Works fine in Windows 7 32 bit. Don't have the 64 bit version.
Title: Re: ToolTips
Post by: Martin Francom on July 02, 2010, 03:12:21 AM
Does anyone have a FF3 example program that demonstrates the use of Jose'  AddToolTip  control   that they would be willing to post?
Title: Re: ToolTips
Post by: José Roca on July 02, 2010, 12:52:45 PM
It is not a control, just a function.
Title: Re: ToolTips
Post by: Robert Eaton on July 02, 2010, 02:05:46 PM
The simple statement in the code below seems to work. (Of course you need to use the include files from Jose.)

However, I haven't had any luck getting the balloon style to work so far.

Function FRMMAIN_WM_CREATE ( _
                           hWndForm As Dword, _      ' handle of Form
                           ByVal UserData As Long _  ' optional user defined Long value
                           ) As Long
                           

Window_AddTooltip (HWND_FRMMAIN, HWND_FRMMAIN_XPBUTTON1, "This is a tool tip.",-1,-1)


End Function
Title: Re: ToolTips
Post by: José Roca on July 02, 2010, 02:20:34 PM
For the balloon style you need a manifest.

Edit: Sorry for this misinformation. Ballon tooltips are available since version 5.80 of COMCTL32.DLL. Therefore a manifest isn't needed.
Title: Re: ToolTips
Post by: Douglas McDonald on July 04, 2010, 11:11:48 AM
Here's how I used the tool tips. It seems to work well but there may be a better way to do it. I catch the mouse entering and leaving a control where I want the tool tip. For some reason I only get %WM_mousefirst and %WM_mouseleave. I do not get any other mouse messages. I set a flag so I do not get 1000's of messages.


Function MAIN_BUTTON_CUSTOM ( _
                            ControlIndex  As Long,  _  ' index in Control Array
                            hWndForm      As Dword, _  ' handle of Form
                            hWndControl   As Dword, _  ' handle of Control
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long
Static mFlag As Word                           
Local msg As String
Local retval As Word
Select Case wMsg
  Case %WM_mousefirst
        If  mFlag = 0  Then
            mFlag = 1
           Select Case ControlIndex
            Case 0
               msg = "Add selected program from right to action list"
            Case 1
               msg = "Remove program from action list"
            Case 2
               msg = "Refresh running programs list"
            Case 3
               msg = "Ping / get status of motion sensor"
            Case 4
               msg = "Actavate settings, motion sensor and minimize program "
            Case 5
               msg = "Exit, no futher action taken if motion sensor trips "
           End Select
           retval = Window_AddTooltip(hWndForm,hWndControl,msg,%TTS_BALLOON,-1)',0)
        End If
  Case %WM_mouseleave
        If mFlag = 1  Then
            mFlag = 0
        End If
       
End Select


End Function



Doug

Title: Re: ToolTips
Post by: Robert Eaton on July 04, 2010, 12:13:45 PM
Doug,
When I try that, it seems to cause a small memory leak.

Bob
Title: Re: ToolTips
Post by: José Roca on July 04, 2010, 12:37:59 PM
The function is to create a tooltip control and associate it win  a windows and control. Creating a new tooltip control each time you want to show it or change the text will drain your resources. Update it sending the TTM_UPDATETIPTEXT message ( http://msdn.microsoft.com/en-us/library/bb760427%28VS.85%29.aspx ) or delete it first before recreate it by sending the TTM_DELTOOL message ( http://msdn.microsoft.com/en-us/library/bb760365%28VS.85%29.aspx ).
Title: Re: ToolTips
Post by: Robert Eaton on July 04, 2010, 05:25:06 PM
Here is an example of balloon tooltips using an include file by William Burns over on the PB forum. http://www.powerbasic.com/support/pbforums/showthread.php?t=24645 (http://www.powerbasic.com/support/pbforums/showthread.php?t=24645)

Title: Re: ToolTips
Post by: José Roca on July 04, 2010, 06:42:58 PM
Just in case somebody thinks that my function doesn't work, here is a short example using my headers.


#COMPILE EXE
#DIM ALL

%USEMACROS = 1                ' // Use macros
%USERICHEDIT = 1              ' // Use RichEdit
#INCLUDE ONCE "CWindow.inc"   ' // CWindow class
#INCLUDE ONCE "winctrl.inc"   ' // Window wrapper functions

%IDC_RICHEDIT = 101

' ########################################################################################
' Main
' ########################################################################################
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "SDK Window", 0, 0, 500, 350, -1, -1, CODEPTR(WindowProc))
   Window_Center hwnd

   ' // Add a rich edit control
   pWindow.AddRichEdit(hwnd, %IDC_RICHEDIT, "RichEdit box", 100, 50, 300, 150, -1, -1)

   ' // Subclassed button with balloon tooltip
   LOCAL hButton AS DWORD
   hButton = pWindow.AddButton(hwnd, %IDCANCEL, "&Close", 350, 250, 75, 23, -1, -1, CODEPTR(TextBtn_SubclassProc))
   Window_AddTooltip(hwnd, hButton, "I'm a subclassed button", %WS_POPUP OR %WS_BORDER OR %WS_CLIPSIBLINGS OR %TTS_BALLOON, -1)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents

END FUNCTION
' ########################################################################################

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // Close the main window
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Processes messages for the subclassed Button window.
' ========================================================================================
FUNCTION TextBtn_SubclassProc ( _
   BYVAL hwnd   AS DWORD, _                 ' // Control window handle
   BYVAL uMsg   AS DWORD, _                 ' // Type of message
   BYVAL wParam AS DWORD, _                 ' // First message parameter
   BYVAL lParam AS LONG _                   ' // Second message parameter
   ) AS LONG

   ' // REQUIRED: Get the address of the original window procedure
   LOCAL pOldWndProc AS DWORD
   pOldWndProc = GetProp(hwnd, "OLDWNDPROC")

   SELECT CASE uMsg
      CASE %WM_DESTROY
         ' // REQUIRED: Remove control subclassing
         SetWindowLong hwnd, %GWL_WNDPROC, RemoveProp(hwnd, "OLDWNDPROC")
   END SELECT

   FUNCTION = CallWindowProc(pOldWndProc, hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

Title: Re: ToolTips
Post by: Roger Garstang on July 06, 2010, 12:23:14 PM
http://www.planetsquires.com/protect/forum/index.php?topic=1955.0

Probably the most recent topic and code with the most functionality...and no need to download alternate headers.  There was a post about tooltips not showing again until app was closed if the timeout is allowed to close the tooltip in XP.  2000/XP does have some issues in drawing tips, but I think if you show a tip in another control it resets the timer so the first control shows the tooltip again.  The other annoying thing is 2000/XP likes to drop the TopMost style often for them and they show behind other controls (Most evident in the Tasktray when the tooltips suddenly start appearing behind the taskbar.  People that sort their Start Menu and/or have it selected to keep the taskbar on top of other windows notice it the most because Windows usually drops the style when drawing like that.

And, a Manifest is needed if you want more advanced functionality...while Balloon Tips have been around since WinME, things like custom icons and such have not.
Title: Re: ToolTips
Post by: José Roca on July 06, 2010, 01:21:10 PM
The size of the TOOLINFO structure must be of 44 bytes for W2K and below, and of 48 bytes for XP and up.
Title: Re: ToolTips
Post by: José Roca on July 06, 2010, 01:23:48 PM
Quote
...and no need to download alternate headers.

True, but there is a little more in them...
Title: Re: ToolTips
Post by: Robert Eaton on July 07, 2010, 12:10:11 AM
Tooltips don't seem to work with the FireTextBox control.
Title: Re: ToolTips
Post by: Paul Squires on July 07, 2010, 08:30:47 AM
Quote from: Robert Eaton on July 07, 2010, 12:10:11 AM
Tooltips don't seem to work with the FireTextBox control.

They do. The "trick" is knowing that a FireTextBox control is actually composed of two windows. The actual edit control and a parent window that holds it (and displays the underline and other eye candy).

You need to attach the tooltip to the edit control portion. The HWND returned by FF3 is for the parent window of that edit control. You would use GetDlgItem to retrieve the edit control portion.

The following code works and displays a tooltip when the mouse is over the FireTextBox.



#INCLUDE Once "winctrl.inc"   ' // Window wrapper functions

'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long

   Window_AddTooltip hWndForm, _
                     GetDlgItem(HWND_FORM1_FIRETEXTBOX1, 100), _
                     "I'm a FireTextBox Custom Control", _
                     %WS_POPUP Or %WS_BORDER Or %WS_CLIPSIBLINGS Or %TTS_BALLOON, _
                     -1

End Function

Title: Re: ToolTips
Post by: Robert Eaton on July 07, 2010, 09:21:23 AM
Thanks Paul.
I'm still confused on the balloon style issue. Your example specifies to use it, but it doesn't work that way for me.

Jose says that a manifest needs to added. Since Firefly creates a manifest, does this mean that needs to be edited or a separate resource added for it? (And what gets added?)

And then there are other examples (such as the one I posted) that work without any changes to the manifest. ???
Title: Re: ToolTips
Post by: Paul Squires on July 07, 2010, 10:31:00 AM
Not sure about the balloon style issue (it didn't work for me either based on the example that I posted). I don't use that style in my apps so I have never researched what the issues would be. If a manifest is needed then you would need to manually edit the one that is generated by FF3. Not sure even what you would have to add to it.  :) 
Title: Re: ToolTips
Post by: José Roca on July 07, 2010, 10:48:52 AM
A manifest isn't needed. Sorry for this misinformation. Ballon tooltips are available since version 5.80 of COMCTL32.DLL.

Compile and run the sample code that I have posted in Reply #15 (it's not a FF project, so compile it using the PB IDE or another editor). It shows a balloon tooltip in my system (Windows 7, 32 bit).

The attached file contains the source code and the executable.
Title: Re: ToolTips
Post by: Robert Eaton on July 07, 2010, 11:24:45 AM
Jose,
I tried your previous example as well as the one you just posted.
Your exe works correctly, but in both cases the version I compile here only shows a standard style tooltip.
The file sizes are also different (54,784 for yours vs 54,272 for mine) so I can only assume that the difference is in my include files.
Title: Re: ToolTips
Post by: José Roca on July 07, 2010, 11:48:09 AM
Keep them updated. I just have released version 1.16, updated to Windows 7. Now PBer's can use the new goodies that offers this operating system.

See: http://www.jose.it-berater.org/smfforum/index.php?topic=3759.0
Title: Re: ToolTips
Post by: Robert Eaton on July 07, 2010, 12:10:11 PM
I'm not using Win 7 yet (and no Vista machine handy here at work), but that fixed the problems on XP (including Paul's example).

Thanks ;D
Title: Re: ToolTips
Post by: Roger Garstang on July 07, 2010, 02:06:40 PM
Quote from: TechSupport on July 07, 2010, 10:31:00 AM
Not sure about the balloon style issue (it didn't work for me either based on the example that I posted). I don't use that style in my apps so I have never researched what the issues would be. If a manifest is needed then you would need to manually edit the one that is generated by FF3. Not sure even what you would have to add to it.  :) 

Shouldn't need to edit Manifests FF creates, they just tell it to use the XP+ versions of the files.  They can be a file or within the exe resource (the method I prefer).

On the toolinfo size...PB's version is 48bytes, and the only difference is the last reserved which is null and not even used.  I've used it on Win2K and Win9x systems without issues.  Couldn't go and download the latest JR headers...I must have registered with an old email and have no clue what my password is since I've only been there once.  If these are going to be an option in FF shouldn't they be included with the install or available here?
Title: Re: ToolTips
Post by: José Roca on July 07, 2010, 02:35:13 PM
I have deleted your old account, so you can reregister if you want.
Title: Re: ToolTips
Post by: Martin Francom on January 02, 2011, 01:57:59 PM
Quote from: Jose Roca on July 04, 2010, 12:37:59 PM
The function is to create a tooltip control and associate it win  a windows and control. Creating a new tooltip control each time you want to show it or change the text will drain your resources. Update it sending the TTM_UPDATETIPTEXT message ( http://msdn.microsoft.com/en-us/library/bb760427%28VS.85%29.aspx ) or delete it first before recreate it by sending the TTM_DELTOOL message ( http://msdn.microsoft.com/en-us/library/bb760365%28VS.85%29.aspx ).


Jose   After reading the link, I am still confused as to how to write the call to Delete a Tool Tip.   I am sure it is obvious, but I don't see it.   Could you be specific on how to write the call to delete the following tool tips?


'--------------------------------------------------------------------------------
Function FRMMAIN_WM_CREATE ( _
                           hWndForm As Dword, _      ' handle of Form
                           ByVal UserData As Long _  ' optional user defined Long value
                           ) As Long

SetToolTip HWND_FRMMAIN, IDC_FRMMAIN_TEXT1, "This is a text box."
SetToolTip HWND_FRMMAIN, IDC_FRMMAIN_COMMAND1, "This is a button."
SetToolTip HWND_FRMMAIN, IDC_FRMMAIN_CHECK1, "This is a checkbox." & Chr$(13,10) & "Second Line"
'SetToolTip HWND_FRMMAIN, 0, "This is the form."
End Function


Would it be something like?
    DelToolTip HWND_FRMMAIN, IDC_FRMMAIN_CHECK1
Title: Re: ToolTips
Post by: José Roca on January 02, 2011, 04:09:23 PM
As you kill any other control. I think there is a wrapper function called FF_Control_Kill.