我想有一些user32.dll调用我可以用来验证窗口是否是MDI窗口,比如使用DefMDIChildProc并查看它是否失败,但我想知道是否有任何限制,或者是否有更好的方法去做这个?检查父母是否足够?
为了简单起见,我最终希望的是一种IsMDI(IntPtr ptr)的呼叫......
思考?建议?
答案 0 :(得分:4)
我已经弄明白了(在pinvoke.net的帮助下) - 您可以根据扩展的Windows样式找到答案:
public static bool IsMDI(IntPtr hwnd)
{
WINDOWINFO info = new WINDOWINFO();
info.cbSize = (uint)Marshal.SizeOf(info);
GetWindowInfo(hwnd, ref info);
//0x00000040L is the style for WS_EX_MDICHILD
return (info.dwExStyle & 0x00000040L)==1;
}
[StructLayout(LayoutKind.Sequential)]
private struct WINDOWINFO
{
public uint cbSize;
public RECT rcWindow;
public RECT rcClient;
public uint dwStyle;
public uint dwExStyle;
public uint dwWindowStatus;
public uint cxWindowBorders;
public uint cyWindowBorders;
public ushort atomWindowType;
public ushort wCreatorVersion;
public WINDOWINFO(Boolean? filler)
: this() // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
{
cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));
}
}
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
答案 1 :(得分:2)
如果控件位于您自己的.NET应用程序中,Form class具有使用MDI窗口的属性: