Why does not clicking on the child window always bring the application to the forefront?

When the application is behind other applications and I click on the application taskbar icon, I expect the entire application to go to the beginning of the z-order, even if the WS_POPUP modal dialog box application is open.

However, for some time, for some of my (and other) dialogs, only the dialog is displayed; the rest of the application is left behind.

I looked at Spy ++ and for those who work correctly, I see WM_WINDOWPOSCHANGING being sent to the parent dialog. For those who leave the rest of the application behind, WM_WINDOWPOSCHANGING is not sent to the parent dialog box.

I have an example where one dialogue usually brings the whole application with it, and the other does not. Both the working dialog and the non-working dialog have the same window style, stand, parent, owner, ontogenesis.

In short, both WS_POPUPWINDOW windows are created using DialogBoxParam (), going into identical HWNDs as the third argument.

Has anyone else noticed this behavioral oddity in Windows programs? What messages does the TaskBar send to the application when I click the button? Who is responsible for ensuring that all application windows come to the fore?

In my case, the base origin is an MDI frame ... somehow this factor?

+5
source share
3 answers

, , , .

, ( ), , , .

, , . .

API Win32 :

INT_PTR DialogBox(
    HINSTANCE hInstance,
    LPCTSTR lpTemplate,
    HWND hWndParent,      /* this is the owner */
    DLGPROC lpDialogFunc
);

int MessageBox(
    HWND hWnd,            /* this is the owner */
    LPCTSTR lpText,
    LPCTSTR lpCaption,
    UINT uType
);

Similary, .NET WinForms, :

public DialogResult ShowDialog(
    IWin32Window owner
)

public static DialogResult Show(
    IWin32Window owner,
    string text
) /* ...and other overloads that include this first parameter */

, WinForms :

public void Show(
    IWin32Window owner,
)

, :

form.Owner = this;
form.Show();

WinAPI :

HWND CreateWindow(
    LPCTSTR lpClassName,
    LPCTSTR lpWindowName,
    DWORD dwStyle,
    int x,
    int y,
    int nWidth,
    int nHeight,
    HWND hWndParent, /* this is the owner if dwStyle does not contain WS_CHILD */
    HMENU hMenu,
    HINSTANCE hInstance,
    LPVOID lpParam
);

:

SetWindowLong(hWndPopup, GWL_HWNDPARENT, (LONG)hWndOwner);

(64- )

SetWindowLongPtr(hWndPopup, GWLP_HWNDPARENT, (LONG_PTR)hWndOwner);

, MSDN : SetWindowLong [Ptr]:

SetWindowLongPtr GWLP_HWNDPARENT, . SetParent.

, , -, , . . SetParent ( WS_CHILD), . - .

+4

Windows WM_ACTIVATE.

, WM_ACTIVATE DefWindowProc ?

+1

?

, , Windows Forms . , , , , -. , .

, !

0

All Articles