c# - Forms from other threads are not brought to front -
i have bunch of forms, created main thread , other threads.
suppose open these forms on screen. if open window on top of them (eg. google chrome) , click on application in windows bar, forms created main thread brought front. need have of them in front, without giving them focus.
this appears windows bug found out.
the following work-around works bringing windows front:
private const int wm_windowposchanging = 0x0046; protected override void wndproc(ref message m) { switch (m.msg) { case wm_windowposchanging: if (control.fromhandle(m.lparam) == null) { var openforms = this.getopenforms(); foreach (var openform in openforms) { showinactive(openform, true); } } break; } base.wndproc(ref m); }
where getopenforms() returns list of forms opened application. showinactive(...) function defined below:
private static void showinactive(form frm, bool topmost) { if (frm.invokerequired) { frm.invoke(new methodinvoker(() => showinactive(frm, topmost))); return; } const int swp_showwindow = 0x0040; const int swp_nosize = 0x0001; const int swp_nomove = 0x0002; user32.setwindowpos( frm.handle.toint32(), topmost ? user32.hwnd_topmost : user32.hwnd_notopmost, 0, 0, 0, 0, user32.swp_noactivate | swp_nomove | swp_nosize | swp_showwindow); }
i tested approach , seems working fine if other windows on top of mine. however, after having positioned windows on top, should override topmost
property false
not remain forever.
basically, need call showinactive(frm, false)
each form in list. question , when (could not find event telling me forms have had z-order changed or 1 guarantee me that).
i appreciate help! thanks!
Comments
Post a Comment