ControlBox after runtime?

Is there any way to change the value of both the ControlBox and ShowInTaskbar of a form after runtime? Such as changing ShowInTaskbar to true when the form is minimized, but false when it's normal.

-Brian Whitmer
bstuffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
You can check the value of the Me.WindowState property in the Resize event, if it's vbMinimized the form has just gotten minimized and when it's vbNormal it's... not minimized or maximized. Code like this

               Sub Form_Resize ()

                 Static WasMinimized As Boolean

                 If (Me.WindowState = vbMinimized) Then
                   WasMinimized = True
                   'Change the Showintaskbar property?
                 ElseIf (Me.WindowState = vbNormal) And WasMinimized Then
                   WasMinimized = False
                   'Change the Showintaskbar property?
                 End If

               End Sub


Because the ShowInTaskbar property can't be changed durin run-time you will have to make some API calls to do it. Here's the code for it..

               Public Declare Function GetWindowLong Lib "user32" _
               Alias "GetWindowLongA" (ByVal hwnd As Long, _
               ByVal nIndex As Long) As Long

               Public Declare Function SetWindowLong Lib "user32" _
               Alias "SetWindowLongA" (ByVal hwnd As Long, _
               ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

               Public Declare Function ShowWindow Lib "user32"_
               (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

               Public Const SW_HIDE = 0
               Public Const SW_SHOW = 5
               Public Const GWL_EXSTYLE = (-20)
               Public Const WS_EX_TOOLWINDOW = &H80&
               Public Sub setShowInTaskbar(Visible As Boolean, hwnd As Long)
               Dim L As Long
               L = ShowWindow(hwnd, SW_HIDE)
               DoEvents
               L = SetWindowLong(hwnd, GWL_EXSTYLE, IIf(Visible, -WS_EX_TOOLWINDOW,
               WS_EX_TOOLWINDOW))
               DoEvents
               L = ShowWindow(hwnd, SW_SHOW)
               End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.