 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Sat Nov 21, 2009 4:28 am Post subject: Problem with variables(?) - Works only outside a function |
|
|
Hey there!
So, can anybody explain to me:
#1 - why this next bit of script works if you press the hotkey repeatedly (what it does: effectively hides the taskbar on 1st and press and on 2nd press the taskbar shows, and so on...):
| Code: | x=1
+<::
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
x=1
Return
}
If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
x=0
Return
}
|
but not the same code inside a function (problem: 1st press of the hotkey hides the taskbar, the 2nd press of the hotkey won't show the taskbar again):
| Code: | x=1
+<::
Func(x)
Func(x)
{
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
x=1
Return
}
If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
x=0
Return
}
} |
#2 - If, there is a way of solving question #1 AND putting the first line of the script ("x=1") after the "+<::" line (inside it, i mean) and not b4 that?
Thanks 4 your help with this! |
|
| Back to top |
|
 |
entropic
Joined: 21 Dec 2008 Posts: 161
|
Posted: Sat Nov 21, 2009 4:39 am Post subject: |
|
|
This should work. [changes in red]
| Code: |
x = 1
+<::
x := Func(x)
return
Func(x)
{
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
Return 1
}
If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
Return 0
}
}
|
|
|
| Back to top |
|
 |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Sat Nov 21, 2009 5:07 am Post subject: |
|
|
Absolutely!! It does work!
Only now did i realize that everything that is placed b4 the hotkey is performed only once, when you start the *.ahk file, and, never again, even if you press the hotkey inside the script! Am i right?...shame on me...sorry 4 my dumbness there!
Thanks a lot 4 that man!
BTW, there's no chance of getting that "x=1" 1st line in the script inside the block of that hotkey, right? |
|
| Back to top |
|
 |
entropic
Joined: 21 Dec 2008 Posts: 161
|
Posted: Sat Nov 21, 2009 5:16 am Post subject: |
|
|
You are correct about it only being called once
I may be misunderstanding your question but...If you put x = 1 inside the function it will always call Func(1) so it will always hide the taskbar, if you want to break it up into two hotkeys it would be something like this.
| Code: |
+>::
Func(0)
return
+<::
Func(1)
return
Func(x)
{
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
}
If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
}
}
|
|
|
| Back to top |
|
 |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Sat Nov 21, 2009 5:31 am Post subject: |
|
|
Thanks again!
What i meant 2 ask was if there was a way of including th "x=1" 1st line in script after the "+<::", not split it into 1 hotkey 2 hide it and another hotkey 2 show it...i wanted 2 keep using the same hotkey 2 show hide the taskbar...but nevermind that question it was just for aesthetics, not leaving a declaration of a variable outside a hotkey command, got it?...really, it's dumb!
All problems solved! Thanks a LOT 4 your time and patience entropic ! |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Sat Nov 21, 2009 8:17 am Post subject: |
|
|
Try this
| Code: |
+<::
Func()
return
Func()
{
static x = 1
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
x = 1
}
Else If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
x = 0
}
} |
|
|
| Back to top |
|
 |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Sat Nov 21, 2009 8:02 pm Post subject: |
|
|
Now that's exactly what I was talking about b4!
That is fantastic a_h_k ! Really is!
Already tried that idea and it surely works as it should... flawlessly!
Seems I still have a long way 2 go 2 learn about how AHK works with variables!
Thanks a lot 4 all of your precious inputs!
BTW, it seemed a mistake but actually, I've found that if you repeat the line this way:
| Quote: | WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
|
99% of the times it'll hide the taskbar effectively, however if you don't it'll only hide it completely in like 60% of the times (it'll just be auto-hidden)... don't ask me why, but there you go!..you know...just in case...
Thanks again!
I've actually managed 2 learn stuff from your ideas! |
|
| Back to top |
|
 |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Sat Nov 21, 2009 10:47 pm Post subject: |
|
|
Hey guys!
Just 2 more questions...
1 - say i wana use the code by a_h_k and compile it 2 create an executable file that whenever executed Hides the taskbar, then, when executed a 2nd time shows the taskbar again...how would you guys do that?
2 - if that would be possible, is there any chance the Hotkey [Shift+<] could b mantained as an option 2 double clicking on the exe file again? i mean, the user would have 2 options: the option 2 toggle show/hide the taskbar pressing [Shift+<] or simply by double-clicking on the exe file?
Again, many thanks!
cheers! |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Sun Nov 22, 2009 2:28 am Post subject: Re: Problem with variables(?) - Works only outside a functio |
|
|
Just briefly going back to your 1st post..
| Code: | x=1
+<::
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
x=1
Return
}
If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
x=0
Return
}
Return ;just needed this here!
| So no need for Func()
Alternatively, if wanting to keep +<:: section minimal... (& using Gosub instead of function)
| Code: | +<::Gosub Routine
Routine:
If x=
x=1 ;as x starts off blank
If x=0
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
x=1
Return
}
If x=1
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
x=0
Return
}
Return ;note that both :: (hotkey) & : (normal) labels require a "Return"
|
|
|
| Back to top |
|
 |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Sat Nov 28, 2009 5:34 am Post subject: |
