VB and VBA Users Source Code: Setting a forms ShowInTaskbar property a runtime
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Setting a forms ShowInTaskbar property a runtime
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, February 01, 2002
Hits:
1045
Category:
Windows API
Article:
The following code alters a forms ShowInTaskbar property at runtime. 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 'Purpose : Sets the forms ShowInTaskbar style bit at runtime 'Inputs : lWinHwnd The forms window handle ' bVisible If True shows the form in the taskbar. 'Outputs : N/A 'Author : Andrew Baker (copyright www.vbusers.com) 'Date : 31/Jan/2002 'Notes : 10 Apr 2004 - Bug fix 'Revisions : Public Sub FormShowInTaskbar(lWinHwnd As Long, bVisible As Boolean) Const SW_HIDE = 0, SW_SHOW = 5, GWL_EXSTYLE = (-20) ', WS_EX_TOOLWINDOW = &H80& Const WS_EX_APPWINDOW = &H40000 Dim lRetVal As Long, lCurrentExStyle As Long 'First hide window lRetVal = ShowWindow(lWinHwnd, SW_HIDE) DoEvents 'Now set the extended style bit to switch the Toolwindow lCurrentExStyle = GetWindowLong(lWinHwnd, GWL_EXSTYLE) If bVisible Then lCurrentExStyle = lCurrentExStyle Or WS_EX_APPWINDOW lRetVal = SetWindowLong(lWinHwnd, GWL_EXSTYLE, lCurrentExStyle) Else lCurrentExStyle = lCurrentExStyle And Not WS_EX_APPWINDOW lRetVal = SetWindowLong(lWinHwnd, GWL_EXSTYLE, lCurrentExStyle) End If DoEvents 'Show the window lRetVal = ShowWindow(lWinHwnd, SW_SHOW) End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder