Lajos Juhász 295 Posted October 18, 2021 In older versions of windows this worked: h := FindWindow( nil,'Calculator') ; if h = 0 then WinExec('calc.exe', sw_ShowNormal) else ShowWindow(h, SW_SHOWNORMAL); Unfortunately on Windows 10 this doesn't work anymore. I can see that the application has 2 top-level windows unfortunately after ShowWindow, SetWindowPos or SetForegroundWindow the calculator application get focused on the taskbar and the "calculator" window turns into dark grey and doesn't get the focus. How should I adjust this code for Windows 10? Share this post Link to post
FredS 138 Posted October 18, 2021 (edited) 1 hour ago, Lajos Juhász said: How should I adjust this code for Windows 10? This works for me, even switches desktops if you have more that one: BringWindowToTop(FindWindow( nil,'Calculator')); EDIT: the desktop switching is a bit flaky though.. Edited October 18, 2021 by FredS 1 Share this post Link to post
Lajos Juhász 295 Posted October 18, 2021 On my laptop doesn't work. Even cannot use directly FindWindow as it returns a window handle from the ApplicationFramHost.exe instead of the Calculator. Tried on Window handles from the calculator but the reasult is same as with ShowWindow or SetWindowPos. Share this post Link to post
FredS 138 Posted October 18, 2021 @Lajos Juhász I assume you replied to me.. best to use a tag like I just did or quote some part of the text else a user never gets alerted. Only checked back here because of a 'Like'.. Maybe we are missing some info? All this assumes your calls are made from the Active input Window, and Calculator actually has the 'Calculator' caption. I did run SpyXX first and my version 20H2 has an actual window 'Calculator' buried within that framework and BringWindowToTop claims, and does on my system, bring that to the Top. Share this post Link to post
David Heffernan 2353 Posted October 18, 2021 Is it the calculator window that you want to bring to the top, or is this just an example? And what if there are multiple windows so named? Share this post Link to post
Attila Kovacs 631 Posted October 18, 2021 I've not much experience with WPF apps but this was interesting to read: https://stackoverflow.com/questions/59651420/bring-calculator-window-to-front-in-windows-10 Share this post Link to post
Lajos Juhász 295 Posted October 18, 2021 9 minutes ago, David Heffernan said: Is it the calculator window that you want to bring to the top, or is this just an example? And what if there are multiple windows so named? The calculator. It's a kiosk type application and the user will have only one instance of calculator open at a time. Share this post Link to post
Lajos Juhász 295 Posted October 18, 2021 45 minutes ago, FredS said: I did run SpyXX first and my version 20H2 has an actual window 'Calculator' buried within that framework and BringWindowToTop claims, and does on my system, bring that to the Top. On My System using reticle (https://chapmanworld.com/2018/10/04/custom-vcl-control-for-getting-window-handles-spy-style-reticle/) I get: Handle: 2952088 Class: Windows.UI.Core.CoreWindow Caption:Calculator Ancestor handle: 396212 Ancestor class: ApplicationFrameWindow Ancestor caption: Calculator I can focus Ancestor handle but it will not get the keyboard focus. In order to focus I have to do: ShowWindow(<Ancestor Handle>, SW_SHOWNORMAL ); SetForegroundWindow(<Ancestor Handle>); ShowWindow(<Handle>, SW_SHOWNORMAL ); Tomorrow I am going to try to find a way to get the handle of the Windows.UI.Core.CoreWindow didn't managed to get it using FindWindowEx. Share this post Link to post
FredS 138 Posted October 18, 2021 (edited) 2 hours ago, Lajos Juhász said: can focus Ancestor handle but it will not get the keyboard focus. BringWindowToTop give it keyboard focus here.. of course I'm not dealing with minimized.. FYI it also gets focus if on a different virtual desktop. This works here, suspended or not.. hFrame := FindWindow('ApplicationFrameWindow', 'Calculator'); if isIconic(hFrame) then ShowWindow(hFrame, SW_RESTORE) else BringWindowToTop(hFrame); Edited October 18, 2021 by FredS Share this post Link to post