ToolTips

Started by Douglas McDonald, June 26, 2010, 11:07:12 AM

Previous topic - Next topic

José Roca

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
' ========================================================================================


Roger Garstang

#16
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.

José Roca

The size of the TOOLINFO structure must be of 44 bytes for W2K and below, and of 48 bytes for XP and up.

José Roca

Quote
...and no need to download alternate headers.

True, but there is a little more in them...

Robert Eaton

Tooltips don't seem to work with the FireTextBox control.

Paul Squires

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

Paul Squires
PlanetSquires Software

Robert Eaton

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. ???

Paul Squires

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.  :) 
Paul Squires
PlanetSquires Software

José Roca

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.

Robert Eaton

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.

José Roca

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

Robert Eaton

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

Roger Garstang

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?

José Roca

I have deleted your old account, so you can reregister if you want.

Martin Francom

#29
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