AutoHotkey Community

It is currently May 25th, 2012, 6:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: February 2nd, 2005, 4:39 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Last edited by toralf on February 14th, 2005, 9:30 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 4:42 pm 
Quote:
I have run the script at home and at work
Both boxes having the same requirements ? OS? SP? AHK? Environment? Hardware?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 4:44 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Hardware: No
AHK: Yes
OS: Yes
Environment: Most likely not

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 6:01 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 6:17 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 6:20 pm 
Active Desktop? Centered ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 6:28 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2005, 9:31 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I have updated the first post to include new functionality of AHK and improved the structure.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher, kiropes, lblb, nothing, rbrtryn and 41 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group