Article ID: 186062
Article Last Modified on 7/13/2004
Name Description
----------------------------------------------------------------------
ScrollBars Scroll bar color
Desktop Desktop color
ActiveTitleBar Color of the title bar for the active window
InactiveTitleBar Color of the title bar for the inactive window
MenuBar Menu background color
WindowBackground Window background color
WindowFrame Window frame color
MenuText Color of text on menus
WindowText Color of text in windows
TitleBarText Color of text in caption, size box, and
scroll arrow
ActiveBorder Border color of active window
InactiveBorder Border color of inactive window
ApplicationWorkspace Background color of multiple-document interface
(MDI) applications
Highlight Background color of items selected in a control
HighlightText Text color of items selected in a control
ButtonFace Color of shading on the face of command buttons
ButtonShadow Color of shading on the edge of command buttons
GrayText Grayed (disabled) text
ButtonText Text color on push buttons
InactiveCaptionText Color of text in an inactive caption
3DHighlight Highlight color for 3-D display elements
3DDKShadow Darkest shadow color for 3-D display elements
3DLight Second lightest 3-D color after 3DHighlight
InfoText Color of text in ToolTips
InfoBackground Background color of ToolTips
Array Element Array1 Array2
------------------------------------------------------------------
0 COLOR_SCROLLBAR vbRed
1 COLOR_BTNSHADOW vbGreen
2 COLOR_HIGHLIGHTTEXT vbBlue
Option Explicit
Private Declare Function SetSysColors Lib "user32" (ByVal nChanges _
As Long, lpSysColor As Long, lpColorValues As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex _
As Long) As Long
Dim OriginalColor As Long
Dim NewColor(0) As Long
Dim IndexArray(0) As Long
'Constant for screen aspects.
Private Const COLOR_BTNTEXT = 18
Private Sub Command1_Click()
'Specify the aspect being changed.
IndexArray(0) = COLOR_BTNTEXT
'Randomly pick a new color.
NewColor(0) = QBColor(Int(Rnd * 16))
'Inform windows of the new color setting.
SetSysColors 1, IndexArray(0), NewColor(0)
End Sub
Private Sub Command2_Click()
'Specify the aspect being changed.
IndexArray(0) = COLOR_BTNTEXT
'Reset the original color.
NewColor(0) = OriginalColor
'Inform Windows of the new color setting.
SetSysColors 1, IndexArray(0), NewColor(0)
End Sub
Sub Form_Load()
'Retrieve current color for a button's caption.
OriginalColor = GetSysColor(COLOR_BTNTEXT)
Command1.Caption = "Change Color"
Command2.Caption = "Reset Color"
'Begin random number generator.
Randomize
End Sub
168795 : How To Hook into a Window's Messages Using AddressOf
Option Explicit
Sub Form_Load()
'Begin random number generator
Randomize
'Store handle to this form's window.
gHW = Me.hwnd
'Call procedure to begin capturing messages for this window.
Hook
'Call procedure to generate the random new colors.
GenerateRandomColors
'Call procedure to save the original color settings.
SaveOriginalColors
'Call procedure to set the new colors as the ones in use.
SetNewColors
End Sub
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
SetNewColors
Else
RestoreColors
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Call procedure to restore colors to their original.
RestoreColors
'Call subprocedure to cease hooking into messages.
Unhook
End Sub
Option Explicit
Declare Function SetSysColors Lib "user32" (ByVal nChanges As _
Long, lpSysColor As Long, lpColorValues As Long) As Long
Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) _
As Long
Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const WM_ACTIVATEAPP = &H1C
Public Const GWL_WNDPROC = -4
Public Const COLOR_SCROLLBAR = 0
Public Const COLOR_BACKGROUND = 1
Public Const COLOR_ACTIVECAPTION = 2
Public Const COLOR_INACTIVECAPTION = 3
Public Const COLOR_MENU = 4
Public Const COLOR_WINDOW = 5
Public Const COLOR_WINDOWFRAME = 6
Public Const COLOR_MENUTEXT = 7
Public Const COLOR_WINDOWTEXT = 8
Public Const COLOR_CAPTIONTEXT = 9
Public Const COLOR_ACTIVEBORDER = 10
Public Const COLOR_INACTIVEBORDER = 11
Public Const COLOR_APPWORKSPACE = 12
Public Const COLOR_HIGHLIGHT = 13
Public Const COLOR_HIGHLIGHTTEXT = 14
Public Const COLOR_BTNFACE = 15
Public Const COLOR_BTNSHADOW = 16
Public Const COLOR_GRAYTEXT = 17
Public Const COLOR_BTNTEXT = 18
Public Const COLOR_INACTIVECAPTIONTEXT = 19
Public Const COLOR_BTNHIGHLIGHT = 20
Global OriginalColors(20) As Long
Global NewColors(20) As Long
Global IndexArray(20) As Long
Global lpPrevWndProc As Long
Global gHW As Long
Public Sub Hook()
'Establish a hook to capture messages to this window.
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Public Sub Unhook()
Dim temp As Long
'Reset the message handler for this window.
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'Check for the ActivateApp message.
If uMsg = WM_ACTIVATEAPP Then
'Check to see if Activating the application.
If wParam <> 0 Then
'Check to see if application is minimized.
If Form1.WindowState <> vbMinimized Then
'Use custom colors.
SetNewColors
End If
Else
'Application is DeActivating so restore normal colors.
RestoreColors
End If
End If
'Pass message on to the original window message handler.
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, _
lParam)
End Function
Public Sub RestoreColors()
SetSysColors 21, IndexArray(0), OriginalColors(0)
End Sub
Public Sub SetNewColors()
SetSysColors 21, IndexArray(0), NewColors(0)
End Sub
Public Sub GenerateRandomColors()
'Randomly pick and assign new colors.
IndexArray(0) = COLOR_SCROLLBAR
NewColors(0) = QBColor(Int(16 * Rnd))
IndexArray(1) = COLOR_BACKGROUND
NewColors(1) = QBColor(Int(16 * Rnd))
IndexArray(2) = COLOR_ACTIVECAPTION
NewColors(2) = QBColor(Int(16 * Rnd))
IndexArray(3) = COLOR_INACTIVECAPTION
NewColors(3) = QBColor(Int(16 * Rnd))
IndexArray(4) = COLOR_MENU
NewColors(4) = QBColor(Int(16 * Rnd))
IndexArray(5) = COLOR_WINDOW
NewColors(5) = QBColor(Int(16 * Rnd))
IndexArray(6) = COLOR_WINDOWFRAME
NewColors(6) = QBColor(Int(16 * Rnd))
IndexArray(7) = COLOR_MENUTEXT
NewColors(7) = QBColor(Int(16 * Rnd))
IndexArray(8) = COLOR_WINDOWTEXT
NewColors(8) = QBColor(Int(16 * Rnd))
IndexArray(9) = COLOR_CAPTIONTEXT
NewColors(9) = QBColor(Int(16 * Rnd))
IndexArray(10) = COLOR_ACTIVEBORDER
NewColors(10) = QBColor(Int(16 * Rnd))
IndexArray(11) = COLOR_INACTIVEBORDER
NewColors(11) = QBColor(Int(16 * Rnd))
IndexArray(12) = COLOR_APPWORKSPACE
NewColors(12) = QBColor(Int(16 * Rnd))
IndexArray(13) = COLOR_HIGHLIGHT
NewColors(13) = QBColor(Int(16 * Rnd))
IndexArray(14) = COLOR_HIGHLIGHTTEXT
NewColors(14) = QBColor(Int(16 * Rnd))
IndexArray(15) = COLOR_BTNFACE
NewColors(15) = QBColor(Int(16 * Rnd))
IndexArray(16) = COLOR_BTNSHADOW
NewColors(16) = QBColor(Int(16 * Rnd))
IndexArray(17) = COLOR_GRAYTEXT
NewColors(17) = QBColor(Int(16 * Rnd))
IndexArray(18) = COLOR_BTNTEXT
NewColors(18) = QBColor(Int(16 * Rnd))
IndexArray(19) = COLOR_INACTIVECAPTIONTEXT
NewColors(19) = QBColor(Int(16 * Rnd))
IndexArray(20) = COLOR_BTNHIGHLIGHT
NewColors(20) = QBColor(Int(16 * Rnd))
End Sub
Public Sub SaveOriginalColors()
Dim i As Long
'Retrieve all current color settings.
For i = 0 To 20
OriginalColors(i) = GetSysColor(i)
Next i
End Sub
168795 : How To Hook into a Window's Messages Using AddressOf
Additional query words: kbDSupport kbDSD kbSDKWin32 kbAPI kbHook sub-class kbVBp500 kbVBp600 kbVBp sub class
Keywords: kbhowto kbgrpdsvb KB186062