【发布时间】:2011-08-16 09:56:37
【问题描述】:
GetWindowPlacement 似乎只能返回一个最小化的窗口的大小。
当窗口最小化时,是否可以获得该窗口内各个控件的大小?
【问题讨论】:
GetWindowPlacement 似乎只能返回一个最小化的窗口的大小。
当窗口最小化时,是否可以获得该窗口内各个控件的大小?
【问题讨论】:
WINDOWPLACEMENT.rcNormalPosition 定义为:
窗口处于恢复位置时的窗口坐标。
要获取当前大小,请使用GetWindowRect 函数。还有一个有趣的article Raymond Chen 关于这个话题。
以下程序在最小化窗口中给出了正确大小的控件:
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);
}
正确:-31948 -31335 -31923 -30761
【讨论】:
GetWindowRect 呢?它为您提供位置和大小。
【讨论】: