Array of hWnds to keep track of times seen

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TULOA
Posts: 3
Joined: 17 Mar 2018, 17:48

Array of hWnds to keep track of times seen

17 Mar 2018, 17:58

I am trying to write a script to find a windows hWnd that has a set format using a regex WinExist function. I want to store the hWnd to an associative array with the hWnd being the key and a value starting at 0 and each time it shows up it will be incremented by 1.

My issue I am running into is either storing the hWnd or something with the array.

Code: Select all

#Persistent

SetTitleMatchMode, RegEx
SetTitleMatchMode, slow

Array := {}

SetTimer, main, 500
return

main:
mHwndWrap := WinExist( "(Line 1:).*(Wrap:).*")
WinGet, mHwndMinStatus, MinMax, ahk_id %mHwndWrap%
;MsgBox, %mHwndMinStatus% . " " . %mHwndWrap%

if (%mHwndWrap% != 0 and mHwndMinStatus != -1){
  Array[%mHwndWrap%] := Array[%mHwndWrap%] + 1
  mTemp := Array[%mHwndWrap%]
  MsgBox, %mTemp%
  if(Array[%mHwndWrap%] < 2){
    PostMessage, 0x112, 0xF020,,, ahk_id %mHwndWrap%
  }
}
return
The above is the current script. It is supposed to minimize the window with the given hWnd only if its the first time it appears. After that there should be a 1 second computer idle delay that I will code but I need to figure out the array first. It is being wierder than other arrays I have worked with.

I have also tried Array := [] at the start.
TULOA
Posts: 3
Joined: 17 Mar 2018, 17:48

Re: Array of hWnds to keep track of times seen

17 Mar 2018, 22:25

Well I would like to fix it so that I dont have to have multiple variables running but for now I am using dynamic variables to store the hwnds and checking them and thats working.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Array of hWnds to keep track of times seen

18 Mar 2018, 02:15

Code: Select all

#Persistent

SetTitleMatchMode, RegEx
SetTitleMatchMode, slow

Array := []

SetTimer, main, 500
return

main:
mHwndWrap := WinExist( "(Line 1:).*(Wrap:).*")
WinGet, mHwndMinStatus, MinMax,% "ahk_id " . mHwndWrap
MsgBox, % mHwndMinStatus . " " . mHwndWrap

if (mHwndWrap != 0) && (mHwndMinStatus != -1){
  Array[mHwndWrap] := Array[mHwndWrap] + 1
  mTemp := Array[mHwndWrap]
  MsgBox % mTemp
  if(Array[mHwndWrap] < 2){
    PostMessage, 0x112, 0xF020,,,% "ahk_id " . mHwndWrap
  }
}
return
Not tested. Check out AHK's help about "variables","expressions" and "forced expressions".
You're mixing up setting variables "legacy-style" and "expression-style".
TULOA
Posts: 3
Joined: 17 Mar 2018, 17:48

Re: Array of hWnds to keep track of times seen

18 Mar 2018, 22:00

I just ran a test and the MsgBox for the array value is returning blank. Its almost as if its rounding the hWnd or something before storing it.

I when I converted it off the array and to dynamic variables it works and properly stores the variable value.

My current working code:

Code: Select all

#Persistent

SetTitleMatchMode, RegEx
SetTitleMatchMode, slow


SetTimer, main, 500
mHwndWrap := 0
return

main:
mHwndWrap := 0
mHwndWrap := WinExist( "(Line 1:).*(Wrap:).*")
WinGet, mHwndMinStatus, MinMax, ahk_id %mHwndWrap%

if (mHwndWrap <> 0 and mHwndMinStatus != -1){
  mTemp%mHwndWrap% += 1
  mTemp2 := mTemp%mHwndWrap%
  if(mTemp2 < 2){
    ;If the wrap window shows up minimize it right away the first time.
    PostMessage, 0x112, 0xF020,,, ahk_id %mHwndWrap%
  } 
  if(mTemp2 > 1){
    ;Wait a moment then minimize for subsequent times so one can hit ok to go to next call.
    if( A_TimeIdle > 300){
      PostMessage, 0x112, 0xF020,,, ahk_id %mHwndWrap%
    }
  }
}
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 388 guests