Page 1 of 1

WinClose fails in OnMessage/ShellMessage

Posted: 06 May 2019, 09:03
by newbieforever
Hi! EDITED:'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


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")


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.

Dec2hex(n) {
  oIF := A_FormatInteger
  SetFormat, Integer, hex
  n := StrLen(n+0) ? n+0 : n
  SetFormat, Integer, % oIF
  Return n

Re: WinClose fails in OnMessage/ShellMessage

Posted: 06 May 2019, 11:46
by newbieforever
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?

Re: WinClose fails in OnMessage/ShellMessage

Posted: 06 May 2019, 12:30
by newbieforever
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...