How to make delphi form in foreground in Windows 10 tablet mode

This parameter is:

I have two views that are implemented in two different forms of vcl. I applied a style to one of them to make it look like an application with an optimized touch application. These forms can be switched according to the application settings. (enable or disable optimized touch viewing)

it works very well. I override Application.MainForm , the old form closes, a new form appears (and takes focus).

I want this to be automated in Windows 10. As an additional view mode, I suggest the "Auto detect" option:

  • I am listening to a Windows WM_SETTINGCHANGE . This is dispatched by switching between desktop and tablet modes.
  • Then I check the registry for the value HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell\TabletMode
  • If it is 1, I will switch to optimized touch mode.

And this is the problem:

The old form is destroyed, a new form appears and Application.MainForm refers to the new form. Buf subsequently also displays the tablet’s initial screen and is displayed at the very top of all windows. Thus, my new optimized touch form disappears behind this screen and loses focus. This behavior does not appear if I set the view fixed to the desktop and switch windows 10 to tablet mode. in this case, my application maintains focus and maximizes itself (thus, the form is not created, of course).

What I have tried so far:

  • The most obvious approach is to call Application.MainForm.BringToFront . This does not work.
  • My second approach was to create a hidden "helperform" that takes FormStyle := fsStayOnTop (so you need to focus) and calls SetForeground(Application.MainForm.Handle) from WinAPI.

any ideas?

+5
source share

Source: https://habr.com/ru/post/1231943/


All Articles