PostMessage Not Working on 64-bit Windows 7

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

PostMessage Not Working on 64-bit Windows 7

11 Dec 2019, 17:18

My system is running a fresh install of Windows 7 Ultimate SP1 64-bit. The hotkeys in the script right below always operate on a non-active window if the active window belongs to a 32-bit process and may operate on a non-active window if the active window belongs to a 64-bit process.

Code: Select all

#NoEnv
SetBatchLines -1

DllCall("QueryPerformanceFrequency", "Int64*", freq)
GroupAdd ExclWindows, ahk_class Shell_TrayWnd
GroupAdd ExclWindows, ahk_class DV2ControlHost

Loop {
	KeyWait RWin, D
	DllCall("QueryPerformanceCounter", "Int64*", RWinDownTimestamp)
	KeyWait RWin
} return

#If A_PriorKey == "RWin" and DllCall("QueryPerformanceCounter", "Int64*", RWinUpTimestamp) and 2 * (RWinUpTimestamp - RWinDownTimestamp) < freq and WinExist("A",, "ahk_group ExclWindows")

RWin Up:: PostMessage 0x112, 0xF020     ; Should minimize the active window
^RWin Up:: PostMessage 0x112, 0xF060    ; Should close the active window

#If
However, the hotkeys in the script below function properly:

Code: Select all

#NoEnv
SetBatchLines -1

DllCall("QueryPerformanceFrequency", "Int64*", freq)

Loop {
	KeyWait RWin, D
	DllCall("QueryPerformanceCounter", "Int64*", RWinDownTimestamp)
	KeyWait RWin
} return

#If A_PriorKey == "RWin" and DllCall("QueryPerformanceCounter", "Int64*", RWinUpTimestamp) and 2 * (RWinUpTimestamp - RWinDownTimestamp) < freq and DllCall("IsWindowVisible", "Ptr", hWndMin := DllCall("GetForegroundWindow", "Ptr")) and VarSetCapacity(MinWinClass, 257 << (A_IsUnicode = true)) and DllCall("GetClassName", "Ptr", hWndMin, "Str", MinWinClass, "Int", 257) and !in(MinWinClass, "Shell_TrayWnd,DV2ControlHost")

RWin Up:: DllCall("PostMessage", "Ptr", hWndMin, "UInt", 0x112, "UInt", 0xF020, "UInt", 0)
^RWin Up:: DllCall("PostMessage", "Ptr", hWndMin, "UInt", 0x112, "UInt", 0xF060, "UInt", 0)

#If

in(string, list) {
	If string in list
		return true
	return false
}
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: PostMessage Not Working on 64-bit Windows 7

12 Dec 2019, 05:24

Code: Select all

RWin Up:: PostMessage 0x112, 0xF020     ; Should minimize the active window
No, it should minimize the "Last Found Window", if any. What makes you think that PostMessage is not working?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: PostMessage Not Working on 64-bit Windows 7

12 Dec 2019, 05:55

If you want to minimize the active window:

Code: Select all

PostMessage 0x112, 0xF020,,, % "ahk_id " . WinExist("A")
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: PostMessage Not Working on 64-bit Windows 7

12 Jan 2020, 07:31

Your problem is this,
WinTitle wrote: If WinTitle is the letter A and the other 3 window parameters (WinText, ExcludeTitle and ExcludeText) are blank or omitted, the active window will be used.
and
WinExist wrote: ExcludeTitle
Type: String

Windows whose titles include this value will not be considered.
The ExcludeTitle parameter is not a WinTitle parameter, so ahk_xxx is not supported. Specifically, WinExist("A",, "ahk_group ExclWindows") will not set the last found window (to non-zero) unless there is a window which title contains an A and also doesn't contain the text ahk_group ExclWindows.

You can do

Code: Select all

#if !WinActive("ahk_group mygrp") && WinExist("A")
a::postmessage x,y
Cheers.
Spoiler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 367 guests