 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
toralf
Joined: 31 Jan 2005 Posts: 3910 Location: Bremen, Germany
|
Posted: Wed Feb 02, 2005 3:39 pm Post subject: Showcase for two windows with interaction |
|
|
During the last days I have learnd a bit about AHK. Mainly I was interessted in how two windows can interact with each other. So here is a small showcase. Other Newbies like me might find it interesting. Any suggestion/hint regarding improvement (stable/learn effect) is appreciated.
| Code: | ; Showcase for two windows with interaction
; tested OS: Windows XP Pro
; AHK version: 1.0.26.00
; Date: 2005-02-14
Windowtitle1 = First Window
Windowtitle2 = Second Window
; GUI of 1st window
Gui, 1:Add, Checkbox, x10 y10 vCkbEditSimu , &Edit both windows simultaneously
Gui, 1:Add, Button, y+10 vBtnOpen2ndWindow gBtnOpen2ndWindow , &Open 2nd window
Gui, 1:Add, Text, y+10 vTxtNumber2ndWindow , Number from 2nd Window:
Gui, 1:Add, Edit, r1 ReadOnly vEdtNumber2ndWindow x+5 yp-3 w40,
Gui, 1:Add, Edit, r5 xs y+10 w172 vEdtEdit1stWindow , Try to edit this field when 2nd window is open
Gui, 1:Add, Button, Default xs+135 , &Close
; GUI of 2nd window, which is owned by 1st window
Gui, 2:+owner1
Gui, 2:Add, Text , x10 y10 , Input Number:
Gui, 2:Add, Edit , r1 Number Limit2 x+5 yp-3 w40 vEdtNumber, 10
Gui, 2:Add, Button, Default xs+30 y+5 , &Apply
Gui, 2:Add, Button, v2ndCancel g2ndCancel x+0 , &Cancel
; Show 1st window
Gui, 1:Show, x100 y100 , %Windowtitle1%
Return
; +++++++++++++++++++++++ End of auto-execute +++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Open 2nd window
BtnOpen2ndWindow:
; get value of CkbEditSimu
Gui, 1:Submit, NoHide
; open 2nd window
Gui, 2:Show ,x350 y100, %Windowtitle2%
; if simultaneous edit is active ...
if CkbEditSimu
{ ; ... disable the open-button to open another 2nd window
GuiControl, 1:Disable, BtnOpen2ndWindow
}
else
{ ; ... otherwise hide the Cancel-Button, so that user can only press Apply-Button
GuiControl, 2:Hide, 2ndCancel ; Auto-Label doesn't work, Button needs variabel
; set 1st window inactive
Gui, 1: +Disabled
}
return
; +++++++++++++++++++ Apply Number from 2nd window into field of 1st window
2ButtonApply:
; get variable in field, if simultaneous edit keep window otherwise hide it
if CkbEditSimu
Gui, 2:Submit, NoHide
else
{
Gui, 2:Submit
GoSub, 2ndCancel
}
; set number into field of 1st "1:" window (important, AHK needs to know which GUI)
GuiControl,1:,EdtNumber2ndWindow,%EdtNumber%
; increase the number in the Apply field for easier testing
NewInput := EdtNumber + 1
GuiControl,2:,EdtNumber, %NewInput%
return
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Closing 2nd window
2ndCancel:
2GuiClose: ; 2GuiClose = GuiClose of second window
;restore all options of controla and GUI to normal
Gui, 1: -Disabled
GuiControl, 1:Enable, BtnOpen2ndWindow
GuiControl, 2:Show, 2ndCancel
;set focus on first window
WinActivate, %Windowtitle1%
; "Gui, 2:Cancel" keeps window in memory, so it can be opened again.
; "Gui, 2:Destroy" would release the memory but the window couldn't be open again.
Gui, 2:Cancel
return
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Exiting 1st window
ButtonClose:
GuiClose:
ExitApp |
I have run the script at home and at work. The differnce is that at home the windows pop up at the correct position. At work they initially pop up at in the center of the screen. Only when the 2nd window pops up a second time, it is at the correct position. Does anyone have an idea why? Is it because I do not have admin rights and AHK might not be fully installed?
EDIT:
- Updated the script with new 1.0.26.00 function for Gui, +/-Disabled
- Improved indentations
- removed the winwait, instead put restore of controls and GUI in the closing subroutine. _________________ Ciao
toralf 
Last edited by toralf on Mon Feb 14, 2005 8:30 am; edited 1 time in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Feb 02, 2005 3:42 pm Post subject: |
|
|
| Quote: | | I have run the script at home and at work | Both boxes having the same requirements ? OS? SP? AHK? Environment? Hardware? |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3910 Location: Bremen, Germany
|
Posted: Wed Feb 02, 2005 3:44 pm Post subject: |
|
|
Hardware: No
AHK: Yes
OS: Yes
Environment: Most likely not _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Wed Feb 02, 2005 5:01 pm Post subject: |
|
|
| I can't think of an explanation other than some OS setting or installed utility that automatically centers windows when they are first created. To work around this, you could try issuing the "Gui Show" command twice in a row. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3910 Location: Bremen, Germany
|
Posted: Wed Feb 02, 2005 5:17 pm Post subject: |
|
|
That workaround does it's job, although it causes some flicker.
I would even like to get ride of the "Gui, 1:Show" after the 1st window is set back to be active. It causes the window to flicker.
I tried it without that command and it works, the only drawback is that it is not in the forground. Is there a differentway to get the 1st window to foreground? Or does this cause other problems.
I tried "WinActivate, %Windowtitle1%". It doesn't causes the window to flicker bt is shown a split second behind a differnt window. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Feb 02, 2005 5:20 pm Post subject: |
|
|
| Active Desktop? Centered ? |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3910 Location: Bremen, Germany
|
Posted: Wed Feb 02, 2005 5:28 pm Post subject: |
|
|
I do not know how to find out,
I have checked the properties of the desktop, but nothing is pointing in that direction.
But might be, since I'm in a big company I might not even have enough rights to find out or change it anyway. Thanks for the help. I think I just have to live with it.
Schönen Feierabend und bis Morgen beim Karneval _________________ Ciao
toralf  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3910 Location: Bremen, Germany
|
Posted: Mon Feb 14, 2005 8:31 am Post subject: |
|
|
I have updated the first post to include new functionality of AHK and improved the structure. _________________ Ciao
toralf  |
|
| 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
|