AutoHotkey Community

It is currently May 27th, 2012, 1:32 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: November 21st, 2009, 5:28 am 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 5:39 am 
Offline

Joined: December 21st, 2008, 7:29 pm
Posts: 181
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
   }
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 6:07 am 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
Absolutely!! It does work! :D

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!:roll:

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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 6:16 am 
Offline

Joined: December 21st, 2008, 7:29 pm
Posts: 181
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
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 6:31 am 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
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 !:wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 9:17 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
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
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 9:02 pm 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 11:47 pm 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
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!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 22nd, 2009, 3:28 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
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"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 6:34 am 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 9:07 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
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 November 30th, 2009, 4:01 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 10:04 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
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 :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 4:17 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2009, 12:30 pm 
Offline

Joined: November 17th, 2009, 1:49 am
Posts: 25
Hey a_h_k!
i know you said you already tried this and all, but, hey!just trying 2 retribute something here!:D
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2009, 2:33 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
No, it doesn't work for me .. it always returns "MsgBox Taskbar Exists"
I'm using WinXP Sp3, whats your os?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Blackholyman, bobbysoon, iDrug, Ohnitiel, Tipsy3000, Yahoo [Bot] and 18 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