WinClose fails in OnMessage/ShellMessage

Get help with using AutoHotkey and its commands and hotkeys
newbieforever
Posts: 400
Joined: 24 Aug 2016, 03:34

WinClose fails in OnMessage/ShellMessage

06 May 2019, 09:03

Hi! EDITED: Sorry...it's not worth reading. A bunch of misunderstandings!

I hope that this question is understandable enough.

I am using OnMessage(MsgNum, "ShellMessage") to detect the syntax-error window on start of another script and to close it immediately. In the following demo script this works perfectly:

If there is a syntax error in OtherScr.ahk, the error window is displayed but closed immediately by WinClose (in the !!! line).

Unfortunately my script is much more complex than this demo script (I cannot reduce it to a form that I could reasonably present here). But the OnMessage/ShellMessage part is exactly as in the demo script. I know this is suboptimal, but maybe someone here would still have an idea what the reason might be that WinClose fails in my script? (Even WinKill doesn't close the window!)

Code: Select all

#Persistent

Gui Test: Show, w500 h500

OtherScr := A_ScriptDir . "\OtherScr.ahk"
Run, %A_AhkPath% "%OtherScr%"

Gui +LastFound
DllCall("RegisterShellHookWindow", UInt, WinExist())
MsgNum := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
OnMessage(MsgNum, "ShellMessage")

RETURN

ShellMessage(wParam, lParam) {
  If (wParam = 32772) {
    lParam := Dec2hex(lParam)
    WinGetTitle, Tit, ahk_id %lParam%
    If InStr(Tit, "OtherScr.ahk") {
      WinGetText, EMsg, ahk_id %lParam%
      If InStr(SubStr(EMsg, -20), "will exit") {
        WinClose, ahk_id %lParam%                                     ; !!!
        MsgBox, , SYNTAX ERROR, The AHK interpreter has identify an syntax error in your script OtherScr.ahk.
        ExitApp
        }
      }
    }
  }

Dec2hex(n) {
  oIF := A_FormatInteger
  SetFormat, Integer, hex
  n := StrLen(n+0) ? n+0 : n
  SetFormat, Integer, % oIF
  Return n
  }
  
TestGuiClose:
  ExitApp
Return
Last edited by newbieforever on 06 May 2019, 12:33, edited 1 time in total.
newbieforever
Posts: 400
Joined: 24 Aug 2016, 03:34

Re: WinClose fails in OnMessage/ShellMessage

06 May 2019, 11:46

I know now that I completely misinterpreted my problem.

In my script the syntax-error window is not detected by OnMessage/ShellMessage! What could be the reason?
newbieforever
Posts: 400
Joined: 24 Aug 2016, 03:34

Re: WinClose fails in OnMessage/ShellMessage

06 May 2019, 12:30

Please forgive me for this bunch of newbie misunderstandings!

The error window was not detected because the OnMessage line was inserted too far down in the script...

Sorry...

Return to “Ask For Help”

Who is online

Users browsing this forum: Cerberus, nanotec89, rbinck, Rohwedder, SamSegal97, teadrinker and 70 guests