Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Dialog - color - using API


'API dialogs for file selections and color selections
Private Type CHOOSECOLOR
 lStructSize As Long
 hwndOwner As Long
 hInstance As Long
 rgbResult As Long
 lpCustColors As String
 Flags As Long
 lCustData As Long
 lpfnHook As Long
 lpTemplateName As String
End Type

Private Declare Function ChooseColorAPI Lib "comdlg32.dll" Alias _
  "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

Sub SelectColor()
  Dim CustomColors() As Byte
  Dim cc As CHOOSECOLOR
  Dim Custcolor(16) As Long
  Dim iReturn As Long
 cc.lStructSize = Len(cc)
 cc.hwndOwner = frmMain.hwnd
 cc.hInstance = 0
 cc.lpCustColors = StrConv(CustomColors, vbUnicode)
 cc.Flags = 0
 iReturn = ChooseColorAPI(cc)
  If iReturn <> 0 Then
    lblBackgroundColor.BackColor = cc.rgbResult
  End If
End Sub