Announcement

Collapse
No announcement yet.

Tooltips for individual statusbar panels

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tooltips for individual statusbar panels

    I'm currently using tooltip code posted by E.B. Knoppert. It did everything I needed untill now. I'd like to display individual tooltips to each statusbar panel.

    While this code is fine, I'm not wedded to it, so if there is some alternate approach that makes it easier to implement statusbar tooltips than that fine also.

    I'm looking for hints as to how to do this? Do the panels have handles?

    Here's the code I'm currently using -

    Code:
    '-------------------------------------------------------------------------------
    '
    ' PROCEDURE: ToolTip_SetToolTip
    ' PURPOSE:   Add a tooltip to a window/control
    ' RETURN:    nothing
    ' SOURCE:    Lifted from E.B. Knoppert
    '
    '-------------------------------------------------------------------------------
    FUNCTION ToolTip_SetToolTip(BYVAL hWnd AS LONG, BYVAL sTEXT AS STRING ) AS LONG
    
        DIM ti AS myTOOLINFO
    
        ' Be sure we have created the tooltip window.
        IF ToolTip_Create(GetParent(hWnd)) = 0 THEN EXIT FUNCTION
    
        ti.cbSize   = LEN(ti)
        ti.uFlags   = %TTF_SUBCLASS OR %TTF_IDISHWND
        ti.hWnd     = GetParent(hWnd)
        ti.uId      = hWnd
    
        ' Remove existing tooltip.
        IF SendMessage(hWnd_ToolTip, %TTM_GETTOOLINFO, 0, BYVAL VARPTR(ti)) THEN
          CALL SendMessage(hWnd_ToolTip, %TTM_DELTOOL, 0, BYVAL VARPTR(ti))
        END IF
    
        ti.cbSize   = LEN(ti)
        ti.uFlags   = %TTF_SUBCLASS OR %TTF_IDISHWND
        ti.hWnd     = GetParent(hWnd)
        ti.uId      = hWnd
        ti.lpszText = STRPTR(sTEXT)
    
        ' Add tooltip now.
        FUNCTION = SendMessage(hWnd_ToolTip, %TTM_ADDTOOL, 0, BYVAL VARPTR(ti))
    END FUNCTION
    
    
    '-------------------------------------------------------------------------------
    '
    ' PROCEDURE: ToolTip_Create
    ' PURPOSE:   Used by ToolTip_SetToolTip to create ToolTip window
    ' RETURN:    nothing
    ' SOURCE:    Lifted from E.B. Knoppert
    '
    '-------------------------------------------------------------------------------
    FUNCTION ToolTip_Create(BYVAL hWnd AS LONG)AS LONG              ' used by ToolTip_SetToolTip ONLY
    
        IF hWnd_ToolTip = 0 THEN
            IF hWnd = 0 THEN hWnd = GetActiveWindow()
            IF hWnd = 0 THEN EXIT FUNCTION
    
            hWnd_ToolTip = CreateWindowEx(0 _
                , "tooltips_class32" _
                , "" _
                , %TTS_ALWAYSTIP OR %TTS_BALLOON _
                , 0 _
                , 0 _
                , 0 _
                , 0 _
                , hWnd _
                , BYVAL 0& _
                , GetWindowLong(hWnd, %GWL_HINSTANCE) _
                , BYVAL 0&)
            SendMessage(hWnd_ToolTip, %TTM_SETMAXTIPWIDTH, 0, 200)                  ' from Fred Buffington
            SendMessage(hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOPOP, 15000)
            'SendMessage(hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOMATIC, 350)
            SendMessage(hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOMATIC, 1000)
    
        END IF                    '     for multi-line tooltips - use CHR$(13) to force
                                  '     a new line, but it will word wrap past the
        FUNCTION = hWnd_ToolTip   '     200 pixel limit (which can be increased)
    
    END FUNCTION
    
    
    '-------------------------------------------------------------------------------
    '
    ' PROCEDURE: Create_ToolTips
    ' PURPOSE:   Amazingly, this sub creates the tooltips
    ' RETURN:    nothing
    '
    '-------------------------------------------------------------------------------
    SUB Create_ToolTips()
      ToolTip_SetToolTip (control handle, tooltip string)
      .
      etc
      .
    END SUB

  • #2
    > Do the panels have handles?

    No, but they have index. See:

    https://forum.powerbasic.com/forum/u...056#post478056
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      And they have areas. Old example, updated for PBWin10:
      Code:
      #COMPILE EXE
      #INCLUDE "WIN32API.INC"
      #INCLUDE "COMMCTRL.INC"
      %ID_STATUSBAR = 180
      
      '====================================================================
      FUNCTION PBMAIN () AS LONG
       LOCAL hDlg, hStatus AS DWORD, rc AS RECT, sTxt AS STRING
      
        DIALOG NEW 0, "Statusbar tooltip test..",,, _
                      240, 150, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
        CONTROL ADD BUTTON,  hDlg, %IDCANCEL, "&Cancel", 184, 120,  50,  14
      
        InitCommonControls
      
        CONTROL ADD "msctls_statusbar32", hDlg, %ID_STATUSBAR, "", 0, 0, 0, 0, _
                                          %WS_CHILD OR %WS_VISIBLE
        CONTROL HANDLE hDlg, %ID_STATUSBAR TO hStatus
      
        REDIM prts(3) AS LONG
        GetClientRect hDlg, rc
        prts(0) = rc.nRight / 4     : prts(1) = rc.nRight / 4 * 2
        prts(2) = rc.nRight / 4 * 3 : prts(3) = -1
        Sendmessage hStatus, %SB_SETPARTS, 4, VARPTR(prts(0))
      
        sTxt = "Part 1" : SendMessage hStatus, %SB_SETTEXT, 0, STRPTR(sTxt)
        sTxt = "Part 2" : SendMessage hStatus, %SB_SETTEXT, 1, STRPTR(sTxt)
        sTxt = "Part 3" : SendMessage hStatus, %SB_SETTEXT, 2, STRPTR(sTxt)
        sTxt = "Part 4" : SendMessage hStatus, %SB_SETTEXT, 3, STRPTR(sTxt)
      
        IF SendMessage(hStatus, %SB_GETRECT, 0, VARPTR(rc)) THEN _
           SetToolTipsArea hStatus, rc, "Tooltip for part 1"
      
        IF SendMessage(hStatus, %SB_GETRECT, 1, VARPTR(rc)) THEN _
           SetToolTipsArea hStatus, rc, "Tooltip for part 2"
      
        IF SendMessage(hStatus, %SB_GETRECT, 2, VARPTR(rc)) THEN _
           SetToolTipsArea hStatus, rc, "Tooltip for part 3"
      
        IF SendMessage(hStatus, %SB_GETRECT, 3, VARPTR(rc)) THEN _
           SetToolTipsArea hStatus, rc, "Tooltip for part 4"
      
        DIALOG SHOW MODAL hDlg CALL DlgProc
      END FUNCTION
      
      
      '====================================================================
      CALLBACK FUNCTION DlgProc() AS LONG
      
        SELECT CASE CBMSG
           CASE %WM_COMMAND
              IF CBCTLMSG = %BN_CLICKED THEN
                 SELECT CASE CBCTL
                    CASE %IDCANCEL : DIALOG END CBHNDL
                 END SELECT
              END IF
      
        END SELECT
      END FUNCTION
      
      
      '====================================================================
      FUNCTION SetToolTipsArea(BYVAL hWnd AS DWORD, rc AS RECT, BYVAL sTxt AS STRING) AS LONG
        LOCAL hInst AS DWORD, ti AS TOOLINFO
        STATIC hToolTip AS DWORD
      
        hInst = GetModuleHandle("")
      
        IF hToolTip  = 0 THEN
           hToolTip = CreateWindowEx(0, "tooltips_class32", "", %TTS_ALWAYSTIP OR %TTS_BALLOON, _
                                        0,0,0,0,0, BYVAL %NULL, hInst, BYVAL %NULL)
        END IF
      
        ti.cbSize   = SIZEOF (ti)
        ti.uFlags   = %TTF_SUBCLASS
        ti.hwnd     = hWnd
        ti.hinst    = hInst
        ti.lpszText = STRPTR(sTxt)
        ti.rrect    = rc   ' was ti.rec in earlier (<PBWin10) include files...
      
        FUNCTION = SendMessage(hToolTip, %TTM_ADDTOOL, 0, BYVAL VARPTR(ti))
      END FUNCTION

      Comment


      • #4
        Thanks both Jose and Borje. (sorry Jose and can't figure out how to do the mark over the e).

        Comment


        • #5
          (sorry Jose and can't figure out how to do the mark over the e)
          José
          I have been known to copy, paste, and if necessary unlink when faced with this dilemma, since all these enabling features are readily available.
          I have figured out how to do it normally, but I don't do it often enough for the method to entrench itself, so I invented this method. After all, laziness is the father of invention.
          Rod
          "To every unsung hero in the universe
          To those who roam the skies and those who roam the earth
          To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

          Comment


          • #6
            Originally posted by James McNab View Post
            Thanks both Jose and Borje. (sorry Jose and can't figure out how to do the mark over the e).
            Alt +0233

            I keep this list as a minimised ATNotes note on my desktop;

            Alt Keys
            ° 0176

            £ 156
            € 0128
            ¥ 0165

            © 0169
            ® 0174
            ™ 0153

            ‰ 0137
            ÷ 0247
            ± 241
            ² 0178 / 253
            ³ 0179
            ½ 171 / 0189
            ¼ 172 /0188
            ¾ 0190

            ¿ 168
            ñ 0241/164
            Ñ 0209/165

            é 0233
            É 0201

            Comment


            • #7
              Windows key + R (Run), type charmap and press enter for quick and easy acess to all characters, even unicode above ANSI table.

              Comment


              • #8
                Rodney, thanks for the unlink, didn't know about that.

                Stuart, thanks.

                Borje, I feel silly that I didn't think of that.

                José, the value of your input to PB is incalculable.

                Comment

                Working...
                X