폼의 위치, 크기 정보를 가져오기 위해 GetWindowRectGetClientRect 를 사용합니다.

이 둘의 차이점은 

GetWindowRect 는 화면좌표를 기준으로 하여 비 클라이언트 영역(Non Client Area)을 포함한 각 면의 위치좌표를 가져오고

GetClientRect 는 컨트롤 등을 디자인하는 클라이언트 영역(Client Area)에 크기 정보만을 취득합니다.

쓰다보니 알아먹기 힘든 소리가 되어버렸는데 아래 이미지를 참고하면 이해가 될 겁니다.


     

 GetWindowRect

 

 GetClientRect



Private Declare Function GetWindowRect Lib "user32" _

                        (ByVal hwnd As Long, _

                         lpRect As RECT) As Long


Private Declare Function GetClientRect Lib "user32" _

                        (ByVal hwnd As Long, _

                         lpRect As RECT) As Long


Private Type RECT

        Left As Long

        Top As Long

        Right As Long

        Bottom As Long

End Type



Private Sub Form_Load()


  Dim WindowRect As RECT

  Dim ClientRect As RECT


  GetWindowRect Me.hwnd, WindowRect


  GetClientRect Me.hwnd, ClientRect


  Debug.Print WindowRect.Left

  Debug.Print WindowRect.Top

  Debug.Print WindowRect.Right

  Debug.Print WindowRect.Bottom


  Debug.Print ClientRect.Left

  Debug.Print ClientRect.Top

  Debug.Print ClientRect.Right

  Debug.Print ClientRect.Bottom


End Sub



약 폼안에 있는 PictureBox를 GetWindowRect 로 위치정보를 가져오면 어디를 기준으로 가져올까요?

화면 좌표 기준이니 화면내 PictureBox의 위치정보를 가져오게됩니다.

 

Tip.

프로젝트 내의 폼 크기나 위치정보를 얻기위해 굳이 API 안써도 된다고 하지만 몰라서 해될건 없으니..^^

RECT 구조체로 얻은 결과를 Form 속성과 비교하여 보면 더 이해가 쉽다.


Me.Left \ 15 = WindowRect.Left

Me.Top \ 15 = WindowRect.Top

Me.Width \ 15 = WindowRect.Right - WindowRect.Left

Me.Height \ 15 = WindowRect.Bottom - WindowRect.Top

Me.ScaleWidth \ 15 = ClientRect.Right

Me.ScaleHeight \ 15 = ClientRect.Bottom




'VB6 > Interface' 카테고리의 다른 글

폼에 보여줄 영역 만들기(구멍난 폼)  (0) 2013.03.28
폼 타이틀바 Show/Hide  (0) 2013.03.28
바탕화면 아이콘 Show/Hide  (0) 2013.03.28
폼 투명도 주기  (0) 2013.03.27
폼 타이틀바 이동효과  (0) 2013.03.26

+ Recent posts