Today a third-party program is made with a WPF program that supports the integration of a third-party program through a menu extension that looks like a popup dialog box.
However, because the new WPF program and the original program is not any relationship, once the original program regain focus, the new WPF program window will switch to the background, it does not look like a child window . Look at the previous people's practice, most of the new pop-up window set to topmost, but then introduced to the window can not switch to the background hidden problems.
Search on the Internet, found the following solution: Http://stackoverflow.com/questions/2599053/how-to-set-win32-window-as-owner-of-wpf-window. Specifically, the external window is set to owner through Windowinterophelper.
???? var helper = newwindowinterophelper(Mywpfchildwindow);
???? helper->Owner = mainwindowhwnd;
This does solve the problem, but in turn, if you want the external window to be a child window of WPF, you cannot use this method. Because the WPF program itself is called WindowsAPI, WINDOWSAPI is to support two unrelated windows of the parent-child relationship settings, and then looked at the Referencesource on the source code, with the following:
Unsafenativemethods.setwindowlong (new HandleRef (null, CriticalHandle),
???????????????? NativeMethods. gwl_hwndparent,????
???????????????? _ownerhandle);
In other words, it calls API SetWindowLong:
???? LONG WINAPI SetWindowLong (
???? _in_ HWND hwnd,
???? _in_ int NIndex,
???? _in_ LONG Dwnewlong
????);
It has three parameters, the first parameter passes into the child window handle, the second parameter passes into the Gwl_hwndparent, and the third passes in the parent window handle. However, MSDN also says that it is not recommended to use this approach to set up parent-child relationships, but with setparent. I tried, in this way can, instead of using setparent, since Microsoft is in use, for the first use, the follow-up found there are problems to add the explanation.
Set windows for two different processes to parent-child relationships