• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Tooltip_SetText usage

Started by David Kenny, March 31, 2014, 11:00:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

David Kenny

I'm trying to figure out how to use this function and couldn't find an code example here or on PB's site.
I've included an example of what I've tried below:
#COMPILE EXE
#DIM ALL
%UNICODE = 1

' // Include files
#INCLUDE ONCE "CWindow.inc"
#INCLUDE ONCE "ToolTipCtrl.inc"

GLOBAL ghChangeCB  AS DWORD
GLOBAL ghToolTip   AS DWORD
%ChangCB = 1001
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

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

   ' // Create the application window.
   pWindow.CreateWindow(%NULL, "Tooltip_SetText Test", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   ' // Set the client size
   pWindow.SetClientSize 300, 300
   ' // Center the window
   pWindow.CenterWindow

   ghChangeCB = pWindow.AddControl( "Button", ghChangeCB, %ChangCB, "Change", _
                        32,  40, 57, 27, _
                        %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_TEXT _
                                  OR %BS_PUSHBUTTON OR %BS_NOTIFY OR %BS_CENTER OR %BS_VCENTER _
                                 ,  %WS_EX_LEFT OR %WS_EX_LTRREADING )

   ghToolTip = pWindow.AddToolTip (ghChangeCB, "Click here to change tooltip text", %FALSE)

   'Tried to change it here
   Tooltip_SetText (ghTooltip, ghChangeCB, "It's been changed")

   pWindow.DoEvents(nCmdShow)

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

   ' // Process window mesages
   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %ChangCB
                IF HI(WORD, wParam) = %BN_CLICKED THEN
                    'And tried it here too
                    Tooltip_SetText (ghTooltip, ghChangeCB, "It's been changed")
                END IF
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT


      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

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

The tooltip never changes.

David

José Roca

If you create the toolltip with pWindow.AddToolTip then change the text with pWindow.SetTooltipText.

If you create it with Tooltip_Add, then change the text with Tooltip_SetText.

But don't mix them.

David Kenny

OK, I feel stupid...  I should have known to look for a method before looking for a function. :-[

Is every thing you can do to a window or control, when not using the pWindow class, available through methods when you are using pWindow?

José Roca

The wrapper functions available in TooltipCtrl.inc are all compatible except Tooltip_Add, Stooltip_Delete and Tooltip_SetText. This is because they use internally the parent of the control, that could be a DDT dialog instead of a SDK window. The rest use the tooltip handle, so no problem. The CWindow class only implements methods for adding (AddTooltip), delete (DeleteTooltip) or set the text (SetTooltipText). For other actions, you can freely use the wrapper functions in TooltipCtrl.inc.

You can also use Tooltip_Add, Tooltip_Delete and Tooltip_SetText with windows and controls created with CWindow. Just don't mix them with the CWindow's AddTooltip, DeleteTooltip and SetTooltipText methods.

David Kenny

Good to know.  I think this gave me enough grief that I might be able to remember next time something similar comes up. 

Thanks Jose!