Set windows for two different processes to parent-child relationships

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.