• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

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
0
bstuff
Asked:
bstuff
1 Solution
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now