Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Maximized app hides taskbar

0 views
Skip to first unread message

Andy

unread,
Apr 5, 2006, 5:42:01 AM4/5/06
to
I'm building an application which has a main form with only two window states
- maximized and minimized (I can re-maximize it by clicking its icon in the
taskbar). Trouble is, when it's maximized, it covers the taskbar, so I can't
then restore another app. by clicking its icon, unless I first minimize my
app.

The app's window has BorderStyle = Fixed Single, MaxButton = False,
MinButton = True, ShowInTaskbar = True, WindowState = Maximized. It's
displayed using
Me.Show vbModeless
from within a public method named OpenForm, so I can pass a couple of
parameters in (another form is displayed first to get user login details,
which are then needed in the main form).

Any ideas how I can stop it maximizing over the taskbar? Thanks for any
help.

Mike Williams

unread,
Apr 5, 2006, 7:01:27 AM4/5/06
to
"Andy" <andrew...@hotmailnospam.com> wrote in message
news:83D809FC-E2FB-45DC...@microsoft.com...

> I'm building an application which has a main form with only two window
> states - maximized and minimized (I can re-maximize it by clicking its
> icon
> in the taskbar). Trouble is, when it's maximized, it covers the taskbar,
> so
> I can't then restore another app. by clicking its icon, unless I first
> minimize
> my app. The app's window has BorderStyle = Fixed Single, MaxButton

> False, MinButton True, ShowInTaskbar True, WindowState Maximized.


> Any ideas how I can stop it maximizing over the taskbar?

Yep. It seems to be a problem with the way VB handles these things when the
MaxButton is False. You can *appear to get around* the problem by setting
the Form's BorderStyle to Sizeable (instead of your Fixed Single) with all
other properties set as you describe. Doing so stops the Form from covering
the taskbar, but the bottom of the Form then just "hides behind the taskbar"
instead, so that you cannot see anything that you may have placed right at
the bottom of the Form. You can get around all of this though and get your
Form behaving exactly as you want it to by adding a bit of code in the
Form's Resize event. Try the following example on a VB Form containing a
Text Box. This should work for you, and it also gives you the option of
using a WindowState of Maximized instead of your current Fixed Single if you
wish (with all othger properties as described), which will prevent the user
from dragging the Form around the screen (if that is what you want to do).

Mike

Option Explicit
' At Design Time set ControlBox to True, BorderStyle to either
' Fixed Single or Sizeable, WindowState to Maximized,
' MaxButton to False and MinButton to True
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd&, _
ByVal nIndex&, ByVal dwNewLong&) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd&, ByVal hWndInsertAfter&, _
ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, _
ByVal wFlags&) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&) As Long
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20
Private Const GWL_STYLE As Long = (-16&)

Private Sub Form_Load()
Me.Show: DoEvents
' position a text box just for test purposes so that it can
' be fully seen at the bottom of the Form, to show the effects
' of the apparent "bug" in the way VB handles Forms with their
' MaxButton property set to False.
' You'll see the problem that this code fixes if you
' comment out the code in the Form Resize event.
Text1.Top = Me.ScaleHeight - Text1.Height
End Sub

Private Sub Form_Resize()
If Me.WindowState = vbMaximized Then
Call SetWindowLong(hWnd, GWL_STYLE, _
GetWindowLong(hWnd, GWL_STYLE) Xor WS_MAXIMIZEBOX)
End If
Call SetWindowPos(hWnd, 0&, 0&, 0&, 0&, 0&, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER _
Or SWP_FRAMECHANGED)
End Sub

Andy

unread,
Apr 5, 2006, 7:26:02 AM4/5/06
to
Mike


"Mike Williams" wrote:


Thanks for your suggestion. Since posting my question, I've found another
workaround, which looks a bit more straightforward.

I have a SysInfo control on the form, with its default name of SysInfo1.

In Form_Resize, I now have

With Me
If .WindowState = vbMaximized Then
.WindowState = vbNormal
.Height = SysInfo1.WorkAreaHeight
.Width = SysInfo1.WorkAreaWidth
End If
End With


Andy

Rick Rothstein

unread,
Apr 5, 2006, 8:59:02 AM4/5/06
to
> Thanks for your suggestion. Since posting my question, I've found another
> workaround, which looks a bit more straightforward.
>
> I have a SysInfo control on the form, with its default name of SysInfo1.
>
> In Form_Resize, I now have
>
> With Me
> If .WindowState = vbMaximized Then
> .WindowState = vbNormal
> .Height = SysInfo1.WorkAreaHeight
> .Width = SysInfo1.WorkAreaWidth
> End If
> End With

You can eliminate the SysInfo control (and, hence, the need to distribute it
with your compiled application) using the following code (also, not as
straight-forward looking as Mike's code, but which does the same thing that
your present code is doing)...

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function MoveWindow Lib "user32" _
(ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long

Private Const SPI_GETWORKAREA = 48

Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, _
lpvParam As Any, ByVal fuWinIni As Long) As Long

Sub GetWorkArea(waLeft As Integer, waTop As Integer, _
waWidth As Integer, waHeight As Integer, _
Optional InTwips As Boolean = True)
Dim rcWork As RECT
Dim ScaleConverterX As Integer
Dim ScaleConverterY As Integer
If InTwips Then
ScaleConverterX = Screen.TwipsPerPixelX
ScaleConverterY = Screen.TwipsPerPixelY
Else
ScaleConverterX = 1
ScaleConverterY = 1
End If
SystemParametersInfo SPI_GETWORKAREA, 0, rcWork, 0
With rcWork
waLeft = .Left * ScaleConverterX
waTop = .Top * ScaleConverterY
waWidth = (.Right - .Left) * ScaleConverterX
waHeight = (.Bottom - .Top) * ScaleConverterY
End With
End Sub

