 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
kobyashi
Joined: 09 May 2005 Posts: 7
|
Posted: Mon May 30, 2005 12:55 am Post subject: close an ahk window |
|
|
none of the things i've tried seem to work. any help?
| Code: |
If WinExist(LastScriptFile)
{
SoundBeep
MsgBox, %ScriptFile%, %LastScriptFile%
SendMessage, 0x111, 65307, 0
WinClose
ControlSend, ahk_parent, !{F4}
}
|
I'm trying to close a script whose name is in the variable LastScriptFile |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2436
|
Posted: Mon May 30, 2005 1:38 am Post subject: |
|
|
Test script (named testapp.ahk): | Code: | Gui, Add, Text,, Current AutoHotkey version:%A_Space%%A_AhkVersion%
Gui, Show,, Test App
Return
GuiClose:
ExitApp
|
Close test script | Code: | Run, testapp.ahk
LastScriptFile = Test App
WinWait, %LastScriptFile%
If WinExist(LastScriptFile)
{
MsgBox, %LastScriptFile%%A_Space%window found.
WinClose, %LastScriptFile%
} |
|
|
| Back to top |
|
 |
kobyashi
Joined: 09 May 2005 Posts: 7
|
Posted: Mon May 30, 2005 12:24 pm Post subject: |
|
|
| Well sure that works, just like closing any random window does with WinClose. But what I want to do is close a script that has no UI, just hotkeys. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2436
|
Posted: Mon May 30, 2005 1:06 pm Post subject: |
|
|
| kobyashi wrote: | | Well sure that works, just like closing any random window does with WinClose. But what I want to do is close a script that has no UI, just hotkeys. | It might have helped to have known that info...
Try looking up Process in the index of the help file  |
|
| Back to top |
|
 |
MYYM
Joined: 05 Apr 2005 Posts: 132
|
|
| Back to top |
|
 |
kobyashi
Joined: 09 May 2005 Posts: 7
|
Posted: Tue May 31, 2005 11:54 am Post subject: |
|
|
Yes that works strangely. The thing is, without the SetTitleMatch, the window is found with WinExist() but isn't closable.
What I really want is to open and close scripts for diferent kinds of windows. I am currently using window titles to do this because the following code always returns autohotkey.exe for the module
| Code: |
WinGet, pid, pid, A
;MsgBox PID = %pid%
hProcess := DllCall("OpenProcess", "int", 0x410, "int", 0, "int", pid)
;MsgBox %ErrorLevel%. hProcess = %hProcess%
VarSetCapacity(szProcess, 260)
hMods := 0 ; set up some memory
cbNeeded := 0
DllCall("psapi\EnumProcessModules", "int", hProcess, "int *", hMods, "int", 4, "int *", cbNeeded)
;MsgBox %ErrorLevel%. PID = %pid%, hProcess = %hProcess%, Module = %hMods%
DllCall("GetModuleFileName", "int",hMods,"str", szProcess, "int", 260)
;DllCall("GetModuleFileNameEx", "int", hProcess,"int",hMods,"str", szProcess, "int", 260)
DllCall("CloseHandle", "int", hProcess)
MsgBox %ErrorLevel%. PID = %pid%, hProcess = %hProcess%, Module = %hMods% file = %szProcess%
Title := szProcess
SplitPath, szProcess, ,,,Title
|
This is code adapted from MSDN sample code on module enumeration.
Any thoughts?
Here's the block of code that uses the variable Title to actually run/close scripts based on the current window (this code is on a 50ms timer loop)
| Code: |
ScriptFile := Title . ".ahk"
;ScriptFile = %ScriptFile%
Empty :=
SplitPath, title,,,ext
if (ext != "ahk" && Title != Empty && ScriptFile != LastScriptFile)
{
;GuiControl, Text, DebugOut, %ScriptFile%
;GuiControl, Text, DebugOut, %ext%
;If LastScriptFile
;MsgBox, %ScriptFile%, %LastScriptFile%)
DetectHiddenWindows, On
; i don't like the looks of this...
SetTitleMatchMode, 2
IfWinExist, %LastScriptFile%
{
;SoundBeep
;MsgBox, %ScriptFile%, %LastScriptFile%
;WinGet, id, id
;MsgBox, %id%
;SendMessage, 0x111, 65307, 0, ahk_id %id%
WinClose
;ControlSend, ahk_parent, !{F4}
}
;LastScriptFile :=
;MsgBox, %A_scriptdir%\%ScriptFile%, %LastScriptFile%)
IfExist, %A_scriptdir%\Specific\%ScriptFile%
{
;SoundBeep
run, "%A_scriptdir%\Specific\%ScriptFile%"
}
LastScriptFile := ScriptFile
}
|
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Wed Jun 01, 2005 8:37 pm Post subject: |
|
|
| kobyashi wrote: | | But what I want to do is close a script that has no UI, just hotkeys. | The script/hotkey here should definitely work. If it doesn't, please post the relevant part of your script that fails to close some other script even though it uses DetectHiddenWindows, SetTitleMatchMode, and WinClose. |
|
| Back to top |
|
 |
Mispent Intent Guest
|
Posted: Thu Oct 06, 2005 9:30 pm Post subject: GetModuleFileNameExA works |
|
|
SetTitleMatchMode 2
WinGet, pid, pid, A
;;WinGet, pid, PID, Total Commander
;;MsgBox PID = %pid%
IfEqual, pid,0, return
hProcess := DllCall("OpenProcess", "int", 0x410, "int", 0, "int", pid)
;;MsgBox %ErrorLevel%. hProcess = %hProcess%
IfEqual, hProcess,0, return
VarSetCapacity(szProcess, 260)
cbNeeded := 0
DllCall("psapi\GetModuleFileNameExA", "int",hProcess, "int",0, "str",szProcess, "int",260 )
MsgBox %ErrorLevel%. PID = %pid%, hProcess = %hProcess%, file = %szProcess%
DllCall("CloseHandle", "int", hProcess)
Title := szProcess
SplitPath, szProcess, ,,,Title
MsgBox Title = %Title% |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|