Can not change ShowInTaskbar setting from within a VB5 or 6 Program

Posted on 2011-04-27
Last Modified: 2013-11-25
I need to allow my user to decide whether or not a form should be visible in the Task Bar.
It seems that I cannot use "ShowInTaskbar" as this property is read only at runtime (according to VB5 help, and it generates a compile error VB6).
Any suggestions

Question by:BigOldDog
    LVL 83

    Expert Comment

    Wow. VB6 was considered legacy but VB5????? Ancient I guess :-)

    Check this

    Author Comment

    I will have to play around with that a bit to see if it will do what I want, but I do not think that it will.
    On first read through it seems to allow you to set the value only before a form is created. What I want to do is allow the user to change this setting for an existing form.
    If I was going to use that sort of approach it would be easier to just use two identical forms but with differing ShowInTaskbar settings then load / unload them. In fact I think that is what I will do if no one comes up with a better idea.
    As for ancient, the first basic I used was something called Sinclair Basic in 1980, ancient sure am!
    I am now trying to get my head around MS VB 2010 Express.
    LVL 27

    Expert Comment

    Not sure about VB5 but VB6 works without hooks:

    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 SW_SHOW = 5
    Private Const SW_HIDE = 0
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_APPWINDOW = &H40000
    Public Sub ShownInTaskBar(ByVal hwnd As Long, Optional bShow As Boolean = True)
    Dim lExStyles As Long
    lExStyles = GetWindowLong(hwnd, GWL_EXSTYLE) ' get the extended style flags
    ' only add or remove when appropriate
    If bShow Xor (lExStyles And WS_EX_APPWINDOW) = 0 Then Exit Sub
    ShowWindow hwnd, SW_HIDE ' heres the trick, hide the window briefly
    SetWindowLong hwnd, GWL_EXSTYLE, lExStyles Xor WS_EX_APPWINDOW ' toggle the value of the flag
    ShowWindow hwnd, SW_SHOW ' make it visible again
    End Sub

    Open in new window

    LVL 27

    Accepted Solution

    PS (off tread) - as for Sinclair basic - it has nothing common with VB5 and others. It was real assembly with 'Data' blocks and DOS interrupts call :)

    Author Comment

    Thanks that works just fine. Thanks a lot.
     I thought that there would probably be a way to do it using the windows API, but I don't know enough to work it out for myself.
    Can you recommend a good source if information on this topic?  

    Author Closing Comment

    Excellent solution
    LVL 27

    Expert Comment

    Thanks for points, glad I could help
    As for win API:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now