-1

我想通过其句柄检查表单是否具有表单边框。而且,句柄来自另一个应用程序。

我该如何处理?请帮助我..谢谢!

4

2 回答 2

2
[DllImport("user32.dll")]
extern static int GetWindowLong(IntPtr hWnd, int nIndex);

const int GWL_STYLE = -16;
const int WS_BORDER = 0x00800000;  // thin border
const int WS_THICKFRAME = 0x00040000;  // sizing (thick) border

public static bool NativeWindowHasBorder(IntPtr hWnd)
{
     return (GetWindowLong(hWnd, GWL_STYLE) & (WS_BORDER | WS_THICKFRAME)) != 0;
}
于 2012-07-16T22:20:31.857 回答
0

Controls 本身实际上并没有句柄。Control.Handle实际上返回它的父窗口的.Handle.

来自MSDNControl.Handle

获取控件绑定到的窗口句柄。

如果您查看反编译的源代码Control,您会看到:

internal IntPtr HandleInternal
{
  get
  {
    return this.window.Handle;
  }
}

编辑

我上面所说的完全不正确。出于历史原因,我要离开它。

Button可以通过将 a放在a 上Form并查看IntPtr Handle它们的值来很容易地证明这一点。它们是不同的。

于 2012-07-16T21:23:04.020 回答