Controlling the windows taskbar from VBA (API example)

J

John Keith

I found this code on another post and it works perfectly... however (see below)

Private Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1&, ByVal hWnd2&, ByVal lpsz1$, ByVal lpsz2$)
Private Declare Function ShowWindow& Lib "user32" (ByVal hwnd&, ByVal
nCmdShow&)

Sub TaskBar_Hide()
ShowWindow FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString), 0
End Sub

Sub TaskBar_Show()
ShowWindow FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString), 5
End Sub

However,
This seems to be setting a visible flag for the task bar. What I need is to
activate/deactivate the minimize of the task bar. (When you position the
mouse on the top line of the task bar, you get a double-headed arrow. when
you click-drag down, it minimizes the task bar. This leaves a small line
which is the top of the task bar that you can grab and drag up to un-minimize
the task bar).

How do I access that feature from VBA (using API or not)

I need this so that when I set my spreadsheet to show fullscreen, the status
bar gets hidden under the taskbar (becuse I want to leave it set "always on
top") I have found that manually minimizing then maximizing the taskbar
forces the status bar to show (I.E. the spreadsheet's full screen becomes
limited at the bottom to force both the taskbar and the (excel) statusbar to
be both visible.)

Also Im curious what the & in the above "FindWindowEx&" API call code does.
The code stops working when that character is removed.
 
M

Michel Pierron

Hi John,
The & is the symbol of a Long type of variable
The $ is the symbol of a String type of variable

To show fullscreen, change the work area like this:

Option Explicit
Private Declare Function SystemParametersInfoA& _
Lib "user32" (ByVal uAction&, ByVal uParam& _
, lpvParam As Any, ByVal fuWinIni&)
Private Declare Function GetWindowRect& Lib _
"user32" (ByVal hwnd&, lpRect As RECT)
Private Declare Function FindWindowA& Lib _
"user32" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function ShowWindow& Lib _
"user32" (ByVal hwnd&, ByVal nCmdShow&)

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private hwnd&, Desktop As RECT

' Warning: this may reorder desktop icons
Sub TaskBar_Hide()
Application.ScreenUpdating = False
Dim TaskBar As RECT
hwnd = FindWindowA("Shell_traywnd", "")
' Get TaskBar area
GetWindowRect hwnd, TaskBar
' Get Desktop area
SystemParametersInfoA 48, 0&, Desktop, 0&
' Set Full screen area and hide TaskBar
TaskBar.Bottom = (TaskBar.Bottom - TaskBar.Top) _
+ (Desktop.Bottom - Desktop.Top)
TaskBar.Top = Desktop.Top
TaskBar.Left = Desktop.Left
TaskBar.Right = Desktop.Right
ShowWindow hwnd, 0
SystemParametersInfoA 47, 0, TaskBar, 0
AppActivate Application.Caption
Application.WindowState = xlNormal
Application.WindowState = xlMaximized
End Sub

Sub TaskBar_Show()
Application.ScreenUpdating = False
' Restore desktop area
SystemParametersInfoA 47, 0, Desktop, 0
' Show TaskBar
ShowWindow hwnd, 8
Application.WindowState = xlNormal
Application.WindowState = xlMaximized
End Sub

Regards,
MP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top