Private Sub Form_Load()
Me.WindowState = vbMaximized
End Sub

Private Sub Form_Resize()
Dim L As Integer
Dim T As Integer
Dim W As Integer
Dim H As Integer
GetWorkArea L, T, W, H, False


If Me.WindowState = vbMaximized Then

Me.WindowState = vbNormal
Me.Move Me.ScaleX(L, vbPixels, vbTwips), _
Me.ScaleX(T, vbPixels, vbTwips), _
Me.ScaleX(W, vbPixels, vbTwips), _
Me.ScaleX(H, vbPixels, vbTwips)
End If
End Sub


Rick


Andy

unread,
Apr 5, 2006, 11:00:01 AM4/5/06
to
Rick

"Rick Rothstein" wrote:

I tried both your suggestion and Mike's. (I like the idea of losing the
SysInfo control, so I'll ditch my own solution).

However, all three workrounds suffer with the same flaw - although the form
appears to be maximized, it's possible to drag it, which isn't normally
possible with a maximized window. Is there a way to prevent that?

Andy

Rick Rothstein

unread,
Apr 5, 2006, 11:23:01 AM4/5/06
to
> However, all three workrounds suffer with the same flaw - although the
> form
> appears to be maximized, it's possible to drag it, which isn't normally
> possible with a maximized window. Is there a way to prevent that?

Set the form's Moveable property to False.

Rick


Andy

unread,
Apr 5, 2006, 11:36:02 AM4/5/06
to
Rick


> Set the form's Moveable property to False.

Doh!

Andy

Mike Williams

unread,
Apr 5, 2006, 3:16:19 PM4/5/06
to
"Andy" <andrew...@hotmailnospam.com> wrote in message
news:DE99DB7F-6B9D-4113...@microsoft.com...

> Is there a way to prevent that [the Form moving]?

As Rick has already said, just set the Form's Moveable property to False.
Bot sets of code will do the job for you, both without the need for the
third party control you were using. Pick whichever you want. Here is my own
example as it stands at the moment, with three text boxes on the Form to
show that the "no Maxbutton" Form works fine whatever size the user makes
the taskbar and wherever he positions it.

Mike

Option Explicit
' At Design Time set ControlBox to True, BorderStyle to either
' Fixed Single or Sizeable, WindowState to Maximized,

' MaxButton to False and MinButton to True and
' Moveable to False


Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd&, _
ByVal nIndex&, ByVal dwNewLong&) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd&, ByVal hWndInsertAfter&, _
ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, _
ByVal wFlags&) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&) As Long
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20
Private Const GWL_STYLE As Long = (-16&)

Private Sub Form_Load()
Me.Show: DoEvents

Text1.Top = Me.ScaleHeight - Text1.Height

Text2.Left = Me.Left
Text3.Left = Me.ScaleWidth - Text3.Width
End Sub

Private Sub Form_Resize()


Text1.Top = Me.ScaleHeight - Text1.Height

Text2.Left = Me.Left
Text3.Left = Me.ScaleWidth - Text3.Width


If Me.WindowState = vbMaximized Then

Mike Williams

unread,
Apr 5, 2006, 4:10:18 PM4/5/06
to
"Mike Williams" <mi...@WhiskyAndCoke.com> wrote in message
news:ebQkzVOW...@TK2MSFTNGP04.phx.gbl...

. . . Oops! Gonna have to take a little more time checking my posts before I
click the "Send" button :-(

In both the Form Load and the Form Resize event change "Text2.Left =
Me.Left" to "Text2.Left = 0".

Mike

Sarbaaz.Com

unread,
Oct 10, 2008, 10:59:01 AM10/10/08
to
== Here how you can fix this issue:
1. Go to Control Panel, Taskbar and Start Menu
2. Under the "Taskbar" tab, Taskbar appearance, check this box "Keep the
taskbar on top of other windows
3. Click Apply, Ok. (You are all done!)
==

Jeff Johnson

unread,
Oct 10, 2008, 11:26:17 AM10/10/08
to
"Sarbaaz.Com" <Sarba...@discussions.microsoft.com> wrote in message
news:5BC6D84B-FD8E-4B7A...@microsoft.com...

>> I'm building an application which has a main form with only two window
>> states
>> - maximized and minimized (I can re-maximize it by clicking its icon in
>> the
>> taskbar). Trouble is, when it's maximized, it covers the taskbar, so I
>> can't
>> then restore another app. by clicking its icon, unless I first minimize
>> my
>> app.
>>
>> The app's window has BorderStyle = Fixed Single, MaxButton = False,
>> MinButton = True, ShowInTaskbar = True, WindowState = Maximized. It's
>> displayed using
>> Me.Show vbModeless
>> from within a public method named OpenForm, so I can pass a couple of
>> parameters in (another form is displayed first to get user login details,
>> which are then needed in the main form).
>>
>> Any ideas how I can stop it maximizing over the taskbar? Thanks for any
>> help.

> == Here how you can fix this issue:


> 1. Go to Control Panel, Taskbar and Start Menu
> 2. Under the "Taskbar" tab, Taskbar appearance, check this box "Keep the
> taskbar on top of other windows
> 3. Click Apply, Ok. (You are all done!)
> ==

The real issue is probably that the form is being displayed as a modeless
dialog. VB can be quirky about that. I know years ago we had a VB(5?)
program where I work that would cover the task bar no matter what its Always
On Top state was. You had to get just the right combination of
properties....


0 new messages