VBA code to set taskbar to autohide

TylerTand

Registered User.
Local time
Today, 07:04
Joined
Aug 31, 2007
Messages
95
I would like to have this code run on database open and then set it back to locked when the database closes. I don't think that I will be able to make any registry changes so if this can be done with VBA that would be great. Thanks for your help,
Tyler:)
 
Thanks but I did a google search and just hiding the task bar isn't what I wanted to do. I just wanted to clean up my database look but still give people the option to bring up the task bar by doing a mouse over. Since I'm not about to go around and set all the computers to autohide the task bar I was hoping I could do it with code while my db is open. If you have any idea about how to do what I asked please share them. Thanks.
 
Thanks but I did a google search and just hiding the task bar isn't what I wanted to do. I just wanted to clean up my database look but still give people the option to bring up the task bar by doing a mouse over. Since I'm not about to go around and set all the computers to autohide the task bar I was hoping I could do it with code while my db is open. If you have any idea about how to do what I asked please share them. Thanks.

I wrote this just for kicks a while ago, seems like it's what you're wanting to do.

Code:
Const ABS_AUTOHIDE = &H1
Const ABS_ONTOP = &H2
Const ABM_SETSTATE = 10

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Type APPBARDATA
    cbSize As Long
    hwnd As Long
    uCallbackMessage As Long
    uEdge As Long
    rc As RECT
    lParam As Long '  message specific
End Type
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long
Sub HideTaskBar()

Dim ABD As APPBARDATA, Ret As Long

ABD.lParam = ABS_AUTOHIDE Or ABS_ONTOP

Ret = SHAppBarMessage(ABM_SETSTATE, ABD)

End Sub

Sub UnHideTaskBar()

Dim ABD As APPBARDATA, Ret As Long

ABD.lParam = ABS_ONTOP

Ret = SHAppBarMessage(ABM_SETSTATE, ABD)

End Sub
 
Hey DJKarl thanks for the code.
I have a question though. My VBA skills are still developing themselves. Can you tell me which part will go on the Form On Open Event Procedure? I am trying to follow your code but I get a little lost. It appears to me that you are defining variables in this section:
Const ABS_AUTOHIDE = &H1
Const ABS_ONTOP = &H2
Const ABM_SETSTATE = 10


Then you define some variables for "Private Type":
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type APPBARDATA
cbSize As Long
hwnd As Long
uCallbackMessage As Long
uEdge As Long
rc As RECT
lParam As Long ' message specific
End Type

I have never used a Private type before so I don't know where to put this.

I don't know what this part does either:
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long

I believe that the actual event procedure that goes behind a button or on the on open event procedure is this part:
Sub HideTaskBar()

Dim ABD As APPBARDATA, Ret As Long

ABD.lParam = ABS_AUTOHIDE Or ABS_ONTOP

Ret = SHAppBarMessage(ABM_SETSTATE, ABD)

End Sub

And the Event Procedure to Unhide the Task bar is this part:
Sub UnHideTaskBar()

Dim ABD As APPBARDATA, Ret As Long

ABD.lParam = ABS_ONTOP

Ret = SHAppBarMessage(ABM_SETSTATE, ABD)

End Sub


The problem is that I don't know where to put the variable definitions at the beginning? I have been taught to define the variable at the beginning of the Sub. I have never seen or used a "Private Type" before. Can you break this up for me so that I know where to put each of the parts? I would really appreciate it. This is something that I have been trying to get working for quite some time now. Thanks,
Tyler:)
 
I would place all of this into a public module and then just call the Subs on the form load / unload events.

Code:
Const ABS_AUTOHIDE = &H1
Const ABS_ONTOP = &H2
Const ABM_SETSTATE = 10

Code:
Then you define some variables for "Private Type":
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Type APPBARDATA
    cbSize As Long
    hwnd As Long
    uCallbackMessage As Long
    uEdge As Long
    rc As RECT
    lParam As Long '  message specific
End Type

I have never used a Private type before so I don't know where to put this.
Types are nothing special, they are required for certain API's and can make dealing with certain situations much easier. The placement of these depends on what uses them, generally I place them after constants but before any API declarations.


I don't know what this part does either:
Code:
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long

This is a Windows API call, the function SHAppBarMessage actually resides in the shell32.dll file. This allows you to use that function in your program.


I believe that the actual event procedure that goes behind a button or on the on open event procedure is this part:

I would place a call to the HideTaskBar sub in your Forms Load Event.

Code:
Sub HideTaskBar()

Dim ABD As APPBARDATA, Ret As Long

ABD.lParam = ABS_AUTOHIDE Or ABS_ONTOP

Ret = SHAppBarMessage(ABM_SETSTATE, ABD)

End Sub

And the Event Procedure to Unhide the Task bar is this part:

And a call to the UnHideTaskBar Sub in your Forms Unload event.
Code:
Sub UnHideTaskBar()

Dim ABD As APPBARDATA, Ret As Long

ABD.lParam = ABS_ONTOP

Ret = SHAppBarMessage(ABM_SETSTATE, ABD)

End Sub

The problem is that I don't know where to put the variable definitions at the beginning? I have been taught to define the variable at the beginning of the Sub. I have never seen or used a "Private Type" before. Can you break this up for me so that I know where to put each of the parts? I would really appreciate it. This is something that I have been trying to get working for quite some time now. Thanks,
Tyler:)

Code:
Form_Load()
 HideTaskBar
End Sub

Form_UnLoad()
 UnHideTaskBar
End Sub
 

Users who are viewing this thread

Back
Top Bottom