您的问题似乎不完整,您是想询问关于C语言编程的某个具体问题吗?比如C语言的语法、编程技巧、项目开发等。请提供更具体的信息,这样我才能给出更准确的回答。
- 内容介绍
- 文章标签
- 相关推荐
本文共计225个文字,预计阅读时间需要1分钟。
plaintext/// summary ///根据子窗口体自动获取父类窗口体,并建立父子关系/// summary ///param name=window 子窗口体public static void SetOwner(System.Windows.Window childWindow){ Action defaultSetOwner=new Action(()=> { ... });}
/// <summary>
/// 根据子窗体自动获取父类窗体,并建立父子关系
/// </summary>
/// <param name="window">子窗体</param>
public static void SetOwner(System.Windows.Window childWindow)
{
Action defaultSetOwner = new Action(() =>
{
IntPtr parentHandler = Process.GetCurrentProcess().MainWindowHandle;
SetOwner(childWindow, parentHandler);
});
try
{
var hwnd = GetForegroundWindow();
if (hwnd != null)
{
var source = HwndSource.FromHwnd(hwnd);
if (null != source)
{
///WPF窗体
var wnd = (System.Windows.Window)source.RootVisual;
childWindow.Owner = wnd;
childWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
}
else
{
///非WPF窗体
defaultSetOwner();
}
}
else
{
defaultSetOwner();
}
}
catch (Exception)
{
defaultSetOwner();
}
}
本文共计225个文字,预计阅读时间需要1分钟。
plaintext/// summary ///根据子窗口体自动获取父类窗口体,并建立父子关系/// summary ///param name=window 子窗口体public static void SetOwner(System.Windows.Window childWindow){ Action defaultSetOwner=new Action(()=> { ... });}
/// <summary>
/// 根据子窗体自动获取父类窗体,并建立父子关系
/// </summary>
/// <param name="window">子窗体</param>
public static void SetOwner(System.Windows.Window childWindow)
{
Action defaultSetOwner = new Action(() =>
{
IntPtr parentHandler = Process.GetCurrentProcess().MainWindowHandle;
SetOwner(childWindow, parentHandler);
});
try
{
var hwnd = GetForegroundWindow();
if (hwnd != null)
{
var source = HwndSource.FromHwnd(hwnd);
if (null != source)
{
///WPF窗体
var wnd = (System.Windows.Window)source.RootVisual;
childWindow.Owner = wnd;
childWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
}
else
{
///非WPF窗体
defaultSetOwner();
}
}
else
{
defaultSetOwner();
}
}
catch (Exception)
{
defaultSetOwner();
}
}

