最小化时控件的大小(GetWindowPlacement)

时间:2011-08-16 09:56:38

标签: c# .net winforms winapi

似乎GetWindowPlacement只能返回最小化窗口的大小。

当窗口最小化时,是否可以获得该窗口中单个控件的大小

2 个答案:

答案 0 :(得分:1)

WINDOWPLACEMENT。rcNormalPosition定义为:

  

窗口处于恢复位置时窗口的坐标。

要获取当前大小,请使用GetWindowRect功能。 Raymond Chen在这个主题上也有一个有趣的article

以下程序在最小化窗口中给出正确的控件大小:

using System.Runtime.InteropServices;
using System;

[StructLayout(LayoutKind.Sequential)]
struct RECT
{
     public int L;
     public int T;
     public int R;
     public int B;
}

static class Program
{
    void Main()
    {
        RECT r;
        bool result = GetWindowRect(0x00120E34, out r);
        Console.WriteLine("{0}: {1} {2} {3} {4}", r.T, r.L, r.B, r.R);
    }

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    extern bool GetWindowRect(int hwnd, out RECT lpRect);
}
  

True:-31948 -31335 -31923 -30761

答案 1 :(得分:0)

GetWindowRect怎么样?它为您提供位置和大小。