AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

close an ahk window

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
kobyashi



Joined: 09 May 2005
Posts: 7

PostPosted: Mon May 30, 2005 12:55 am    Post subject: close an ahk window Reply with quote

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
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Mon May 30, 2005 1:38 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kobyashi



Joined: 09 May 2005
Posts: 7

PostPosted: Mon May 30, 2005 12:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Mon May 30, 2005 1:06 pm    Post subject: Reply with quote

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... Wink

Try looking up Process in the index of the help file Smile
Back to top
View user's profile Send private message Visit poster's website
MYYM



Joined: 05 Apr 2005
Posts: 132

PostPosted: Mon May 30, 2005 1:33 pm    Post subject: Reply with quote

kobyashi wrote:
I want to do is close a script that has no UI, just hotkeys.


Read this, maybe it's what you need.

http://www.autohotkey.com/forum/viewtopic.php?t=3679&start=0&postdays=0&postorder=asc
Back to top
View user's profile Send private message Visit poster's website
kobyashi



Joined: 09 May 2005
Posts: 7

PostPosted: Tue May 31, 2005 11:54 am    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Wed Jun 01, 2005 8:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Mispent Intent
Guest





PostPosted: Thu Oct 06, 2005 9:30 pm    Post subject: GetModuleFileNameExA works Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group