
'====================================================================
'' System color demo, modal dialog as main.
'====================================================================

#include "dialogs.bas"

'' These currently missing from winuser.bi.

#define COLOR_MENUHILIGHT 29
#define COLOR_MENUBAR     30

'====================================================================

#define LBADDS(h,s)SendMessage(h,LB_ADDSTRING,0,cast(LPARAM,@s))

'' List boxes use a zero-based index.

Dim Shared As Integer sysColors(0 To 35) = { _
    COLOR_3DDKSHADOW, _
    COLOR_3DFACE, _
    COLOR_3DHIGHLIGHT, _
    COLOR_3DHILIGHT, _
    COLOR_3DLIGHT, _
    COLOR_3DSHADOW, _
    COLOR_ACTIVEBORDER, _
    COLOR_ACTIVECAPTION, _
    COLOR_APPWORKSPACE, _
    COLOR_BACKGROUND, _
    COLOR_BTNFACE, _
    COLOR_BTNHIGHLIGHT, _
    COLOR_BTNHILIGHT, _
    COLOR_BTNSHADOW, _
    COLOR_BTNTEXT, _
    COLOR_CAPTIONTEXT, _
    COLOR_DESKTOP, _
    COLOR_GRADIENTACTIVECAPTION, _
    COLOR_GRADIENTINACTIVECAPTION, _
    COLOR_GRAYTEXT, _
    COLOR_HIGHLIGHT, _
    COLOR_HIGHLIGHTTEXT, _
    COLOR_HOTLIGHT, _
    COLOR_INACTIVEBORDER, _
    COLOR_INACTIVECAPTION, _
    COLOR_INACTIVECAPTIONTEXT, _
    COLOR_INFOBK, _
    COLOR_INFOTEXT, _
    COLOR_MENU, _
    COLOR_MENUBAR, _
    COLOR_MENUHILIGHT, _
    COLOR_MENUTEXT, _
    COLOR_SCROLLBAR, _
    COLOR_WINDOW, _
    COLOR_WINDOWFRAME, _
    COLOR_WINDOWTEXT }

'====================================================================

Function DialogProc( Byval hDlg As  HWND, _
                     Byval uMsg As UINT, _
                     Byval wParam As WPARAM, _
                     Byval lParam As LPARAM ) As Integer

  Static As HWND hWndList, hWndSample
  Static As HBRUSH hBrush
  Dim As Integer i, clr
  Dim As String h

  Select Case uMsg

    Case WM_INITDIALOG

      hWndList = GetDlgItem( hDlg, 100 )
      hWndSample = GetDlgItem( hDlg, 101 )

      LBADDS( hWndList, "COLOR_3DDKSHADOW" )
      LBADDS( hWndList, "COLOR_3DFACE" )
      LBADDS( hWndList, "COLOR_3DHIGHLIGHT" )
      LBADDS( hWndList, "COLOR_3DHILIGHT" )
      LBADDS( hWndList, "COLOR_3DLIGHT" )
      LBADDS( hWndList, "COLOR_3DSHADOW" )
      LBADDS( hWndList, "COLOR_ACTIVEBORDER" )
      LBADDS( hWndList, "COLOR_ACTIVECAPTION" )
      LBADDS( hWndList, "COLOR_APPWORKSPACE" )
      LBADDS( hWndList, "COLOR_BACKGROUND" )
      LBADDS( hWndList, "COLOR_BTNFACE" )
      LBADDS( hWndList, "COLOR_BTNHIGHLIGHT" )
      LBADDS( hWndList, "COLOR_BTNHILIGHT" )
      LBADDS( hWndList, "COLOR_BTNSHADOW" )
      LBADDS( hWndList, "COLOR_BTNTEXT" )
      LBADDS( hWndList, "COLOR_CAPTIONTEXT" )
      LBADDS( hWndList, "COLOR_DESKTOP" )
      LBADDS( hWndList, "COLOR_GRADIENTACTIVECAPTION" )
      LBADDS( hWndList, "COLOR_GRADIENTINACTIVECAPTION" )
      LBADDS( hWndList, "COLOR_GRAYTEXT" )
      LBADDS( hWndList, "COLOR_HIGHLIGHT" )
      LBADDS( hWndList, "COLOR_HIGHLIGHTTEXT" )
      LBADDS( hWndList, "COLOR_HOTLIGHT" )
      LBADDS( hWndList, "COLOR_INACTIVEBORDER" )
      LBADDS( hWndList, "COLOR_INACTIVECAPTION" )
      LBADDS( hWndList, "COLOR_INACTIVECAPTIONTEXT" )
      LBADDS( hWndList, "COLOR_INFOBK" )
      LBADDS( hWndList, "COLOR_INFOTEXT" )
      LBADDS( hWndList, "COLOR_MENU" )
      LBADDS( hWndList, "COLOR_MENUBAR" )
      LBADDS( hWndList, "COLOR_MENUHILIGHT" )
      LBADDS( hWndList, "COLOR_MENUTEXT" )
      LBADDS( hWndList, "COLOR_SCROLLBAR" )
      LBADDS( hWndList, "COLOR_WINDOW" )
      LBADDS( hWndList, "COLOR_WINDOWFRAME" )
      LBADDS( hWndList, "COLOR_WINDOWTEXT" )

      '' Set the current selection to the first item
      '' and send a LBN_SELCHANGE notification.

      SendMessage( hWndList, LB_SETCURSEL, 0, 0 )
      SendMessage( hDlg, WM_COMMAND, LBN_SELCHANGE Shl 16 , 0 )

    Case WM_COMMAND

      If hiword(wParam) = LBN_SELCHANGE Then

        '' Update everything to reflect the selection.

        i = SendMessage( GetDlgItem( hDlg, 100 ), LB_GETCURSEL, 0, 0 )
        hBrush = GetSysColorBrush( sysColors(i) )
        If hBrush Then

          clr = GetSysColor( sysColors(i) )
          h = Hex(clr)
          h = String(6-Len(h),"0") & h & "h"
          SetDlgItemText( hDlg, 102, h )

          '' This will force an update of the sample, causing
          '' the system to send a WM_CTLCOLORSTATIC message to
          '' the dialog before the control is updated.

          SetDlgItemText( hDlg, 101, "" )

        End If

      Elseif loword(wParam) = IDCANCEL Then

        '' This will allow the user to close the
        '' dialog by pressing the Escape.

        EndDialog( hDlg, null )

      End If

    Case WM_CTLCOLORSTATIC

      '' Return the brush that corresponds to the selected
      '' system color only for the sample window.

      If lParam = hWndSample Then

        Return cast(Integer,hBrush)

      End If

    Case WM_CLOSE

      EndDialog( hDlg, null )

  End Select

  Return 0

End Function

'====================================================================

Dim As LPDLGTEMPLATE lpdt

Dialog( 3, 0, 0, 160, 120, "System Colors", lpdt, _
        WS_OVERLAPPED Or WS_SYSMENU Or DS_CENTER )

ListBox( 100, 5, 5, 146, 80, _
         WS_TABSTOP Or WS_BORDER Or WS_VSCROLL Or LBS_NOTIFY )

'' This will be used to display a sample of the color.

LText( 101, 20, 86, 60, 15, "", SS_SUNKEN )

'' This will be used to display the color value.

LText( 102, 100, 90, 40, 10, "" )

CreateModalDialog( 0, @DialogProc, 0, lpdt )

'====================================================================
 