Results 1 to 8 of 8

Thread: Set/Get the ShowInTaskbar property for a window at runtime

Hybrid View

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Set/Get the ShowInTaskbar property for a window at runtime

    VB Code:
    1. 'You need 2 command buttons 'cmdToggle' and 'cmdCheck'
    2.  
    3. Option Explicit
    4.  
    5. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    6.     (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    7.    
    8. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    9.     (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    10.  
    11. Private Declare Function ShowWindow Lib "user32" _
    12.     (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    13.    
    14. Private Const GWL_EXSTYLE = (-20)
    15. Private Const WS_EX_APPWINDOW = &H40000
    16.  
    17. Const SW_HIDE = 0
    18. Const SW_NORMAL = 1
    19.  
    20. Private Sub ShowInTheTaskbar(hwnd As Long, bShow As Boolean)
    21.     Dim lStyle As Long
    22.    
    23.     ShowWindow hwnd, SW_HIDE
    24.    
    25.     lStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
    26.    
    27.     If bShow = False Then
    28.         If lStyle And WS_EX_APPWINDOW Then
    29.             lStyle = lStyle - WS_EX_APPWINDOW
    30.         End If
    31.     Else
    32.         lStyle = lStyle Or WS_EX_APPWINDOW
    33.     End If
    34.    
    35.     SetWindowLong hwnd, GWL_EXSTYLE, lStyle
    36.    
    37.     App.TaskVisible = bShow
    38.    
    39.     ShowWindow hwnd, SW_NORMAL
    40. End Sub
    41.  
    42. Private Function IsVisibleInTheTaskbar(hwnd As Long) As Boolean
    43.     Dim lStyle As Long
    44.    
    45.     lStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
    46.    
    47.     If lStyle And WS_EX_APPWINDOW Then
    48.         IsVisibleInTheTaskbar = True
    49.     End If
    50. End Function
    51.  
    52. Private Sub cmdToggle_Click()
    53.     Static bVisible As Boolean
    54.    
    55.     bVisible = Not IsVisibleInTheTaskbar(Me.hwnd)
    56.    
    57.     ShowInTheTaskbar Me.hwnd, bVisible
    58. End Sub
    59.  
    60. Private Sub Form_Load()
    61.     cmdToggle.Caption = "Toggle visibility"
    62.     cmdCheck.Caption = "Check visibility"
    63. End Sub
    Last edited by manavo11; Aug 25th, 2005 at 08:49 PM.


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Set/Get the ShowInTaskbar property for a window

    nice code

  3. #3

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Set/Get the ShowInTaskbar property for a window

    Thanks Just altered a bit of code I found here and made them functions/subs


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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?

  5. #5

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    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).
    Last edited by manavo11; Aug 28th, 2005 at 08:04 AM.


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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.

    BTW - In you example cmdCheck does nothing. Just thought I'd let you know.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  7. #7

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Set/Get the ShowInTaskbar property for a window at runtime

    Oops Good catch eyeR! I had it to just have a msgbox and call the IsVisible... function, nothing much


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Set/Get the ShowInTaskbar property for a window at runtime

    Nice code Philip!

    WS_EX_???????? = Extended Window Style Or Window Style Extended
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width