alternative ways to showwindow?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

alternative ways to showwindow?

08 Feb 2018, 19:16

I'm using ControlClick to interact with Spotify (automatically), however the window ofc. needs to be visible for this to work, trying to get it to show it [the window when its behind another or minimized] without activating it is somewhat a struggle though;

I've tried changing Z-Order with DllCall("SetWindowPos", UInt, hwnd, UInt, 1, Int, 0, Int, 0, Int, 0, Int, 0, UInt, (SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW)), but it does nothing.
using showwindow DllCall("ShowWindow", UInt, hwnd, Int, SW_SHOWNOACTIVATE), but it does nothing.
SetForegroundWindow/SwitchToThisWindow works but ofcourse it activates the window, BringWindowToTop does nothing.
All return success [with no A_LastError] and running the script as admin doesn't change the results.

The only other working method is setting AlwaysOnTop but this isn't ideal.

Any other methods I've missed, before resorting to AlwaysOnTop?

*EDIT*
Just for confirmation heres what the I get back from each call:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by KuroiLight on 08 Feb 2018, 19:38, edited 1 time in total.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
User avatar
Exaskryz
Posts: 2855
Joined: 17 Oct 2015, 20:28

Re: alternative ways to showwindow?

08 Feb 2018, 19:38

If ControlClick is working, and it is not activating the window, try just moving the window off screen. I have used WinMove, Title,, 0, 1100, 1000, 1000 (changing the 1000s to whatever size the window natively is; can be obtained with Window Spy or using WinGetPos) / WinMove, 0, 1100 when it was active to move the window to below the rendered area of my screen (which is 1920x1080) and been able to interact with it. In my case, I actually used normal Click and Send because the Control varieties weren't working.

It's a workaround, so I'd hope someone can supply a better answer.
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: alternative ways to showwindow?

08 Feb 2018, 19:44

ControlClick works and doesn't activate the window and I want to keep it that way; but the window has to be visibly on top
There is no WinSetPos so I tried

Code: [Select all] [Download] GeSHi © Codebox Plus

ShowNoActivateViaMove(hwnd) {
WinGetPos, x, y, w, h, ahk_id %hwnd%
WinSet, Region, %x%-%y%, ahk_id %hwnd%
}

But it doesn't bring it forward.

*edit* guess you fixed winsetpos beofre I replied :P
changed it to:

Code: [Select all] [Download] GeSHi © Codebox Plus

ShowNoActivateViaMove(hwnd) {
WinGetPos, x, y, w, h, ahk_id %hwnd%
WinMove, ahk_id %hwnd%,, %x%, %y%, %w%, %h%
}

still nope.

Nvm I misunderstood what you meant, I will try that.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: alternative ways to showwindow?

08 Feb 2018, 20:14

trying to see if it will work and... running into the multi-timer lockup bug again....
Don't understand why in some cases running 2 timers kills one of them.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



*EDIT*
I have my doubts that this method will work, I don't think ImageSearch works on offscreen objects and I still need to restore w/ no activate when I accidently hit minimize on spotify.
I'm open to other suggestions though.
*EDIT2*
Just confirmed ImageSearch doesn't work offscreen.
The funny thing is I'm working on this script despite the fact that Ill be re-subbing to spotify in a week or 2... lol
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
Exaskryz
Posts: 2855
Joined: 17 Oct 2015, 20:28

Re: alternative ways to showwindow?

08 Feb 2018, 23:49

Without any familiarity with Spotify or the images in your ImageSearch, I do wonder if they are strictly necessary though. I also see PixelGetColor strung throughout, so, that would probably need to be on screen unfortunately. I think if images/pixel colors are necessary, you may need to turn to GDI+, but I also have no familiarity with that.

You can handle the accidental minimize with a separate timer that checks every 200-300 ms for the state of Spotify with WinGet and the MinMax subcommand. Then make it WinRestore if it's the Minimized position (-1), but that would reactivate it... So you might need to capture the active window and WinActivate that active window immediately after restoring Spotify, maybe. Clunky, but could work...

This kind of alludes to the issue of multi-timer lock up. I see in some places you're using a Loop for WinWait[Not]Active -- in the AutoMove(), which might be a problem? If you have two loops like that, one thread is going to be interrupted by a never ending thread -- so the first thread isn't going to resume. I didn't spot the second potential offending loop that could be in a timer, but something to look for. That's why I suggested you keep repeating the WinGet for the MinMax; to avoid one of them getting permanently interrupted.
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: alternative ways to showwindow?

09 Feb 2018, 17:32

imagesearch/pixelgetcolor are needed because the entire spotify window just shows up as a Chrome_RenderWidgetHostHWND1, with no discernible controls.
Yea, you are likely right about WinWait commands, I had assumed they would automatically yield to other running timers between internal checks but I guess this wasn't considered when they were written.

*edit*
Just testing what causes the timer lockup and its easily reproduced, despite me thinking it should work.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


^This timer1 function never completes a loop, but timer2 does. but adding a sleep between timer calls will stop timer2 from ever running.

but doing it this way, succeeds, I think some mention of this should be included in the docs. something like: "Using a negative value will cause the timer thread to return only when its completed." or "Using a negative value will stall the current thread until the timer finishes."

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: alternative ways to showwindow?

09 Feb 2018, 19:19

- Did you try AccViewer, to investigate controls/GUI elements?
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
- I searched threads featuring me for Spotify, and found these, in case they're useful:
Spotify - Adding a song to a specific playlist - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=42651
Spotify Hotkeys (again) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=41636
Spotify PostMessage Library - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39465
Adding a song to a specific playlist in Spotify - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=24771

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 37 guests