|
|
Hey!sorry i took soooo long replying...
Anyways, yup! both of your code examples work seamlessly which is great! thanks a_h_k !
Later i've come up with this somewhat simpler solution (do let me know what you think...):
| Code: |
+<::
If TaskabarAndStartToggler := !TaskabarAndStartToggler
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
Return
}
Else
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
Return
}
Return |
However, i'm still unable 2 complete the second task i set up 4 (making it work as an exe), because i can't find a way 2 have this thing working this way:
When a user starts the script/compiled exe of the script, it hides/shows the taskbar&start button immediately (without pressing a hotkey) depending on their state of visibility...then the scipt should close, and, if executed (started) again it should revert the taskbar 2 its previous state...
how would you guys do that?
i mean, what i'm going 4 here is 2 understand how 2 make it work as an .exe file 2 toggle the taskbar&start button on/off, either with the hotkey press OR by executing the .exe file...
thanks for your help/guidance with this!
cheers! |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Sat Nov 28, 2009 8:07 am Post subject: |
|
|
This will work for both running exe & pressing hotkey...
| Code: | #SingleInstance force
; Fetch current hidden/showing status of taskbar
;TaskbarAndStartToggleState = ?
Gosub +, ;Toggle the taskbar/SM state (showing->hidden or hidden->showing)
Exit ;Exit (or Return) = keeps script running in background (so can still use the +< (+,) hotkey)
+,:: ;how did this work before?? [edit: "<+" = left Shift key]
If TaskbarAndStartToggleState := !TaskbarAndStartToggleState
{
NumPut( ( ABS_ALWAYSONTOP := 0x2 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
Return
}
Else
{
DetectHiddenWindows, On
VarSetCapacity( APPBARDATA, 36, 0 )
NumPut( ( ABS_ALWAYSONTOP := 0x2 )|( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" )
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
WinHide ahk_class Shell_TrayWnd
Return
}
Return |
However, as the code shows, you will need to find a way to find the current hidden/showing status of the taskbar/sm
I also have been struggling to find the active/exist/etc (not show/hide) status of the taskbar today (for a script of mine)
- WinGet, MinMax = failed (as taskbar/sm are ALWAYS in "restored" state)
- IfWinExist("ahk_class Shell_TrayWnd") = failed (as ALWAYS "exist")
- IfWinActive("ahk_class Shell_TrayWnd") = failed (as must CLICK it to be "active")
Maybe theres some DllCall that can fetch this info for you?
Last edited by a_h_k on Mon Nov 30, 2009 3:01 pm; edited 1 time in total |
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 499 Location: Berlin / Germany
|
Posted: Sat Nov 28, 2009 9:04 am Post subject: |
|
|
| Code: | ; http://msdn.microsoft.com/en-us/library/ms633530%28VS.85%29.aspx
MsgBox, % DllCall("IsWindowVisible", UInt, WinExist("ahk_class Shell_TrayWnd")) ? "Visible" : "Hidden"
WinGet, Style, Style, ahk_class Shell_TrayWnd
MsgBox, % (Style & WS_VISIBLE := 0x10000000) ? "Visible" : "Hidden" |
_________________ nick
denick @ http://de.autohotkey.com/forum/ |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Sat Nov 28, 2009 3:17 pm Post subject: |
|
|
I actually tried DllCall("IsWindowVisible") before, for my own script, but it always returned 1, so i moved on to other methods
What is needed is for whatever method to return "1" when taskbar is showing, and return "0" when taskbar is hidden
(both these always return 1) |
|
| Back to top |
|
 |
blehmeco
Joined: 17 Nov 2009 Posts: 24
|
Posted: Mon Nov 30, 2009 11:30 am Post subject: |
|
|
Hey a_h_k!
i know you said you already tried this and all, but, hey!just trying 2 retribute something here!
Hope i'm not misunderstanding what you want 2 do, but, are sure this doesn't work?:
| Code: | +z::
IfWinExist, ahk_class Shell_TrayWnd
{
MsgBox Taskbar Exists
}
IfWinNotExist, ahk_class Shell_TrayWnd
{
MsgBox Taskbar does not exist
}
Return |
Cuz 4 me it works well, if you use 1 of the above scripts 2 hide/show the taskbar!
Hope that helps!
As soon as I get 2 test that other bit of script you showed, i'll report what i could do!
Cheers! |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Mon Nov 30, 2009 1:33 pm Post subject: |
|
|
No, it doesn't work for me .. it always returns "MsgBox Taskbar Exists"
I'm using WinXP Sp3, whats your os? |
|
| 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
|