WinMaximize fails with timer

Get help with using AutoHotkey and its commands and hotkeys
BunsenH
Posts: 31
Joined: 11 Apr 2015, 10:45

WinMaximize fails with timer

21 Feb 2019, 14:34

I'm looking at adding some enhancements to my "Go to bed!" nagger and have run across a case in which the WinMaximize command appears to fail when the function that includes it is called from a thread set up by SetTimer, but not when the same function is called from the main thread.

The intention for the script is to have each monitor covered by a full-screen window, displaying some text, that's very hard to dislodge. These windows persist for a short time and then go away. This can be run as a scheduled task in the evening as an inducement to stop surfing, creating an increasing level of interruption until one gives up and goes to bed (or at least finds something to do that doesn't involve the computer).

What's supposed to happen is that every 1000 ms, each of the script's windows is moved to the upper left of its monitor and maximized. (Maximization alone isn't sufficient; the window could be dragged to a different monitor.) Please see the attached. (It's configured to run for 30 seconds.) When the function that updates the windows is called from the main thread, it does just what it's supposed to do.

But if line 81 is uncommented, enabling the SetTimer call, and line 88 is commented out to prevent the window updater from being called there, the WinMaximize is unreliable. One can drag a window by its title bar, which appears to shrink the window to fit the text, and move it around the screen. It gets repositioned to the upper left within a second of being released, as it should, but sometimes it doesn't get maximized. It looks rather as though the reduced window size is stored as the window's new maximum size. Or that AHK thinks that the window is already maximized when it isn't, so doesn't bother to repeat what it thinks is an unnecessary maximization.

Since the WinMove call immediately before the WinMaximize call is working properly, and the function that's doing those calls is the same in both cases, and everything else seems to be the same, I'm fairly sure that the problem is a glitch involving WinMaximize specifically in this situation.

I'm using this with Windows 8.1 . I'm currently using AHK v. 1.1.30.01, but was seeing the same kind of behaviour with v. 1.1.19.03 .
Attachments
goto_bed_2_1.ahk
(6.52 KiB) Downloaded 20 times
Last edited by BunsenH on 22 Feb 2019, 02:15, edited 1 time in total.
BunsenH
Posts: 31
Joined: 11 Apr 2015, 10:45

Re: WinMaximize fails with timer

21 Feb 2019, 15:49

A bit more data: Adding a Sleep, 100 call right after the WinMaximize call doesn't make a difference. That is, it's not that the WinMaximize is getting "cut off" (so to speak) by the end of the timed function. Nor does adding a second WinMaximize call affect the behaviour.
Helgef
Posts: 4031
Joined: 17 Jul 2016, 01:02
Contact:

Re: WinMaximize fails with timer

22 Feb 2019, 03:02

winmaximize works just fine in when used in a subroutine launched by settimer. You should ask in the help forum if you need help to debug your code.
swagfag
Posts: 3075
Joined: 11 Jan 2017, 17:59

Re: WinMaximize fails with timer

22 Feb 2019, 03:42

cant reproduce

Code: Select all

Run notepad.exe
WinWaitActive ahk_exe notepad.exe
hwnd := "ahk_id " WinActive("A")

SetTimer Max, -200

Esc::
	WinClose % hwnd
	ExitApp
Return

Max:
	WinMaximize % hwnd
	SetTimer Min, -200
Return

Min:
	WinRestore % hwnd
	SetTimer Max, -200
Return
BunsenH
Posts: 31
Joined: 11 Apr 2015, 10:45

Re: WinMaximize fails with timer

22 Feb 2019, 12:10

Did either of you run the script that I included, and follow the instructions that I gave?
swagfag
Posts: 3075
Joined: 11 Jan 2017, 17:59

Re: WinMaximize fails with timer

22 Feb 2019, 13:26

no? did i have to? the claim was "WinMaximize fails with timer [subroutine]" which is demonstrably false
BunsenH
Posts: 31
Joined: 11 Apr 2015, 10:45

Re: WinMaximize fails with timer

22 Feb 2019, 19:41

I'm not asserting that it always fails. But it fails in this case, when the only apparent difference is which thread it's called from.

Return to “Ask For Help”

Who is online

Users browsing this forum: agrout, AHKStudent, Bing [Bot], Google [Bot], holahapi, MannyKSoSo and 220 guests