C# Winfrom项目,怎么实现用API.SetWindowPos方法设置固定位置后,能够正常的将打开的第三方的应用程序嵌入到Panel控件中
C# Winfrom项目,如何实现用API.SetWindowPos方法设置固定位置后,能够正常的将打开的第三方的应用程序嵌入到Panel控件中。
在C# Winfrom项目中,有一个form窗体,一个panel控件.
通过Process.start方法打开第三方的应用程序,将第三方程序嵌入Panel控件中。
用API.SetWindowPos方法改变第三方的应用程序位置以及大小。
目前发现一个问题,
打开第三方的应用程序设置大小及位置,通过获取panel控件的位置可以显示嵌入到Panel控件中,代码如下:
API.SetWindowPos(ptravayaWnd, IntPtr.Zero, this.panel1.Location.X, this.panel1.Location.Y, 956, 536, 0);
API.SetParent(ptravayaWnd, this.panel1.Handle);
打开第三方的应用程序设置大小及位置,通过获设置固定的位置无法显示嵌入到Panel控件中,代码如下:
API.SetWindowPos(ptravayaWnd, IntPtr.Zero,650,0, 956, 536, 0);//设置位置为:650,0 无法显示打开第三方的应用程序嵌入到Panel控件中
API.SetParent(ptravayaWnd, this.panel1.Handle);
请问如何实现用API.SetWindowPos方法设置固定位置后,能够正常的将打开的第三方的应用程序嵌入到Panel控件中。
------解决思路----------------------
先看下取的窗口句柄对了没
SetParent msdn最下面有个备注,就是设置前要移除目标窗口风格,WS_POPUP,并设置WS_CHILD
不知道是否跟这个有关,之前写过了个玩
------解决思路----------------------
窗口当然是会受到Z-order影响的
你可以试试先SetParent,然后SetWindowPos
在C# Winfrom项目中,有一个form窗体,一个panel控件.
通过Process.start方法打开第三方的应用程序,将第三方程序嵌入Panel控件中。
用API.SetWindowPos方法改变第三方的应用程序位置以及大小。
目前发现一个问题,
打开第三方的应用程序设置大小及位置,通过获取panel控件的位置可以显示嵌入到Panel控件中,代码如下:
API.SetWindowPos(ptravayaWnd, IntPtr.Zero, this.panel1.Location.X, this.panel1.Location.Y, 956, 536, 0);
API.SetParent(ptravayaWnd, this.panel1.Handle);
打开第三方的应用程序设置大小及位置,通过获设置固定的位置无法显示嵌入到Panel控件中,代码如下:
API.SetWindowPos(ptravayaWnd, IntPtr.Zero,650,0, 956, 536, 0);//设置位置为:650,0 无法显示打开第三方的应用程序嵌入到Panel控件中
API.SetParent(ptravayaWnd, this.panel1.Handle);
请问如何实现用API.SetWindowPos方法设置固定位置后,能够正常的将打开的第三方的应用程序嵌入到Panel控件中。
------解决思路----------------------
先看下取的窗口句柄对了没
SetParent msdn最下面有个备注,就是设置前要移除目标窗口风格,WS_POPUP,并设置WS_CHILD
不知道是否跟这个有关,之前写过了个玩
public const long WS_CHILD = 0x40000000L, WS_POPUP = 0x80000000L;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
public static extern long GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern long SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);
public static void RemoveWindowStyle(IntPtr hwnd, long styles)
{
styles = GetWindowLong(hwnd, GWL_STYLE) & ~styles;
SetWindowLong(hwnd, GWL_STYLE, styles);
}
public static void AddWindowStyle(IntPtr hwnd, long styles)
{
styles = GetWindowLong(hwnd, GWL_STYLE)
------解决思路----------------------
styles;
SetWindowLong(hwnd, GWL_STYLE, styles);
}
public static void SafeSetParent(IntPtr hChildWnd, IntPtr hNewParent)
{
//移除父窗口
if (hNewParent == IntPtr.Zero)
{
SetParent(hChildWnd, hNewParent);
RemoveWindowStyle(hChildWnd, WS_CHILD);
AddWindowStyle(hChildWnd, WS_POPUP);
}
//设置父窗口
else
{
RemoveWindowStyle(hChildWnd, WS_POPUP);
AddWindowStyle(hChildWnd, WS_CHILD);
SetParent(hChildWnd, hNewParent);
}
}
------解决思路----------------------
窗口当然是会受到Z-order影响的
你可以试试先SetParent,然后SetWindowPos