Announcement

Collapse
No announcement yet.

GetClientRect, rc.nLeft, rc.nTop

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

  • GetClientRect, rc.nLeft, rc.nTop

    Guys --
    WS_CHILD window. In which cases rc.nLeft and rc.nTop <> 0 ?
    This question worries me, because I build regions and, as I understand, should operate with GetWindowRect
    (0 .. rc.nRight - rc.nLeft, 0 .. rc.nBottom - rc.nTop, where rc is a result of GetWindowRect)

    ------------------
    E-MAIL: [email protected]

  • #2
    Never seen anything but 0, 0 with GetClientRect. Waistful implementation,
    IMO. Left and top position on parent would have been far more useful there.
    GetWindowRect() together with MapWindowPoints() maybe?


    ------------------

    Comment


    • #3
      Semen (I am sure you know most of this, but for the sake of lurkers);

      GetClientRect always returns 0,0 for .nLeft and .nTop !

      Only GetWindowRect returns non zero values for those elements !

      Each function is very important in their own right.

      GetClientRect returns coordinates which are unique the the window
      which is why the .nLeft and .nRight members are always zero.

      GetWindowRect returns values which are Screen coordinates, which
      means they can't be used Directly with the GDI to draw unless
      you use the desktops DC.

      I find that GetClientRect is the most useful for most drawing
      functions.

      GetWindowRect is more useful for finding the overall location of
      a window and possibly moving or sizing it.

      The ScreenToClient and ClientToScreen functions are very important
      for conversion back and forth between them.




      ------------------
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"
      http://cwsof.com
      http://twitter.com/EZGUIProGuy

      Comment


      • #4
        As far as Regions, you can use GetClientRect !

        I have a custom control which is a Drag Handle control which uses
        Regions and I use GetClientRect for building the Regions.



        ------------------
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          Chris,

          I'm sure you and Semen don't need this, but as we're on the subject, I find this little function quite useful -
          Code:
          sub GetRelativeRect( byval hParent as long, byval hChild as long, byref rResult as RECT )
          
            'Purpose : For window <hChild>, determines its RECT relative to the client area of <hParent>.
            '
            'Returns : Byref <rResult> receives the result
            '
            'Remarks : The results hold good even when the two windows aren't related or don't overlap. 
            '          Parent / child is simply the anticipated usage.
            '
            '          Note that this is NOT the same as calling GetWindowRect for the pair, then obtaining
            '          a relative rectangle with SubtractRect.
            '
            local rParent as RECT
            local rChild  as RECT
            local p       as POINTAPI
          	
            'Measure the child's rectangle in screen co-ordinates...
            GetWindowRect hChild, rChild
          	
            'Convert the top-left corner to the parent's client co-ordinates...
            p.x = rChild.nLeft
            p.y = rChild.nTop
            ScreenToClient hParent, p	
            rResult.nLeft = p.x
            rResult.nTop  = p.y
          	
            'And the bottom-right corner...
            p.x = rChild.nRight
            p.y = rChild.nBottom
            ScreenToClient hParent, p	
            rResult.nRight  = p.x
            rResult.nBottom = p.y
          
          end sub
          Cheers -

          Paul
          Zippety Software, Home of the Lynx Project Explorer
          http://www.zippety.net
          My e-mail

          Comment


          • #6
            Chris --
            1) rc.nLeft / rc.nTop <> 0
            I asked, because, as I remember, somebody told that this can happend, if OS supports two monitors (not very actual case).
            But if nobody know another variant, it's good.

            2) Regions and non-client area.
            For top-level windows all area is under region's control. It's visible.
            Code:
            #Compile Exe
            #Register None
            #Dim all
            #Include "WIN32API.INC"
            
            Function PbMain () As Long
              Dim hDlg   As Long, rc As RECT, hRgn As Long, Pt(1:4) As POINTAPI
              Dialog New 0, "Test", ,, 200, 150, %WS_SYSMENU, 0 To hDlg
              GetWindowRect hDlg, rc
              pt(1).x = 0: pt(1).y = 0
              pt(2).x = (rc.nRight - rc.nLeft) / 2:  pt(2).y = (rc.nBottom - rc.nTop)
              pt(3).x = (rc.nRight - rc.nLeft): pt(3).y = 0
              
              hRgn = CreatePolygonRgn(Pt(1), 3, %ALTERNATE)
              SetWindowRgn hDlg, hRgn, 1
              Dialog Show Modal hDlg
            
            End Function
            Child windows ... Imagine WS_BORDER or %WS_EX_CLIENTEDGE.
            As I understand, borders belong to non-client area. Is it so ?
            If so, there are any documents, which confirm that for regions (0,0) is the same point as (0,0) for client area ?

            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              In the past few days I finally got my Matrox G450 dualhead card running, so I now have multiple desktops (although the latest drivers are pretty buggy and unstable it is working after a fashion).

              Anyway, I'm interested in this topic. Sem,en, can you be more specific about the multiple desktop situation? I'm willing to run a few test apps for you if you wish.

              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:la[email protected]

              Comment


              • #8
                Lance --
                Unf. I have no multiply monitors and can't test.
                I remember only a phrase, something "it's not safety to assume that rc.nLeft = 0 ...".
                Which OS ? Why ? - no idea. ("one woman said")

                So, pls, simply test ClientRect for child windows, located on secondary monitor.




                ------------------
                E-MAIL: [email protected]

                Comment


                • #9
                  Originally posted by Semen Matusovski:
                  Lance --
                  Unf. I have no multiply monitors and can't test.
                  I remember only a phrase, something "it's not safety to assume that rc.nLeft = 0 ...".
                  Which OS ? Why ? - no idea. ("one woman said")

                  So, pls, simply test ClientRect for child windows, located on secondary monitor.
                  I might have been that person, I corrected the post some time ago.

                  AFAIK (and according to MSDN) GetClientRect always returns (0,0) for upper left corner.
                  If you post runnable code that you want tested on a dual monitor setup, I can do that too.




                  ------------------
                  Best Regards
                  Peter Scheutz
                  Best Regards
                  Peter Scheutz

                  Comment


                  • #10
                    Peter --

                    About MSDN ...

                    From one side,
                    The GetClientRect function retrieves the coordinates of a window's client area.
                    The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).
                    From another side, in samples
                    Code:
                       ' Get the dimensions of the client area.
                       r = GetClientRect(hWnd_SrcWindow, RectClient)
                       Client_Width = Abs(RectClient.Right - RectClient.Left)
                       Client_Height = Abs(RectClient.Bottom - RectClient.Top)
                    or
                    Code:
                    GetClientRect(hwnd, &r); 
                    TextOut(hdc, r.left, r.top, "Defenestration can be hazardous", 4);
                    A test can be enough simple
                    Code:
                    #Compile Exe
                    #Register None
                    #Dim All
                    #Include "WIN32API.INC"
                    
                    CallBack Function TestProc
                      Dim rc As Rect, i As Static Long
                      GetClientRect GetDlgItem(CbHndl, %IDOK), rc
                      Incr i
                      If rc.nLeft <> 0 Or rc.nTop <> 0 Then MsgBox "Ah" Else SetWindowText CbHndl, "Ok" + Str$(i)
                    End Function
                    
                    Function PbMain () As Long
                      Dim hDlg   As Long
                      Dialog New 0, "Test", ,, 70, 50, %WS_SYSMENU, 0 To hDlg
                      Control Add Button, hDlg, %IDOK, "Test", 10, 10, 50, 14 Call TestProc
                      Dialog Show Modal hDlg
                    End Function
                    Hope, it's never say "Oh", even you will move it to secondary monitor.

                    Guys --
                    what about regions ? I mean non-client area for WS_CHILD.
                    (0,0) for region is (0,0) for client area or left-upper point (in non-client area) ?

                    [This message has been edited by Semen Matusovski (edited April 26, 2001).]

                    Comment

                    Working...
                    X