This is the setting:
I have two views that are implemented within two different vcl forms. To one of those I applied a style to make it look like a touch optimized metro app. Those forms can be switched according to an application's setting. (show touch optimized view on/off)
this works pretty good. I override Application.MainForm
, the old form closes, the new form appears (and takes the focus).
I want this to be automated in Windows 10. As additional view mode I offer an option "Auto detect":
- I am listening for the windows message
WM_SETTINGCHANGE
. This is sent by switching between desktop mode and tablet mode. - Then I check the registry for the value of
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell\TabletMode
- If it's 1 I switch to the touch optimized view.
And this is the problem:
The old form is destroyed, the new form pops up and Application.MainForm
references the new form.
Buf afterwards also the start screen of the tablet mode pops up and shows itself on the very top of all windows.
So my new touch optimized form disappears behind this screen and loses the focus. This behavior doesn't appear if I set the view fixed to the desktop view and switch windows 10 into tablet mode. in this case, my application keeps the focus and maximizes itself (that way there's no form created of course).
What I've tried so far:
- The most obvious approach would be a call of
Application.MainForm.BringToFront
.This doesn't work. - My second approach was to create a hidden "helperform" that takes
FormStyle := fsStayOnTop
(this way the focus should be taken) and callsSetForeground(Application.MainForm.Handle)
from WinAPI.
any ideas?