如何获得不包括标题栏和边框的工作区的RECT?

解决方案 »

  1.   

    Option ExplicitPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    '获取窗体结构信息函数
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const GWL_STYLE = (-16)
    Private Const WS_SYSMENU = &H80000
    Private Const WS_CAPTION = &HC00000
    Private Const WS_SIZEBOX = &H40000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    '为窗体指定一个新位置和状态函数
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Const SWP_NOZORDER = &H4
    Private Const SWP_FRAMECHANGED = &H20
    Private Const SWP_NOREPOSITION = &H200
    '获得整个窗体的大小和位置
    Private Declare Function GetWindowRect 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 TypePrivate Sub Form_Load()
        Dim lStyle As Long
        Dim MyRect As RECT
        Dim Change As Boolean
        '获取窗体的大小和位置
        GetWindowRect Me.hwnd, MyRect
        '取得当前窗体信息
        lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
        lStyle = lStyle And Not WS_SYSMENU
        lStyle = lStyle And Not WS_CAPTION
        lStyle = lStyle And Not WS_SIZEBOX
        lStyle = lStyle And Not WS_MAXIMIZEBOX
        lStyle = lStyle And Not WS_MINIMIZEBOX
        '按lStyle的值设置窗体信息
        SetWindowLong Me.hwnd, GWL_STYLE, lStyle
        '保持窗体的大小与位置不变
        SetWindowPos Me.hwnd, 0, MyRect.Left, MyRect.Top, MyRect.Right - MyRect.Left, MyRect.Bottom - MyRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
        
    End Sub
      

  2.   

    我的意思是:窗体标题栏左上角为坐标原点(就是那个图标附近)
    然后找出实际工作区的坐标,就是标题栏下边缘,左边框的右边缘的坐标
    以及右下角的那点我用GetWindowRect,但他返回的左上角是0,0
      

  3.   

    me.ScaleMode=vbPixelsRect.Left=0
    Rect.Top=0
    Rect.Right=me.ScaleWidth
    Rect.Bottom=me.Height
      

  4.   

    GetClientRect
    The GetClientRect function retrieves the coordinates of a window抯 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抯 client area, the coordinates of the upper-left corner are (0,0).VB4-32,5,6
    Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT) As Long VB.NET
    System.Windows.Forms.Form.ClientSize  Operating Systems Supported Requires Windows NT 3.1 or later; Requires Windows 95 or later 
    Library User32 
    Parameter Information ?hWnd
    Identifies the window whose client coordinates are to be retrieved.?lpRect
    Points to a RECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window. 
    Return Values If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError. 
      

  5.   

    如果问题还没有解决的话,俺给你出一个馊注意吧!!!^_^
    1、在窗体里面放一个有hWnd的控件;
    2、将控件放到窗体的左上角,也就是Left=0,Top=0,
       Width=窗体的ScaleWidth,Height=窗体的ScaleHeight;
    3、用GetWindowRect函数取出控件的RECT;
    4、得到你想要的×××了。