DetectHiddenWindows bug?

Report problems with documented functionality
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

DetectHiddenWindows bug?

02 Apr 2017, 17:47

Possible DetectHiddenWindows bug?

When I run this script, the MsgBox says that A_DetectHiddenWindows is 'Off', even though it is set to 'On' in the auto-execute section.

It shows 'Off' the first time, but 'On' on subsequent occasions. It appears that placing 'DetectHiddenWindows, On' again, just before the MsgBox, fixes the problem in this case.

It sounds reminiscent of this bug:
Possible DetectHiddenWindows bug - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/2487 ... ndows-bug/

The documentation:
DetectHiddenWindows
https://autohotkey.com/docs/commands/De ... indows.htm

Code: Select all

;from:
;FileSelectFile, add controls to the Open/Save As dialog - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=29934&sid=dcb1186ada346b66ac30bd95a6fed2d1

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
DetectHiddenWindows, On

VarSetCapacity(OPENFILENAMEW, (cbOFN := A_PtrSize == 8 ? 152 : 88), 0)
NumPut(cbOFN, OPENFILENAMEW,, "UInt") ; lStructSize
NumPut(A_ScriptHwnd, OPENFILENAMEW, A_PtrSize, "Ptr") ; hwndOwner

filters := [ "Text Documents", "*.txt"
			,"Test",           "*.nfo"
			,"All files",      "*.*"]

if (IsObject(filters) && Mod(filters.MaxIndex(), 2) == 0) {
	finalFilterString := ""
	for _, filter in filters
		finalFilterString .= Mod(A_Index, 2) ? filter . " (" : filter . ")|" . filter . "|"

	while ((char := DllCall("ntdll\wcsrchr", "Ptr", &finalFilterString, "UShort", Asc("|"), "CDecl Ptr")))
		NumPut(0, char+0,, "UShort")

	NumPut(&finalFilterString, OPENFILENAMEW, A_PtrSize*3, "Ptr") ; lpstrCustomFilter
	NumPut(1, OPENFILENAMEW, A_PtrSize*(5 + (A_PtrSize == 4)), "UInt") ; nFilterIndex
}

VarSetCapacity(vPath, (260+2)*2, 0) ; if keeping the option to select multiple files, consider raising the size
vPath .= "*.txt"
NumPut(&vPath, OPENFILENAMEW, A_PtrSize*(6 + (A_PtrSize == 4)), "Ptr") ; lpstrFile
NumPut(260, OPENFILENAMEW, A_PtrSize*(7 + (A_PtrSize == 4)), "UInt") ; nMaxFile

initialDir := A_Desktop
title := "Open"
NumPut(&initialDir, OPENFILENAMEW, A_PtrSize*(10 + (A_PtrSize == 4)), "Ptr") ; lpstrInitialDir
NumPut(&title, OPENFILENAMEW, A_PtrSize*(11 + (A_PtrSize == 4)), "Ptr") ; lpstrTitle

NumPut((cb := RegisterCallback("OFNHookProc")), OPENFILENAMEW, A_PtrSize == 8 ? 120 : 68, "Ptr")
NumPut(OFN_EXPLORER := 0x00080000 | OFN_HIDEREADONLY := 0x00000004 | OFN_ALLOWMULTISELECT := 0x00000200 | OFN_ENABLEHOOK := 0x00000020, OPENFILENAMEW, A_PtrSize*(12 + (A_PtrSize == 4)), "UInt") ; Flags

if (DllCall("comdlg32\GetOpenFileNameW", "Ptr", &OPENFILENAMEW)) {
	dirOrFile := StrGet(&vPath,, "UTF-16")
	if (InStr(FileExist(dirOrFile), "D")) {
		; Multiple files selected
		fileNames := &vPath + (NumGet(OPENFILENAMEW, A_PtrSize == 8 ? 100 : 56, "UShort") * 2)
		while (*fileNames) {
			MsgBox % dirOrFile . "\" . (filename := StrGet(fileNames,, "UTF-16"))
			fileNames += (DllCall("ntdll\wcslen", "Ptr", fileNames, "CDecl Ptr") * 2) + 2
		}
	} else {
		MsgBox %dirOrFile%
	}
	if (ColorSelection)
		MsgBox % ColorSelection
}
DllCall("GlobalFree", "Ptr", cb, "Ptr")
return

