Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How do you recreate the blur/haze effect that the Shut Down Windows function pro

A long time ago I read an article that suggested windows has an API call that
would allow a VB app to recreate the effect produced when the user clicks
Start-Shut Down. The background has a semi-black overlay that clearly identifies
the shut down dialog box as the only active window. I utilize a number of
modal dialog boxes in my current project, that seem to confuse new users.
I would like to haze over the current form (just the current form, nothing
else) and display the modal dialog box. This should provide the user with
the best visual cues that only the non-modal form is inactive.
[620 byte] By [John Lewin] at [2007-11-10 0:20:56]
# 1 Re: How do you recreate the blur/haze effect that the Shut Down Windows function pro
> I utilize a number of modal dialog boxes in my current project
> that seem to confuse new users. I would like to haze over the
> current form (just the current form, nothing else) and display
> the modal dialog box. This should provide the user with the
> best visual cues that only the non-modal form is inactive.

John: If your users are confused by your app's interface, perhaps you should
rethink its design. Modal forms are often employed to force the user to do
things in the order the developer would like them to be done, rather than
the order in which the user would like to do them. There are exceptions, of
course, but in my experience, modal dialogs are often unnecessary and
usually disruptive to the user's flow. I would suggest that you redesign
your UI to eliminate most or all modal dialogs.

That said, you can use the code below to apply the shading effect you
describe to a form. A more standard mechanism is to simply disable the form
(frm.Enabled = False), which will cause its title bar and controls to paint
in Windows' inactive colors.
--
Phil Weber

[Followups posted to design.ui]

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long,
_
ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As
Long, _
lpBits As Any) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap _
As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As
Long) _
As Long
Private Declare Function FillRect Lib "user32" (ByVal hDC As Long,
lpRect _
As RECT, ByVal hBrush As Long) As Long

Public Sub ShadeForm(frm As Form)

Dim hBitmap As Long
Dim hBrush As Long
Dim lResult As Long
Dim rc As RECT
Static iBrush(1 To 8) As Integer

If iBrush(1) = 0 Then
iBrush(1) = &H55: iBrush(2) = &HAA
iBrush(3) = &H55: iBrush(4) = &HAA
iBrush(5) = &H55: iBrush(6) = &HAA
iBrush(7) = &H55: iBrush(8) = &HAA
End If

With frm
.Cls
' .ScaleMode = vbPixels
With rc
.Left = 0
.Top = 0
.Right = frm.ScaleWidth
.Bottom = frm.ScaleHeight
End With
hBitmap = CreateBitmap(8, 8, 1, 1, iBrush(1))
hBrush = CreatePatternBrush(hBitmap)
lResult = FillRect(.hDC, rc, hBrush)
lResult = DeleteObject(hBrush)
lResult = DeleteObject(hBitmap)
End With

End Sub
Phil Weber at 2007-11-11 20:02:40 >
# 2 Re: How do you recreate the blur/haze effect that the Shut Down Windows function pro
> I utilize a number of modal dialog boxes in my current project
> that seem to confuse new users. I would like to haze over the
> current form (just the current form, nothing else) and display
> the modal dialog box. This should provide the user with the
> best visual cues that only the non-modal form is inactive.

John: If your users are confused by your app's interface, perhaps you should
rethink its design. Modal forms are often employed to force the user to do
things in the order the developer would like them to be done, rather than
the order in which the user would like to do them. There are exceptions, of
course, but in my experience, modal dialogs are often unnecessary and
usually disruptive to the user's flow. I would suggest that you redesign
your UI to eliminate most or all modal dialogs.

That said, you can use the code below to apply the shading effect you
describe to a form. A more standard mechanism is to simply disable the form
(frm.Enabled = False), which will cause its title bar and controls to paint
in Windows' inactive colors.
--
Phil Weber

[Followups posted to design.ui]

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long,
_
ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As
Long, _
lpBits As Any) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap _
As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As
Long) _
As Long
Private Declare Function FillRect Lib "user32" (ByVal hDC As Long,
lpRect _
As RECT, ByVal hBrush As Long) As Long

Public Sub ShadeForm(frm As Form)

Dim hBitmap As Long
Dim hBrush As Long
Dim lResult As Long
Dim rc As RECT
Static iBrush(1 To 8) As Integer

If iBrush(1) = 0 Then
iBrush(1) = &H55: iBrush(2) = &HAA
iBrush(3) = &H55: iBrush(4) = &HAA
iBrush(5) = &H55: iBrush(6) = &HAA
iBrush(7) = &H55: iBrush(8) = &HAA
End If

With frm
.Cls
' .ScaleMode = vbPixels
With rc
.Left = 0
.Top = 0
.Right = frm.ScaleWidth
.Bottom = frm.ScaleHeight
End With
hBitmap = CreateBitmap(8, 8, 1, 1, iBrush(1))
hBrush = CreatePatternBrush(hBitmap)
lResult = FillRect(.hDC, rc, hBrush)
lResult = DeleteObject(hBrush)
lResult = DeleteObject(hBitmap)
End With

End Sub
Phil Weber at 2007-11-11 20:03:34 >