Set/Get the ShowInTaskbar property for a window at runtime
VB Code:
'You need 2 command buttons 'cmdToggle' and 'cmdCheck'
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_APPWINDOW = &H40000
Const SW_HIDE = 0
Const SW_NORMAL = 1
Private Sub ShowInTheTaskbar(hwnd As Long, bShow As Boolean)
Dim lStyle As Long
ShowWindow hwnd, SW_HIDE
lStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
If bShow = False Then
If lStyle And WS_EX_APPWINDOW Then
lStyle = lStyle - WS_EX_APPWINDOW
End If
Else
lStyle = lStyle Or WS_EX_APPWINDOW
End If
SetWindowLong hwnd, GWL_EXSTYLE, lStyle
App.TaskVisible = bShow
ShowWindow hwnd, SW_NORMAL
End Sub
Private Function IsVisibleInTheTaskbar(hwnd As Long) As Boolean
Dim lStyle As Long
lStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
If lStyle And WS_EX_APPWINDOW Then
IsVisibleInTheTaskbar = True
End If
End Function
Private Sub cmdToggle_Click()
Static bVisible As Boolean
bVisible = Not IsVisibleInTheTaskbar(Me.hwnd)
ShowInTheTaskbar Me.hwnd, bVisible
End Sub
Private Sub Form_Load()
cmdToggle.Caption = "Toggle visibility"
cmdCheck.Caption = "Check visibility"
End Sub
Re: Set/Get the ShowInTaskbar property for a window
Re: Set/Get the ShowInTaskbar property for a window
Thanks :thumb: Just altered a bit of code I found here and made them functions/subs :)
Re: Set/Get the ShowInTaskbar property for a window at runtime
Is (lStyle-WS_EX_APPWINDOW) the same as (lStyle And Not WS_EX_APPWINDOW) ?
And, doesn't WS_EX_APPWINDOW also have something to do with the form borderstyle?
Re: Set/Get the ShowInTaskbar property for a window at runtime
I think WS_EX_APPWINDOW can affect the borderstyle if you "or" it with some other constants (I assume that WS_ stands for Window Style?)...
And yes, (lStyle-WS_EX_APPWINDOW) is the same as (lStyle And Not WS_EX_APPWINDOW).
Re: Set/Get the ShowInTaskbar property for a window at runtime
Great code manavo. I just needed something like this. I'm glad I checked the codebank. :thumb:
BTW - In you example cmdCheck does nothing. Just thought I'd let you know.
Re: Set/Get the ShowInTaskbar property for a window at runtime
Oops :blush: Good catch eyeR! I had it to just have a msgbox and call the IsVisible... function, nothing much :)
Re: Set/Get the ShowInTaskbar property for a window at runtime
Nice code Philip! :thumb:
WS_EX_???????? = Extended Window Style Or Window Style Extended