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

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

0
BigOldDog
Asked:
BigOldDog
  • 3
  • 3
1 Solution
 
CodeCruiserCommented:
Wow. VB6 was considered legacy but VB5????? Ancient I guess :-)

Check this

http://www.vbaccelerator.com/codelib/winstyle/taskshow.htm
0
 
BigOldDogAuthor Commented:
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.
0
 
ArkCommented:
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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ArkCommented:
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 :)
0
 
BigOldDogAuthor Commented:
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?  
0
 
BigOldDogAuthor Commented:
Excellent solution
0
 
ArkCommented:
Thanks for points, glad I could help
As for win API:
http://www.amazon.com/Applemans-Visual-Basic-Programmers-Guide/dp/0672315904
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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