 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
psjw12
Joined: 10 May 2007 Posts: 25
|
Posted: Fri Apr 25, 2008 12:26 pm Post subject: Destroy gui regardless of number |
|
|
I'm making a program like msn so gui's need to be generated with each new chat which I've already done. However rather than typing "2GuiClose: 3GuiClose: 4GuiClose:... Gui, Destroy" Can I make it so that any gui closed is destroyed rather than hidden because at the moment the code that generates gui's is limited to 99 chat windows even if all old ones where closed because it still see's that they exist.
The only exception is Gui 1, which has a list of users and when that closes I need the script to exit. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Fri Apr 25, 2008 2:41 pm Post subject: |
|
|
Seems to work:
| Code: | Gui, 1:Show, x40 y150 w150 h100,Gui-1
Gui, 2:Show, x250 y150 w150 h100,Gui-2
Gui, 3:Show, x450 y150 w150 h100,Gui-3
OnMessage( 0x18, "WM_SHOWWINDOW")
Return
WM_SHOWWINDOW( wParam, lParam ) {
if ( wParam=0 and A_Gui <> 1 )
Gui, %A_Gui%:Destroy
} |
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Fri Apr 25, 2008 2:57 pm Post subject: |
|
|
On a related note, you may ascertain an unused GUI number as follows:
| Code: | Gui, 1:Show
Gui, 2:Show
Gui, 4:Show
MsgBox, % Gui() ; an unused GUI number
Gui() {
Loop 99 {
Gui, %A_Index%:+LastFoundExist
IfWinNotExist,,,,,Return, A_Index
}
Return Null
} |
 |
|
| Back to top |
|
 |
psjw12
Joined: 10 May 2007 Posts: 25
|
Posted: Fri Apr 25, 2008 3:05 pm Post subject: |
|
|
Thanks that works
The only problem is that every time I exit the application I get a windows error message
---------------------------
AutoHotkey.exe - Application Error
---------------------------
The instruction at "0x0043e4e3" referenced memory at "0x00d50d0c". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
---------------------------
OK Cancel
---------------------------
But that will only occur if any chat windows are open, it's ok when none are open. I guess I'll have to find a way around that. Is there a way to stop the onmessage function running when the script has began it's exit routine? |
|
| Back to top |
|
 |
psjw12
Joined: 10 May 2007 Posts: 25
|
Posted: Fri Apr 25, 2008 3:07 pm Post subject: |
|
|
| Found a solution, make the onmessage go to a non-existing function before closing. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Fri Apr 25, 2008 3:14 pm Post subject: |
|
|
| psjw12 wrote: | | make the onmessage go to a non-existing function |
Simply OnMessage( 0x18, "" ) would suffice.  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Sat Apr 26, 2008 6:33 am Post subject: |
|
|
I just wanted to mention that this technique would produce undesireable effect when some other program tries to hide your GUIs. ( like "minimize to tray" )
Edit: The following version should be better
| Code: | sPID := DllCall("GetCurrentProcessId")
Gui, 1:Show, x40 y150 w150 h100,Gui-1
Gui, 2:Show, x250 y150 w150 h100,Gui-2
Gui, 3:Show, x450 y150 w150 h100,Gui-3
OnMessage( 0x18, "WM_SHOWWINDOW")
Return
WM_SHOWWINDOW( wParam, lParam, Msg, hWnd ) {
Global sPID
WinGet,PID,PID, ahk_id %hWnd%
if ( wParam=0 and A_Gui <> 1 and PID=sPID )
Gui, %A_Gui%:Destroy
} |
|
|
| 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
|