c#调用外部程序,怎么限制它的子窗口不能移出它的范围
展开全部
用api设置窗体的parent window ,提供几个api给你 ,可以设置窗体的parent,窗体的位置,去掉窗体的边框等,用C#中的Process类可以获取外部程序的主窗体句柄(IntPtr)
public const int GWL_STYLE = -16;
//public const int WS_VISIBLE = 0x10000000;
public const int WS_CAPTION = 0x00C00000;
public const int WS_CAPTION_2 = 0x00C0000;
[DllImport("user32.dll", SetLastError = true)]
public static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("User32.dll", EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr handle, int style);
//[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
//public static extern long SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("User32.dll", EntryPoint = "SetWindowPos")]
public static extern long SetWindowPos(IntPtr hwnd, int ord, int x, int y, int dx, int dy, int uflag);
[DllImport("User32.dll")]
public static extern void SetWindowLong(IntPtr handle, int oldStyle, int newStyle);
public const int GWL_STYLE = -16;
//public const int WS_VISIBLE = 0x10000000;
public const int WS_CAPTION = 0x00C00000;
public const int WS_CAPTION_2 = 0x00C0000;
[DllImport("user32.dll", SetLastError = true)]
public static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("User32.dll", EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr handle, int style);
//[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
//public static extern long SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("User32.dll", EntryPoint = "SetWindowPos")]
public static extern long SetWindowPos(IntPtr hwnd, int ord, int x, int y, int dx, int dy, int uflag);
[DllImport("User32.dll")]
public static extern void SetWindowLong(IntPtr handle, int oldStyle, int newStyle);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询