Professional Documents
Culture Documents
LightBox For Visual Basic 6
Helping to reduce information‐overload
By William Sengdara
Programmer
January 2010
Introduction
My first encounter with selective ‘Black outs’ in dialogs was on the world wide web. Let me explain.
Some of the savvy web sites I tend to visit, such as Information Technology websites, make use of input
dialogs with a difference. The big difference here is that these dialogs were displayed in front of a
darkened background webpage. I later learned about a script called LightBox.
Suffice to say, this simple act means that focus and attention moves from the cluttered web page behind
and naturally to the dialog in front.
I encountered the same thing on Microsoft Windows Vista as well. One example that immediately
comes to mind is that whenever I attempted to make changes to my desktop, such as the color scheme,
the desktop would slightly black out until the procedure completed etc.
Clearly there is Zen in reducing information overload in decision making in input/interaction
dialogs.
I see this as an extremely beautiful idea in this world of information overload and so, I have decided to
implement it in my applications. What follows is a small study in implementing ‘black out’ in software
interface windows and dialogs.
Before implementing selective black‐out
We will consider the application below. It is an SMS Control and Administration Center for my SMS
System.
Fig.1. the application window showing the list of text messages received.
Fig.2. composing a new text message. Notice the clutter of text messages in the background ?
After implementing selective black‐out
Clearly, the screenshot below shows a much better user experience.
Fig.3. composing a text message with ‘black out’ implemented
Examples
Normal dialogs
You have a form named frmMain and a connection dialog named frmMySQLconnect. To show
frmMySQLconnect over frmMain with the selective black out form:
showFormAndThis frmMain, frmMySQLconnect
There is no return value after calling showFormAndThis(),show use global/public variables if you need
to pass data from forms.
For other dialogs
For other dialogs, such as InputBox() or MsgBox(), there is a second function which creates the selective
black out form directly
Dim frm As Form
Set frm = showFormOnly(frmMain)
endif
unload frm
How it all works
The application demonstrated here is written in VB 6. Although I am only able to provide the source
code in VB 6, the principle is the same regardless of the language in use. Also, I am not trying to provide
a complete solution, just a simple foundation. One issue found is that the ‘black out’ can only applied to
one form at a time; you cannot propagate it to any other forms.
Normally, you would display your dialog in this way
frmParent.show frmChild, vbmodal
To implement our ‘black out’, we instead call the public ‘black out’ (showFormAndThis) procedure:
showFormAndThis frmParent, frmChild
The example above would work for normal dialogs but when your frmChild is an input‐type form, you
should call the ‘black out’ procedure from that form’s Form_Load event instead.
Now for the actual code inside frmBlackOut
‘ inside frmBlackOut
Option Explicit
STEP 2:
Option Explicit
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As
RECT) As Long
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 Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As
POINTAPI) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
pt.x = 0
pt.y = 0
rc.Left = 0
rc.Bottom = 0
rc.Right = 0
rc.Top = 0
GetClientRect frmParent.hwnd, rc
ClientToScreen frmParent.hwnd, pt
MoveWindow frmB.hwnd, pt.x, pt.y, rc.Right, rc.Bottom, True
Unload frmB
Exit Sub
bail:
‘ This function is specific for other types of modal dialogs, e.g. MsgBox
‘ Dim frm as Form
‘ Set frm = showFormOnly(m)
‘ MsgBox “Information”, 64, “Test”
‘ unload frm ‘ make sure to close the form!
Public Function showFormOnly(frmParent As Form) As Form
On Error Resume Next
pt.x = 0
pt.y = 0
rc.Left = 0
rc.Bottom = 0
rc.Right = 0
rc.Top = 0
GetClientRect frmParent.hwnd, rc
ClientToScreen frmParent.hwnd, pt
MoveWindow frmB.hwnd, pt.x, pt.y, rc.Right, rc.Bottom, True
bail:
End Function
‘ STEP 3:
‘
‘ create a module
‘ name it modXPtransparent
Option Explicit
'----------------------------------------------------------
' Make a form transparent on Windows 2000
'----------------------------------------------------------
'----------------------------------------------------------
' API declares
'----------------------------------------------------------
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
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 SetLayeredWindowAttributes Lib _
"user32" (ByVal hwnd As Long, ByVal crKey As Long, _
ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'----------------------------------------------------------
' API constants
'----------------------------------------------------------
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
'----------------------------------------------------------
' sub to make the form transparent
'----------------------------------------------------------
Public Function setFormTransparent(frm As Form, ByVal bAlphaParam As Byte) As Long
Dim rtn As Long