Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog Save Custom Colors

Status
Not open for further replies.

Terabithia

Programmer
Aug 31, 2004
70
0
0
US
The code that Hypetia posted in thread222-1066475 works great, however I need to save the users 16 custom color selections to an array. I did not see where these colors are actually saved in the Registry, can someone point me in the right direction or offer any methods to get the current custom color selections (all 16 of them).
 
In the example, the custom colors are still in the array CustColors.

Code:
Option Explicit

Private Declare Function ChooseColor Lib "comdlg32" Alias "ChooseColorA" (pChoosecolor As CHOOSE_COLOR) As Long
Private Type CHOOSE_COLOR
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    rgbResult As Long
    lpCustColors As Long
    flags As Long
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
Const CC_FULLOPEN = &H2
Const CC_RGBINIT = &H1
Dim CustColors(15) As Long
Private Sub Form_Load()
    'initialize colors
    Dim N As Long
    For N = 0 To 15
        CustColors(N) = QBColor(N)
    Next
End Sub
Private Sub Command1_Click()

    Dim i As Long
    
    Dim cc As CHOOSE_COLOR
    cc.flags = CC_FULLOPEN Or CC_RGBINIT
    cc.hwndOwner = hWnd
    cc.lpCustColors = VarPtr(CustColors(0))
    cc.rgbResult = Me.BackColor
    cc.lStructSize = Len(cc)
    If ChooseColor(cc) Then
        Me.BackColor = cc.rgbResult
    End If
    
    [green]' Display custom color selections 
    ' after user closes color form[/green]
[!]    For i = 0 To 15
        Debug.Print CustColors(i)
    Next
   [/!] 
End Sub

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
The colors in the custom colors array don't get saved automatically. You have to do this of your own. You can write them to a file, or in registry, which is preferred and easier as well.

See the code below which is slightly modified verion of the original code. It shows you how to preserve custom colors by writing them in registry.
___
[tt]
Private Declare Function ChooseColor Lib "comdlg32" Alias "ChooseColorA" (pChoosecolor As CHOOSE_COLOR) As Long
Private Type CHOOSE_COLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Const CC_FULLOPEN = &H2
Const CC_RGBINIT = &H1
Dim CustColors(15) As Long
Private Sub Form_Load()
'initialize colors
Dim N As Long
For N = 0 To 15
CustColors(N) = GetSetting(App.Title, "Colors", N, QBColor(N))
Next
Me.BackColor = GetSetting(App.Title, "Colors", "BackColor", BackColor)
End Sub
Private Sub Command1_Click()
Dim cc As CHOOSE_COLOR
cc.flags = CC_FULLOPEN Or CC_RGBINIT
cc.hwndOwner = hWnd
cc.lpCustColors = VarPtr(CustColors(0))
cc.rgbResult = Me.BackColor
cc.lStructSize = Len(cc)
If ChooseColor(cc) Then
Me.BackColor = cc.rgbResult
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim N As Long
For N = 0 To 15
SaveSetting App.Title, "Colors", N, CustColors(N)
Next
SaveSetting App.Title, "Colors", "BackColor", BackColor
End Sub[/tt]
___

Just in case you want to know, the custom colors are save in the following registry location.
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<App Title>\Colors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top