【问题标题】:Size of controls when minimized (GetWindowPlacement)最小化时控件的大小 (GetWindowPlacement)
【发布时间】:2011-08-16 09:56:37
【问题描述】:

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

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

【问题讨论】:

    标签: c# .net winforms winapi


    【解决方案1】:

    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

    【讨论】:

    • 也许我的问题不清楚。这不是我想要的。我试着改写我的问题
    • 你尝试了什么,结果在哪里?
    • 我尝试了一个控件,结果是 l:-31966, r:-31966, t:-31686, b:-31686 => 这意味着宽度和高度都是 0。你通过了控件的句柄还是窗口的句柄?
    • 控件。在您的情况下,如果窗口在最小化时更改布局,则控件的宽度和高度可能为零。
    • 嗯,这很奇怪。稍后我将在测试应用程序中验证这一点。谢谢。
    【解决方案2】:

    GetWindowRect 呢?它为您提供位置和大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多