|
在C# Winfrom项目中,有一个form窗体,一个panel控件. 目前发现一个问题, 打开第三方的应用程序设置大小及位置,通过获设置固定的位置无法显示嵌入到Panel控件中,代码如下: 请问如何实现用API.SetWindowPos方法设置固定位置后,能够正常的将打开的第三方的应用程序嵌入到Panel控件中。 |
|
| 15分 |
先看下取的窗口句柄对了没
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);
}
}
|
|
还有没有其它的解决办法?
|
|
|
是不是要设置下层级,设置固定位置会不会被panel控件遮挡住?
请各位帮忙看看,谢谢。 |
|
| 5分 |
窗口当然是会受到Z-order影响的
你可以试试先SetParent,然后SetWindowPos |
|
那如果窗口是受到Z-order影响的,那下面设置固定位置的代码应该怎么修改。谢谢! |
|
|
没人知道吗?
|
|