modal over modal doesn't get focus

Add-in Express™ Support Service
That's what is more important than anything else

modal over modal doesn't get focus
 
Fabrice


Guest


Hello

I just run on a problem and want to know if you know something about it.

I've added a menu item in the right click menu on an email in inbox. When selecting this menu a modal form is show.
This form contains a button. When clicking on this button a second modal form is shown.

Problem: I cannot click on this form, it doesn't receive the focus. Mouse over events works (I see the mouse over color) but no click.

But the point it that if I set the Outlook compatibility mode, then everything is working.

Both form are opened using ".ShowDialog()", and the strange thing is that I've other case with "double modal" that works perfectly.

Do you know anything about this problem ? Is it related to ADX ? (I suppose not)


AddinExpress.OL.2005: 9.4.4644.0
Office Version: Office ProPlusRetail16.0.12026.20334 Click-To-Run Production
Windows 10 - 1803

Tx,
Fabrice
Posted 04 Nov, 2019 05:23:06 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Fabrice,

Fabrice writes:
if I set the Outlook compatibility mode, then everything is working.


This detail indicates that the issue relates to the DPI context introduced with multi-DPI support in Windows and Office. I would try to show the first modal form *after* the button's Click event is handled; you can use the SendMessage/OnSendMessage machinery that we describe in section Wait a Little at https://www.add-in-express.com/docs/net-office-tips.php#wait-a-little: when the OnSendMessage event occurs and e.Message is your message (an integer > 1024), you show the modal form.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Nov, 2019 07:46:08 Top
Fabrice


Guest


Hello Andrei

I'm used to the SendMessage, but until now I use it to return on the main thread.
If I correctly undestand, the goal here is to let the outlook event finish, then open the modal form ?
I'll try and let you know if it fix the problem.

Thank you
Fabrice
Posted 04 Nov, 2019 12:59:42 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Fabrice,

Fabrice writes:
If I correctly undestand, the goal here is to let the outlook event finish, then open the modal form ?


Exactly.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Nov, 2019 02:19:23 Top
Fabrice


Guest


I'm bit late on this, but unluckily it doesn't work.

I've tried to use SendMessage to open the 1st AND 2nd modal, or only first, or only 2nd, but anyway I still have the 2nd modal that don't get the focus.


In fact It's not linked to modal, because I've just discovered a second case when it's a (single) non modal windows that have the same focus problem.

What's strange is that in the first case (modal over modal) the form is filled with its controls, visually correct. In the second case I've a blank window, even if the controls are created.

In both case everything works fine if I enable the Outlook compatibility mode.
Posted 13 Nov, 2019 11:35:27 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Fabrice,

protected override void CreateHandle()
        {
            int context = DPIAwareAPI.GetWindowDpiAwarenessContext(GetOutlookWindowHandle());
            DPIAwareAPI.SetThreadDpiAwarenessContext(context);
            base.CreateHandle();
        }


The method above - it should be used on both forms - sets the DPI context of the form to the DPI context of the main Outlook window. Find descriptions of the GetWindowDpiAwarenessContext() and SetThreadDpiAwarenessContext() functions at https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-improvements-for-desktop-applications. These functions aren't available in Windows versions before Windows 10 version 1607.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2019 07:28:55 Top
Fabrice


Guest


Nice, thank you

I had to search a bit for the pinvoke stuff, and workaround the fact that the form is in a project without link to ADX, but now it works. I can only test the 2nd case atm, but now the windows open and everything seems to work as expected.

I post here for future users that need it. I still have to add the check for minimum version (windows 10 1607).
I'm planning to execute it by default on all forms.

Pinvoke (DPIHelper):

public enum DPI_AWARENESS
{
    DPI_AWARENESS_INVALID = -1,
    DPI_AWARENESS_UNAWARE = 0,
    DPI_AWARENESS_SYSTEM_AWARE = 1,
    DPI_AWARENESS_PER_MONITOR_AWARE = 2
}

public enum DPI_AWARENESS_CONTEXT
{
    DPI_AWARENESS_CONTEXT_DEFAULT = 0, 
    DPI_AWARENESS_CONTEXT_UNAWARE = -1, 
    DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = -2, 
    DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = -3 
}

[DllImport("User32.dll")]
public static extern DPI_AWARENESS_CONTEXT GetWindowDpiAwarenessContext(
    IntPtr hwnd);

[DllImport("User32.dll")]
public static extern DPI_AWARENESS_CONTEXT SetThreadDpiAwarenessContext(
    DPI_AWARENESS_CONTEXT dpiContext);


Usage:

object activeWindow = App.ADXModule.OutlookApp.ActiveWindow();
if (activeWindow != null)
{
    var context = DPIHelper.GetWindowDpiAwarenessContext(App.ADXModule.GetOutlookWindowHandle(activeWindow));
    DPIHelper.SetThreadDpiAwarenessContext(context);
}
Posted 14 Nov, 2019 08:28:59 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Thank you very much!


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2019 08:45:40 Top