Announcement

Collapse
No announcement yet.

Show tooltip of a different control on demand

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

  • Show tooltip of a different control on demand

    I want to force users to fill in required fields before filling in fields that depend on the required fields. I can show and hide of course to get this effect but was wondering if I can just use the tooltip of the required control when someone clicks on another field before it is time.

    In superclassed controls I can trap wm_killfocus and validate the data and prevent moving to another control from getting focus. What I would like to do is to popup the tooltip of the required control when the user clicks any other control on the form in an attempt to set focus to a control other than the required one. Is this possible?

    The only way I can think of at the moment is to programmatically move the mouse to hover over the required control and let 'that' popup the tooltip.

    I'll have the handle at the point of time that I want to do this so I could get the ctrlid and the location, convert to pixel coordinates and move the mouse. Seems like a lot of work.

    I tried the ShowBallonText sample for on demand balloon style help popups but it didn't work well on my gradient screen and eventually gpf'd.

    Bob Mechler

  • #2
    Originally posted by BOB MECHLER View Post
    ...was wondering if I can just use the tooltip of the required control when someone clicks on another field before it is time.
    this might help http://www.powerbasic.com/support/pb...ight=createtip

    Comment


    • #3
      Bob,
      Until I can find to use the tips from Chris, here is a lil gift for you.

      (Chris, a quick look (not fully checked out yet) shows me that you may solve a problem I have with a similar idea that my instructions are not on the window that needs to be dealt with depending on the requirements for tooltips to work on an OS that is)

      I would like to give credit where credit is due, but honestly I lost track of where I got this tidbit of code (that obviously I am in the midst of working on to do what I want but)

      Mouse.inc
      Code:
      FUNCTION LeftButtonPressed() AS LONG
          ON ERROR GOTO ErrHandler
          DIM ButtonState AS LONG
          ButtonState = (GetAsyncKeyState(%vbKeyLButton) AND &H8000)
          SELECT CASE ButtonState
              CASE %False
                  ButtonState = %False
              CASE ELSE
                  ButtonState = %True
          END SELECT
          FUNCTION = ButtonState
          EXIT FUNCTION
      ErrHandler:
          StartTrace
          ErrorCheck ERR
          EndTrace
      END FUNCTION
      
      FUNCTION RightButtonPressed() AS LONG
          ON ERROR GOTO ErrHandler
          DIM ButtonState AS LONG
          ButtonState = (GetAsyncKeyState(%vbKeyRButton) AND &H8000)
          SELECT CASE ButtonState
              CASE %False
                  ButtonState = %False
              CASE ELSE
                  ButtonState = %True
          END SELECT
          FUNCTION = ButtonState
          EXIT FUNCTION
      ErrHandler:
          StartTrace
          ErrorCheck ERR
          EndTrace
      END FUNCTION
      
      FUNCTION MiddleButton() AS LONG
          ON ERROR GOTO ErrHandler
          DIM ButtonState AS LONG
          ButtonState = (GetAsyncKeyState(%vbKeyMButton) AND &H8000)
          SELECT CASE ButtonState
              CASE %False
                  ButtonState = %False
              CASE ELSE
                  ButtonState = %True
          END SELECT
          FUNCTION = ButtonState
          EXIT FUNCTION
      ErrHandler:
          StartTrace
          ErrorCheck ERR
          EndTrace
      END FUNCTION
      
      SUB MoveMouseToControl (hWnd AS LONG)
          ON ERROR GOTO ErrHandler
          %tmr = 250 ' 0.25 sec
          %ii_min = 10 ' 0.5 sec
          %ii_max = 40 ' 2 sec
          %ii_ave = 20 ' 1 sec
          EnableWindow GetParent(hWnd), %False
          LOCAL rc AS RECT, pt1 AS POINTAPI, pt2 AS PointApi, MovingPt AS PointApi
          LOCAL i AS LONG, ii AS LONG, dx AS LONG, dy AS LONG
          LOCAL p AS PointApi
          GetWindowRect hWnd, rc              'Get position of control
          GetCursorPos pt1                    'Get current position
      '    dx = 0.5 * (rc.nLeft + rc.nRight) - pt1.x                   'Get distance in x to go
      '    dy = 0.5 * (rc.nTop + rc.nBottom) - pt1.y                   'Get distance in y to go
          p.x = rc.nLeft
          p.y = rc.nTop
          ScreenToClient HwndMain, p
      '    MSGBOX STR$(p.x) + $CR + STR$(p.y)
          dx = 0.5 * (rc.nLeft + rc.nRight) - pt1.x                   'Get distance in x to go
          dy = 0.5 * (rc.nTop + rc.nBottom) - pt1.y                   'Get distance in y to go
      'msgbox str$(dy)
      '    dx = dx - (30)
      '    dy = dy - (85)
      'msgbox str$(dy)
      'MSGBOX "Top = " + STR$(rc.nTop) + $CR + "Bottom = " + STR$(rc.nBottom) + $CR + "From = " + STR$(pt1.y) + $cr + "Distance = " + str$(dy)
          ii = MAX(GetSystemMetrics(%SM_CXSCREEN) / %ii_ave / dx, _
          GetSystemMetrics(%SM_CYSCREEN) / %ii_ave / dy)
      'MSGBOX "Max = " + STR$(ii)
          ii = MIN(ii, %ii_max)
      'MSGBOX "Min = " + STR$(ii)
          ii = MAX(ii, %ii_min)
      'MSGBOX "Max = " + STR$(ii)
          FOR i = 1 TO ii
              pt2.x = pt1.x + i * dx / ii
              pt2.y = pt1.y + i * dy / ii
      'MSGBOX STR$(pt1.x) + "," + STR$(pt1.y) + $CR + STR$(pt2.x) + "," + STR$(pt2.y) + $CR + STR$(dx) + "," + STR$(dy) +$CR + STR$(ii)
              SetCursorPos pt2.x, pt2.y
              SLEEP 40
          NEXT
      
      '    SendMessage hwnd, %BM_SETSTATE, 1, 0: SLEEP %tmr
      '    PostMessage hWnd, %BM_SETSTATE, 0, 0
      '    PostMessage hWnd, %BM_CLICK, 0, 0
      '    FOR i = ii TO 0 STEP -1
      '        pt2.x = pt1.x + i * dx / ii
      '        pt2.y = pt1.y + i * dy / ii
      '        SetCursorPos pt2.x, pt2.y
      '        SLEEP 40
      '    NEXT
      '    SetCursorPos pt1.x, pt1.y
          EnableWindow GetParent(hWnd), %True
          EXIT SUB
      ErrHandler:
          StartTrace
          ErrorCheck ERR
          EndTrace
      END SUB
      
      FUNCTION IsMouseOverControl(hWnd AS LONG)AS LONG
          ON ERROR GOTO ErrHandler
           LOCAL p AS PointApi
           LOCAL R AS Rect
           GetCursorPos(p)
           GetWindowRect hWnd, R
           SELECT CASE p.x
                CASE R.nLeft TO R.nRight
                     SELECT CASE p.y
                          CASE R.nTop TO R.nBottom
                               FUNCTION = %TRUE
                          CASE ELSE
                               FUNCTION = %FALSE
                     END SELECT
                CASE ELSE
                     FUNCTION = %FALSE
           END SELECT
          EXIT FUNCTION
      ErrHandler:
          StartTrace
          ErrorCheck ERR
          EndTrace
      END FUNCTION
      Bob, if you combine this with what Chris posted, I am sure you will get what you need...(and if you beat me to the punch, I would appreciate if you post the inc (or multiple inc's) in the source code forum

      Dang...now that I offered the code, it looks like a space-race challenge
      Game ONNnnnnnn
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        In my SuperClassed control that has focus but is not yet valid I put this code to force it to stay in the control and move the cursor over the left part of the control which triggers the previously defined tooltip when the user attemps to click in any other field.

        Learned some TTM_SETDELAYTIME AND TTS_BALLOON tips, much appreciated.



        Code:
                 CASE %WM_KILLFOCUS 
                   Tlen = GetWindowTextLength(CBHNDL) 'get the text length
                   IF Tlen < FieldLen(ActnrID&) THEN
                     SetFocus CBHNDL 
                     DIALOG GET SIZE GetParent(CBHNDL) TO tot_x&,tot_y&
                     DIALOG GET CLIENT GetParent(CBHNDL) TO cli_x&,cli_y&
                     DIALOG UNITS GetParent(CBHNDL),tot_x& - cli_x&,tot_y& - cli_y& TO PIXELS non_client_x&,non_client_y&
                     DIALOG GET LOC GetParent(CBHNDL) TO MOUSE_X&,MOUSE_Y&
                     DIALOG UNITS GetParent(CBHNDL), MOUSE_X&,MOUSE_Y& TO PIXELS P_MOUSE_X&,P_MOUSE_Y&
                     CONTROL GET LOC GetParent(CBHNDL),ActnrID& TO TV_X&,TV_Y&
                     DIALOG UNITS GetParent(CBHNDL), TV_X&,TV_Y& TO PIXELS P_TV_X&,P_TV_Y&
                     SetCursorPos P_MOUSE_X& + P_TV_X& + 10, P_MOUSE_Y& + P_TV_Y& + non_client_y& + 9
                     
                     EXIT FUNCTION 'stay in field until there is a valid account
                   END IF
        Bob Mechler

        Comment


        • #5
          Well, I guess this method might be appropriate in this case, but the mouse does
          not have to be anywhere near an object in order to force a tooltip to be displayed
          over or near the object. It seems to me that a tracking tooltip with absolute positioning
          is a better option.
          Dominic Mitchell
          Phoenix Visual Designer
          http://www.phnxthunder.com

          Comment


          • #6
            Thanks Dominic. What I came up with was based on what I know, which isn't much about tooltips. It's a sledgehammer approach I used once before to position the cursor over the last selected item in a treeview when a menu program was run after returning from a called program.

            I'm not satisfied with this method.

            I'd actually like to have two or three tooltips per control, some to be called when the mouse hovers over the control and others on demand to point attention to a problem in the field contents, either with allowed characters or logical content based on the value of other fields. (Ex. some transaction codes would be inappropriate for certain types of financial transactions etc)

            Tooltips seem like a built in way to do this.

            The other option for tooltips might be a form level validation that would run through a check list and popup a demand tooltip until all information on a form was valid for the field and for the function of the transaction.

            I tried to use Semen's ShowBallonText example as a substitute but it gpf'd when called in the wm_killfocus event. It worked fine though in other events where I would move focus from one field to another using Up,Down,Tab,Shift-Tab and Return.

            Bob Mechler

            Comment


            • #7
              Code:
              FUNCTION IsMouseOverControl(hWnd AS LONG)AS LONG
                  ON ERROR GOTO ErrHandler
                   LOCAL p AS PointApi
                   LOCAL R AS Rect
                   GetCursorPos(p)
                   GetWindowRect hWnd, R
                   SELECT CASE p.x
                        CASE R.nLeft TO R.nRight
                             SELECT CASE p.y
                                  CASE R.nTop TO R.nBottom
                                       FUNCTION = %TRUE
              .....
              =>
              Code:
              FUNCTION IsMouseOverControl(hWnd AS LONG)AS LONG
                   LOCAL p AS PointApi
                   LOCAL R AS Rect
              
                   GetCursorPos (p)
                   GetWindowRect hWnd, R
                   FUNCTION =  PtInRect (R, pt.x, pt.y)
              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Not to hijack, but maybe a possible cause of GPF (I have not had a chance to test yet but....)

                Just before end of day, I had a user come to me about "Getting rid of ALLLLlll these dialog boxes"???? So I thought to myself I better go look because they could not explain it.

                I went and looked, and only 2 programs open, so I had them show me where these "Dialog Boxes" were????

                I watched and they kept looking back as if to show me...and I finally asked, "Did you mean the yellow box that shows up if the mouse sits still a moment or two??"

                The reply was yes.....and how to get rid of it??!?!?!?! (Their computer at home they just disable it......as it turns out its a MAC)

                Anyways, I figured out a registry key to turn off tooltips....but now wondering, if tooltips are turned off (for whatever reason) If it would cause a GPF? or just not do anything when you purposely coded in routines to show tooltips?

                Just a thought
                Engineer's Motto: If it aint broke take it apart and fix it

                "If at 1st you don't succeed... call it version 1.0"

                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                Comment


                • #9
                  I'd actually like to have two or three tooltips per control, some to be called when the mouse hovers over the control and others on demand to point attention to a problem in the field contents

                  TTM_UPDATETIPTEXT

                  TTM_UPDATE

                  WM_NOTIFY/TTN_GETDISPINFO (req Toolinfo.lpszText = %LPSTR_TEXTCALLBACK)
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X