VC implementation of A process window embedded in the B process window display method

  • 2020-04-02 02:27:10
  • OfStack

This article USES A Demo example to show you how to embed application A into application B for display.

The main code is as follows:

//Create A process when the B application starts
HWND hWndChild = FindWindow(_T("AAA"),_T("AAA"));
  hWndChild = FindWindow(_T("AAA"),_T("AAA"));
//Move the A process window position
//A process window is embedded in B process window

An application can use the SetParent function to set the parent window of a pop-up, overlapped, or child window. The new parent window and the child window must belong to the same application.
This is A description of the use of SetParent in MSDN. It says that the window to be embedded by SetParent must belong to the same application as the window to be embedded, which is not the case. However, SetParent does return A Null, because the window in A process does not have A parent window, and SetParent will return the handle of the parent window after calling SetParent, so it returns Null. However, it does not affect A process window embedding.

In the WM_ACTIVE received when the B process window is displayed, WA_ACTIVE or WA_CLICKACTIVE is received first, and then the WA_INACTIVE parameter is also received. That is, at some point, the B process is not set to the front window, which should affect the B process window when SetParent is called. If you want the B process window to receive the WM_ACTIVE message, you must call setgroundwindow (hWnd). If the current window is not the most active window, you will not receive WA_INACTIVE in the WM_ACTIVE message when exiting or minimizing. Keep that in mind, especially when you're doing nested applications.

In addition to that, When you use SetParent(hWndChild,hWnd) to put A process into A B process window, you use FindWindow to find that the window handle of A process is null.

Related articles: