Link to home
Start Free TrialLog in
Avatar of BigOldDog
BigOldDog

asked on

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

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

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Check this

http://www.vbaccelerator.com/codelib/winstyle/taskshow.htm
Avatar of BigOldDog
BigOldDog

ASKER

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.
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

ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?  
Excellent solution
Thanks for points, glad I could help
As for win API:
http://www.amazon.com/Applemans-Visual-Basic-Programmers-Guide/dp/0672315904