#IfWinExist gui Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

#IfWinExist gui

25 Aug 2017, 08:40

Good morning fellow AHK'ers,

I'm trying to use #IfWinExist with my GUI to have active hotkeys only when the GUI is active, but unfortunately I'm not figuring out how to get this to work.

Also is it possible to have duplicate hotkeys while #IfWinExist is in affect or not.

Please advise, thank you! :)

Code: Select all

AOCoverage:
Gui, 2:+AlwaysOnTop +HwndAnalysisHandle +LastFound
Gui, 2:Add, Progress, % "x9 y9 w402 h137 +Disabled Background" . BorderColor . ""
Gui, 2:Add, Picture, x10 y10 w400 h135, %ThemeDir%\Analysis.jpg
Gui, 2:Font, S52 c%TextColor% Underline, Times New Roman
Gui, 2:Add, Text, x40 y150 w350 h80 +BackgroundTrans, ANALYSIS
Gui, 2:Font,S12 Normal Bold, Calibri
Gui, 2:Add, Button, Default x40 y240 w100 h80 gOpen, Partial
Gui, 2:Add, Button, x150 y240 w100 h80 gFinal, Final
Gui, 2:Add, Button, x260 y240 w100 h80 vAfterClose gAfterClose, After close
Gui, 2:Color, %Gui_Color%
Gui, 2:Show,, Analysis
Exit

#IfWinExist ahk_id AnalysisHandle
	p::Goto, Open
	f::Goto, Final
	a::Goto, AfterClose
	ESC::Gui, 2:Destroy
Exit

2GuiClose:
Gui,2:destroy
Exit

Open:
Gui,2:submit
Gui,2:destroy
PayType := "Open"

Final:
Gui,2:submit
Gui,2:destroy
PayType := "Final"

AfterClose:
Gui,2:submit
Gui,2:destroy
PayType := "AfterClose"
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: #IfWinExist gui  Topic is solved

25 Aug 2017, 09:15

Trigg wrote:I'm trying to use #IfWinExist with my GUI to have hotkeys active only when the GUI is ACTIVE, but unfortunately I'm not figuring out how to get this to work.
It sounds like you want to use #IfWinActive not #IfWinExist, you must also put #IF at the end of the context sensitive hotkeys.

Also it appears your code is missing some returns after labels, and Exit where a return should be?

However if you are using just those hotkeys with your GUI, might I suggest this instead:

Code: Select all

AOCoverage:
Gui, 2:+AlwaysOnTop +HwndAnalysisHandle +LastFound
Gui, 2:Add, Progress, % "x9 y9 w402 h137 +Disabled Background" . BorderColor . ""
Gui, 2:Add, Picture, x10 y10 w400 h135, %ThemeDir%\Analysis.jpg
Gui, 2:Font, S52 c%TextColor% Underline, Times New Roman
Gui, 2:Add, Text, x40 y150 w350 h80 +BackgroundTrans, ANALYSIS
Gui, 2:Font,S12 Normal Bold, Calibri
Gui, 2:Add, Button, Default x40 y240 w100 h80 gOpen, &Partial ; Notice the Ampersand before the letter you want to be a shortcut to this button.
Gui, 2:Add, Button, x150 y240 w100 h80 gFinal, &Final ; Notice the Ampersand before the letter you want to be a shortcut to this button.
Gui, 2:Add, Button, x260 y240 w100 h80 vAfterClose gAfterClose, &After close ; Notice the Ampersand before the letter you want to be a shortcut to this button.
Gui, 2:Color, %Gui_Color%
Gui, 2:Show,, Analysis
Return

2GuiEscape: ; Will launch when you press Escape with the GUI Active
2GuiClose:
Gui,2:destroy
Return

Open:
Gui,2:submit
Gui,2:destroy
PayType := "Open"
Return

Final:
Gui,2:submit
Gui,2:destroy
PayType := "Final"
Return

AfterClose:
Gui,2:submit
Gui,2:destroy
PayType := "AfterClose"
Return
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: #IfWinExist gui

25 Aug 2017, 09:19

Nightwolf85 wrote:
Trigg wrote:I'm trying to use #IfWinExist with my GUI to have ACTIVE hotkeys only when the GUI is active, but unfortunately I'm not figuring out how to get this to work.
It sounds like you want to use #IfWinActive not #IfWinExist, you must also put #IF at the end of the context sensitive hotkeys.

Also it appears your code is missing some returns after labels, and Exit where a return should be?

However if you are using just those hotkeys with your GUI might I suggest this instead:
My apologies, the reason was because they go to another part of the script "AnalysisStart:". But 2GuiEscape is something you just taught me so thank you ! :)

I added the & and that worked. Thank you for clearing this up!

Code: Select all

AOCoverage:
Gui, 2:Add, Progress, % "x9 y9 w402 h137 +Disabled Background" . BorderColor . ""
Gui, 2:Add, Picture, x10 y10 w400 h135, %ThemeDir%\Analysis.jpg
Gui, 2:Font, S52 c%TextColor% Underline, Times New Roman
Gui, 2:Add, Text, x40 y150 w350 h80 +BackgroundTrans, ANALYSIS
Gui, 2:Font,S12 Normal Bold, Calibri
Gui, 2:Add, Button, Default x40 y240 w100 h80 gOpen, &Partial
Gui, 2:Add, Button, x150 y240 w100 h80 gFinal, &Final
Gui, 2:Add, Button, x260 y240 w100 h80 gAfterClose, &After close
Gui, 2:Color, %Gui_Color%
Gui, 2:Show,, Analysis GUI
Exit

2GuiEscape:
2GuiClose:
Gui,2:destroy
Exit

Open:
Gui,2:submit
Gui,2:destroy
PayType := "Open"
Goto, AnalysisStart

Final:
Gui,2:submit
Gui,2:destroy
PayType := "Final"
Goto, AnalysisStart

AfterClose:
Gui,2:submit
Gui,2:destroy
PayType := "AfterClose"
Goto, AnalysisStart

AnalysisStart:
MsgBox % Paytype
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: #IfWinExist gui

25 Aug 2017, 09:26

Did the Ampersand before the letter not work? that way you can get rid of the context hotkeys all together.

Edit, just saw your edit. Good to hear it works.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], BurrowBird, c7aesa7r, Google [Bot], nutnutwin, PuzzledGreatly and 33 guests