This is code I am using to show small popup window exactly in the middle of the main form of application:
TForm_Popup::Show
{
SetBounds(Form_Main->Left + ((Form_Main->Width - Width) >> 1), Form_Main->Top + ((Form_Main->Height - Height) >> 1), Width, Height); // set window position in the center of main window
SetWindowLong(Handle, GWL_HWNDPARENT, (long)Form_Main->Handle); // popup window should be modal relative to main window of application
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); // without this the window will not be shown
ShowWindow(Handle, SW_SHOWNOACTIVATE);
Visible = true;
}
The popup window really shows without stealing focus when another top-level window is active (because of SW_SHOWNOACTIVATE flag). But if that another window is maximized by user just before calling TForm_Popup::Show, the popup window is shown on top of it which is undesirable. Could it be changed so that popup window is visible only when the corresponding area of its parent window (main window of application) is not overlapped with another top-level window ? So if main form of application is entirely behind some other window, it is not logical to see child windows of this main window.