Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show In Taskbar function for all types of Access (2003) Forms

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
Below is my code so far:
It accepts the Form name as Me.hWnd
It allows to choose True or False (to say whether to put Form in taskbar)

But it only seems to have an effect on popup Forms.

Does anyone know how to modify it to work for all types of Form?

Code:
[COLOR=#204A87]Option Compare Database
Option Explicit

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 GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
  ByVal hwnd As Long, _
  ByVal nIndex As Long) As Long

Private Const WS_EX_APPWINDOW = &H40000
Private Const GWL_STYLE = -20

Public Function ShowInTaskbar(Lhwnd As Long, Show As Boolean)
Dim lStyle As Long
lStyle = GetWindowLong(Lhwnd, GWL_STYLE)

If Show Then
lStyle = lStyle Or WS_EX_APPWINDOW
Else
lStyle = lStyle And Not WS_EX_APPWINDOW
End If

Call SetWindowLong(Lhwnd, GWL_STYLE, lStyle)

End Function
[/color]
 
You need to investigate what WS_EX_APPWINDOW actually is. That will then (start to) explain why the function ony works for popup forms. In summary WS_EX_APPWINDOW only works on top-level windows (and only when they are visible), and an Access form is only a top-level window when it is a popup. And you can only make it a popup at design time (actually, this is not entirely true, but it is a somewhat complex operation involving the API to switch a window from being a child window to a top-level window AFTER it has been created, particularly ones that are as heavily subclassed as Access forms are.

 
Hello strongm

I checked the Extended Window Styles on MSDN but I cannot see an alternative for child Forms.

Do you know of some code that will achieve what I need?

Having looked into this some more I realize that its only necessary to

1. force the form for Popups onto the taskbar as by default the don’t appear there and as my code I posted does that then I’ve got that one covered.

and

2. don’t have the form appear on the taskbar for all non popups because by default they do. This is the one I need something for.

If you don’t have some code to achieve number 2 then you might be able to explain why the following which still uses WS_EX_APPWINDOW seems to not make the non popup (standard child) form appear in the taskbar (which is what I need). I don’t think its working properly although it gets the result because it does so whether you select True or False? and i would like a proper solution if this is not one.

Code:
[COLOR=#204A87]Option Compare Database
Option Explicit

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 GetWindow Lib "user32" Alias "GetWindowLongA" ( _
  ByVal hwnd As Long, _
  ByVal nIndex As Long) As Long
  
  Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Const WS_EX_APPWINDOW = &H40000
Private Const GWL_EXSTYLE = (-20)

Public Function ShowInTaskbar(Lhwnd As Long, Show As Boolean)
Dim lStyle As Long
 Dim lRetVal As Long
Const SW_HIDE = 0
Const SW_SHOW = 5
   lRetVal = ShowWindow(Lhwnd, SW_HIDE)
 
lStyle = GetWindow(Lhwnd, GWL_EXSTYLE)


If Show Then
lStyle = lStyle Or WS_EX_APPWINDOW
lRetVal = SetWindowLong(Lhwnd, GWL_EXSTYLE, lStyle)
Else
'ShowWindow Lhwnd, SW_HIDE
' lRetVal = ShowWindow(Lhwnd, SW_HIDE)
lStyle = lStyle And Not WS_EX_APPWINDOW
lRetVal = SetWindowLong(Lhwnd, GWL_EXSTYLE, lStyle)
End If

  lRetVal = ShowWindow(Lhwnd, SW_SHOW)

End Function
[/color]
 
We have to be a little careful here. Access forms are not just child windows, they are (very heavily subclassed) MDI child windows, and do not really follow normal winow beahviour.

As a result, for forms as you describe, some of the normal tricks for hiding them from the taskbar just do not work (e.g setting the WS_EX_TOOLBOX style). I'm afraid I am not aware of a way of achieving what you want. I'd be more than happy for someone else to come along and prove it can be done, though.
 
Hello strongm

I’ve been trying some different ways and I must admit its all a bit confusing.

The thing is the following code actually does what I want which is to say it does not dhow the form on the taskbar.

Code:
[COLOR=#204A87]Option Compare Database
Option Explicit

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 GetWindow Lib "user32" Alias "GetWindowLongA" ( _
  ByVal hwnd As Long, _
  ByVal nIndex As Long) As Long
  
  Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Public Function ShowInTaskbar(Lhwnd As Long)

 Dim lRetVal As Long
Const SW_HIDE = 0
Const SW_SHOW = 5

  lRetVal = ShowWindow(Lhwnd, SW_SHOW)

End Function

[/color]

And if I substitute the SW_SHOW with SW_HIDE then it does show the form on the taskbar (even though it sounds to me the wrong way round, it seems to work).

Does this make sense to you and sound like a viable solution to use?
 
Typically, a hidden window (SW_HIDE) will not appear on the taskbar, that's standard behaviour and nothing to do - but then it often isn't much use to you as a window. And anyway, Access Forms don't respond to it the way we migth expect.

Having said that, your description of what is happening is ... odd, even for Access.

Can you confirm which version of Access you are using, and on what OS? Also, we might like to see that actual code in use, rather than ct'n'pasted snippets that are not giving the whole story.
 
Hello strongm

You ask to see code in use so I put a demo db together here

In this example the code is reduced even further to just a few lines, it compiles and runs without error and gives me the results I need, which are: to show popup form on taskbar, and not show standard form on taskbar. I’ve tested it on XP, Vista and Windows7.

Just out of interest I would like to know why it works when apparently it shouldn’t.

As a more experienced programmer I value your opinion and would like to know if you find my example a viable solution for what I need also if you feel any modifications to the code would be beneficial please let me know.


 
That's really quite ... odd.

As you say, SW_SHOW does indeed appear to hide the non-popup forms from the taskbar. Rather unexpectedly. Interesting. The popup form, on the other hand, is behaving as expected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top