5

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":

  1. I am listening for the windows message WM_SETTINGCHANGE. This is sent by switching between desktop mode and tablet mode.
  2. Then I check the registry for the value of HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell\TabletMode
  3. 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:

  1. The most obvious approach would be a call of Application.MainForm.BringToFront.This doesn't work.
  2. My second approach was to create a hidden "helperform" that takes FormStyle := fsStayOnTop (this way the focus should be taken) and calls SetForeground(Application.MainForm.Handle) from WinAPI.

any ideas?

René Hoffmann
  • 2,766
  • 2
  • 20
  • 43
Florian Grummel
  • 332
  • 3
  • 14
  • Might be a stupid suggestion, but did you try popping up (and focusing, setting foreground) the new form *before* destroying/hiding the old one? – Boris B. Sep 21 '15 at 14:27
  • Unfortunately this doesn't work either. The application first behaves like I described above (*This behavior doesn't appear if I set the view fixed to the desktop view and switch windows 10 into tablet mode*) and maximizes the desktop form. Then both disappear. – Florian Grummel Sep 22 '15 at 08:22
  • Between `Show` and `Hide` I also tried to call a procedure that performs the helperform hack as well as `Application.MainForm.BringToFront`. **And this also didn't work**: I moved the block to a thread that waits for 3 seconds until windows finished its stuff (switching and displaying start screen) in order to perform the switch of my forms asynchronuously. – Florian Grummel Sep 22 '15 at 08:30
  • This any help http://stackoverflow.com/a/20707637/185565 (bring form to front) ? – Whome Oct 15 '15 at 21:59

0 Answers0