Announcement

Collapse
No announcement yet.

ScrollWindow... Is a control visible?

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

  • ScrollWindow... Is a control visible?

    I've got a window where I use ScrollWindow and I'm curious if there's an easy way to determine if various controls on the window are viewable from the ScrollWindow's current position. My window only scrolls vertically, so I'm guessing I could check the location of the control and see if its currently in the range being displayed, but I thought IsWindowVisible (tried this, didn't work) or something similar existed for this situation (but couldn't find it).
    LOCAL MyEMail AS STRING
    MyEmail = STRREVERSE$("53pmohtj") & CHR$(64) & STRREVERSE$("liamg") & CHR$(46) & STRREVERSE$("moc")

  • #2
    Try the IntersectRect WinApi function using the client area of the screen and window rect of the control. If any areas are in common (a rect is returned) the control is at least partially visible.

    MCM

    ADDED:
    Not tested but I think it will work.

    Code:
    FUNCTION IsControlInVisibleArea (hWndparent, %ID_CONTROL) AS LONG
     LOCAL rParent AS RECT, rCtrl AS RECT, rDest AS RECT, iRet AS LONG
    
     ' Get RECT of parent Window
      GetClientRect hwndParent, rHwnd  ' client coodinates
    ' --------------------------------------------------
    ' convert client coordinates to screen coordinates
    ' --------------------------------------------------
      MapWindowPoints hWndParent, %HWND_DESKTOP, BYVAL VARPTR(rParent), BYVAL 2&  'when using RECT cPoints=2
    ' ------------------------------------------------
    ' Get screen coordinates of the Control's RECT 
    ' ------------------------------------------------
     GetWindowRect GetDlgItem (hWndParent, %ID_CONTROL), rCtrl  ' screen coordinates
     ' -------------------------------- 
     ' See if the two RECTs intersect. 
     ' -------------------------------- 
     iRet = IntersectRect (rDest, rParent, rCtrl) 
    
     FUNCTION = ISTRUE (iret)  ' if true is returned the RECTs intersect
    
    END FUNCTION
    Last edited by Michael Mattias; 20 Apr 2008, 11:43 AM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Hey John,

      for the fun of it, here is a little one using
      GetClientRect, GetWindowRect, MapWindowPoints and PtInRect.


      Code:
       
      #COMPILE EXE '#Win 8.04#
      #DIM ALL
      #INCLUDE "WIN32API.INC" '#2005-01-27#
       
      %LABEL = 200
      '______________________________________________________________________________
       
      CALLBACK FUNCTION DlgProc() AS LONG
       LOCAL si       AS SCROLLINFO
       LOCAL DlgRect  AS RECT
       LOCAL CtrlRect AS RECT
       LOCAL hControl AS DWORD
       LOCAL oldPos   AS LONG
       LOCAL WmScroll AS LONG
       LOCAL iSeeYou  AS LONG
       
       SELECT CASE CBMSG
        CASE %WM_INITDIALOG
          si.cbSize = LEN(si)
          si.fMask  = %SIF_ALL
          si.nMin   =   0
          si.nMax   = 800
          si.nPage  =  50
          si.nPos   =   0
          SetScrollInfo CBHNDL, %SB_VERT, si, 1
          SetScrollInfo CBHNDL, %SB_HORZ, si, 1 
       
        CASE %WM_HSCROLL, %WM_VSCROLL
          si.cbSize = SIZEOF(si)
          si.fMask  = %SIF_ALL
          IF CBMSG = %WM_HSCROLL THEN
            GetScrollInfo CBHNDL, %SB_HORZ, si
            oldPos = si.nPos
            SELECT CASE LOWRD(CBWPARAM)
              CASE %SB_LINELEFT   : si.nPos = si.nPos - 5
              CASE %SB_PAGELEFT   : si.nPos = si.nPos - si.nPage
              CASE %SB_LINERIGHT  : si.nPos = si.nPos + 5
              CASE %SB_PAGERIGHT  : si.nPos = si.nPos + si.nPage
              CASE %SB_THUMBTRACK : si.nPos = HIWRD(CBWPARAM)
              CASE ELSE           : EXIT FUNCTION
            END SELECT
            si.fMask = %SIF_POS
            SetScrollInfo CBHNDL, %SB_HORZ, si, 1
            ScrollWindow CBHNDL, oldPos - si.nPos, 0, BYVAL %NULL, BYVAL %NULL
          ELSE
            GetScrollInfo CBHNDL, %SB_VERT, si
            oldPos = si.nPos
            SELECT CASE LOWRD(CBWPARAM)
              CASE %SB_LINEUP     : si.nPos = si.nPos - 5
              CASE %SB_PAGEUP     : si.nPos = si.nPos - si.nPage
              CASE %SB_LINEDOWN   : si.nPos = si.nPos + 5
              CASE %SB_PAGEDOWN   : si.nPos = si.nPos + si.nPage
              CASE %SB_THUMBTRACK : si.nPos = HIWRD(CBWPARAM)
              CASE ELSE           : EXIT FUNCTION
            END SELECT
            si.fMask = %SIF_POS
            SetScrollInfo CBHNDL, %SB_VERT, si, 1
            ScrollWindow CBHNDL, 0, oldPos - si.nPos, BYVAL %NULL, BYVAL %NULL
          END IF
          FUNCTION = 1
       
          GetClientRect(CBHNDL, DlgRect)
          hControl = GetDlgItem(CBHNDL, %LABEL)
          GetWindowRect(hControl, CtrlRect)
          MapWindowPoints %HWND_DESKTOP, CBHNDL, CtrlRect, 2
       
          iSeeYou = 0
          IF PtInRect(DlgRect, CtrlRect.nLeft,  CtrlRect.nTop )   THEN INCR iSeeYou
          IF PtInRect(DlgRect, CtrlRect.nRight, CtrlRect.nTop)    THEN INCR iSeeYou
          IF PtInRect(DlgRect, CtrlRect.nLeft,  CtrlRect.nBottom) THEN INCR iSeeYou
          IF PtInRect(DlgRect, CtrlRect.nRight, CtrlRect.nBottom) THEN INCR iSeeYou
          IF iSeeYou = 4 THEN
            SetWindowText CBHNDL, "Control is fully viewable"
          ELSEIF iSeeYou = 0 THEN
            SetWindowText CBHNDL, "Control is not viewable"
          ELSE
            SetWindowText CBHNDL, "Control is partially viewable"
          END IF 
       
       END SELECT
       
      END FUNCTION
      '______________________________________________________________________________
       
      FUNCTION PBMAIN () AS LONG
       LOCAL hDlg AS DWORD
       
       DIALOG NEW %HWND_DESKTOP, "isControlViewable",,, 450, 250, _
         %WS_CAPTION OR %WS_SYSMENU OR %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX,  TO hDlg
       DIALOG SET COLOR hDlg, -1, RGB(75, 165, 125)
       SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice dialog icon
       
       CONTROL ADD LABEL, hDlg, %LABEL, "Keep scrolling !", 100, 100, 300, 200, _
         %SS_CENTER OR %SS_CENTERIMAGE, %WS_EX_LEFT
       
       CONTROL SET COLOR hDlg, %LABEL, -1, RGB(25, 125, 255)
       
       DIALOG SHOW MODAL hDlg CALL DlgProc
       
      END FUNCTION
      '______________________________________________________________________________
      '
      Last edited by Pierre Bellisle; 21 Apr 2008, 12:51 AM.

      Comment


      • #4
        Awesome! Thank you both very much. -John
        LOCAL MyEMail AS STRING
        MyEmail = STRREVERSE$("53pmohtj") & CHR$(64) & STRREVERSE$("liamg") & CHR$(46) & STRREVERSE$("moc")

        Comment


        • #5
          Code:
          GetClientRect(CBHNDL, DlgRect)
          ...
          GetWindowRect(hControl, CtrlRect)
          These lines will compile and execute in 7x, but not in anything else. The parens around the parameters are a syntax error when the CALL verb is not used. (That would be a bug in 7x which was fixed in 8x).

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Originally posted by Michael Mattias View Post
            Code:
            GetClientRect(CBHNDL, DlgRect)
            ...
            GetWindowRect(hControl, CtrlRect)
            These lines will compile and execute in 7x, but not in anything else. The parens around the parameters are a syntax error when the CALL verb is not used. (That would be a bug in 7x which was fixed in 8x).

            MCM
            Is that the right way around?

            Code:
            Call GetClientRect CBHNDL, DlgRect
            compiles in PBWin703 but not in PBWn804 (needs parens)
            Code:
            GetClientRect(CBHNDL, DlgRect)
            compiles in both as does
            Code:
            GetClientRect CBHNDL, DlgRect
            Seems the PBWin8x compiler requires parens when the Call verb is used. The bug was that the PBWin7x compiler would accept use of the Call verb without parens. Wasn't it?
            Rgds, Dave

            Comment


            • #7
              Yes, I think I said that correctly.

              Without CALL, a DECLARE is required and no parens are permitted.
              With CALL, DECLARE is not required (but is permitted) and parens are mandatory.

              The above is the "corrrect" syntax. What different versions of the compiler of the compiler do... well that's what defines bugs.

              >The bug was that the PBWin7x compiler would accept use of the Call verb without parens. Wasn't it?

              Actually two bugs..
              - Accepted parens when CALL was not used. (But it worked as though the parens weren't there)
              - This also 'worked' :
              Code:
               Value = FunctionName param, param, param
              I know the documented syntax works in all versions; so just use that.
              Last edited by Michael Mattias; 21 Apr 2008, 10:01 AM.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Ok since PBWin8x parens are mandatory with Call.
                Without CALL, a DECLARE is required and no parens are permitted.
                Yet
                Code:
                GetClientRect(CBHNDL, DlgRect)
                compiles and runs in both PBWin703 and PBWin804.
                Rgds, Dave

                Comment


                • #9
                  GetClientRect(CBHNDL, DlgRect) compiles and runs in both PBWin703 and PBWin804.
                  It shouldn't compile.

                  Well, I'll be dipped... this compiles in 8.03, too:
                  Code:
                  FUNCTION TestParens() AS LONG
                      LOCAL hWnd AS LONG, R AS RECT
                      
                      GetClientRect (hWnd, R)
                      
                  END FUNCTION
                  I could have sworn this was fixed in 8x.

                  Oh, wait a minute, the help file changed. These are all shown as valid under CALL:
                  CALL MyProc (parm1, parm2)
                  MyProc (parm1, Parm2)
                  MyProc parm1, parm2
                  Aha, I see now by doing some more RTFM:
                  This updated syntax now permits macros to be called using the SUB-style convention if/when the macros expand directly to Function calls. For example:
                  .. and here it is in the What's New section of 8.03 help file:

                  PowerBASIC now supports parentheses around parameters in calls to Subs (and functions that are being called as Subs) when the CALL keyword is omitted. For example, the following lines demonstrate valid syntax:
                  I guess it's true the memory is the second thing to go.

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Welcome in 2008.

                    Comment

                    Working...
                    X