OFNHookProc(hdlg, uiMsg, wParam, lParam)
{
MsgBox, % A_DetectHiddenWindows
	global ColorSelection
	if (uiMsg == 0x0110) { ; WM_INITDIALOG

;===============
;some experiments:
;WinGetPos returns width/height values of 0
if 0
{
	WinGetPos, vPosX, vPosY, vPosW, vPosH, % "ahk_id " hdlg
	MsgBox, % vPosX " " vPosY " " vPosW " " vPosH
}

;WinMove at this stage has surprising results
;the resulting dialog box will be than it would have been
;in pixels, by the height value specified
;(note: the dialog height is set in a WinMove line lower down, so that will have to
;be commented out in order to set the height here)
if 0
	WinMove, % "ahk_id " hdlg, , , , 400, 200 ;does not affect width

if 0
{
	vWinStyle := 0x96CC00C4, vWinExStyle := 0x00010101
	WinSet, Style, % vWinStyle, % "ahk_id " hdlg
	WinSet, ExStyle, % vWinExStyle, % "ahk_id " hdlg
}
;===============

WinMove, % "ahk_id " hdlg, , , , , 46 ;resulting dialog box will be 46 pixels taller than it would have been
vPosX1 := 102, vPosY1 := 387, vPosW1 := 60, vPosH1 := 65
vPosX2 := 195, vPosY2 := 385, vPosW2 := 246, vPosH2 := 21

		Gui, Add, Text, x%vPosX1% y%vPosY1% w%vPosW1% h%vPosH1% hWndhCtl1, &Encoding:
                ;h%vPosH2% was affecting the height of the drop-down list
		;note: for 'Gui, Add, DropDownList', h determines the height of the popup list not the ComboBox
		Gui, Add, DropDownList, x%vPosX2% y%vPosY2% w%vPosW2% hwndhCtl2 vColorSelection, ANSI||Unicode|Unicode big endian|UTF-8
		DllCall("SetParent", "Ptr", hCtl1, "Ptr", DllCall("GetParent", "Ptr", hdlg, "Ptr"), "Ptr")
		DllCall("SetParent", "Ptr", hCtl2, "Ptr", DllCall("GetParent", "Ptr", hdlg, "Ptr"), "Ptr")
	} else if (uiMsg == 0x004E) {
		if (NumGet(lParam+0, A_PtrSize * 2, "UInt") == 4294966690) { ; CDN_FILEOK
			Gui submit
		}
	} else if (uiMsg == 0x0002) { ; WM_DESTROY
		Gui Destroy
	}
	return 0
}
==================================================

[EDIT:][relevant comment in the documentation]
AutoHotkey Scripts and Macros
https://www.autohotkey.com/docs/Scripts.htm#auto
If the auto-execute section takes a long time to complete (or never completes), the default values for the above settings will be put into effect after 100 milliseconds. When the auto-execute section finally completes (if ever), the defaults are updated again to be those that were in effect at the end of the auto-execute section. Thus, it's usually best to make any desired changes to the defaults at the top of scripts that contain hotkeys, hotstrings, timers, or custom menu items. Also note that each thread retains its own collection of the above settings. Changes made to those settings will not affect other threads.
Last edited by jeeswg on 03 Apr 2017, 07:53, edited 3 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: DetectHiddenWindows bug?

02 Apr 2017, 22:24

I'm pretty sure it's not a bug, and was already explained in the topic you linked to (and with the relevant documentation quoted).

You are calling the function before the auto execute section completes.
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DetectHiddenWindows bug?

03 Apr 2017, 02:02

If the auto-execute section takes a long time to complete (or never completes), the default values for the above settings will be put into effect after 100 milliseconds.
I have to admit that I didn't really noticed that as yet. Is there a technical reason for the delay? Will it stay in effect in v2?

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 63 guests