Results 1 to 4 of 4

Thread: [RESOLVED] creating custom colors before opening the commondialog box

  1. #1

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Resolved [RESOLVED] creating custom colors before opening the commondialog box

    Hai,

    I've been looking around a bit but couldn't find anything about this.

    I want to create/build some custom colors (programmaticly) before the commondialog box is opened.

    the objective is to let the user choose either one of the standard colors or 1 of the 6 colors used in their logo.

    Is it possible and how to approach this?

    Thanks in Advance
    Last edited by Dnereb; Oct 18th, 2005 at 07:47 AM.
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: creating custom colors before opening the commondialog box

    Here's an API solution that doesn't require the Common Dialog Control.
    VB Code:
    1. Private Declare Function ChooseColorAPI _
    2.  Lib "comdlg32.dll" Alias "ChooseColorA" ( _
    3.  pChoosecolor As CHOOSECOLOR) As Long
    4.  
    5. Private Type CHOOSECOLOR
    6.     lStructSize As Long
    7.     hwndOwner As Long
    8.     hInstance As Long
    9.     rgbResult As Long
    10.     lpCustColors As Long
    11.     flags As Long
    12.     lCustData As Long
    13.     lpfnHook As Long
    14.     lpTemplateName As String
    15. End Type
    16.  
    17. Public Function ShowColor() As Long
    18.     Dim cc As CHOOSECOLOR
    19.     Dim lReturn As Long
    20.     Dim CustomColors(15) As Long
    21.     Dim i As Integer
    22.    
    23.     'Set the custom colors in the CustomColors array
    24.     CustomColors(0) = vbRed
    25.     CustomColors(1) = vbGreen
    26.     CustomColors(2) = vbYellow
    27.     'and so on
    28.    
    29.     cc.lStructSize = Len(cc)
    30.     cc.hwndOwner = Me.hWnd
    31.     cc.hInstance = 0
    32.     cc.lpCustColors = VarPtr(CustomColors(0))
    33.     cc.flags = 0
    34.     lReturn = ChooseColorAPI(cc)
    35.     If lReturn <> 0 Then
    36.         ShowColor = cc.rgbResult
    37.     Else
    38.         'User clicked the Cancel button so we return -1 instead of a color
    39.         ShowColor = -1
    40.     End If
    41. End Function

  3. #3

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: creating custom colors before opening the commondialog box

    Thanks I will play around with it
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  4. #4
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: creating custom colors before opening the commondialog box

    Quote Originally Posted by Joacim Andersson
    Here's an API solution that doesn't require the Common Dialog Control.
    VB Code:
    1. Private Declare Function ChooseColorAPI _
    2.  Lib "comdlg32.dll" Alias "ChooseColorA" ( _
    3.  pChoosecolor As CHOOSECOLOR) As Long
    4.  
    5. Private Type CHOOSECOLOR
    6.     lStructSize As Long
    7.     hwndOwner As Long
    8.     hInstance As Long
    9.     rgbResult As Long
    10.     lpCustColors As Long
    11.     flags As Long
    12.     lCustData As Long
    13.     lpfnHook As Long
    14.     lpTemplateName As String
    15. End Type
    16.  
    17. Public Function ShowColor() As Long
    18.     Dim cc As CHOOSECOLOR
    19.     Dim lReturn As Long
    20.     Dim CustomColors(15) As Long
    21.     Dim i As Integer
    22.    
    23.     'Set the custom colors in the CustomColors array
    24.     CustomColors(0) = vbRed
    25.     CustomColors(1) = vbGreen
    26.     CustomColors(2) = vbYellow
    27.     'and so on
    28.    
    29.     cc.lStructSize = Len(cc)
    30.     cc.hwndOwner = Me.hWnd
    31.     cc.hInstance = 0
    32.     cc.lpCustColors = VarPtr(CustomColors(0))
    33.     cc.flags = 0
    34.     lReturn = ChooseColorAPI(cc)
    35.     If lReturn <> 0 Then
    36.         ShowColor = cc.rgbResult
    37.     Else
    38.         'User clicked the Cancel button so we return -1 instead of a color
    39.         ShowColor = -1
    40.     End If
    41. End Function
    I am preparing my own color definition routine (maybe add-ins). I have only Visual Basic Editor - Version 6.3. This code writes me an error. How I should change
    VB Code:
    1. Me.
    part of the code? I do not understand what this code should do.

    Boris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width