Solved

A better color picker

Posted on 1998-05-08
7
241 Views
Last Modified: 2008-02-01
Is there a way to let the user pick a color other than using ComCtrl32.dll? I'm looking for either API calls that do not require ComCtrl32 installed on the user's PC or a thirdparty small control that does the job in VB5.
0
Comment
Question by:cellphone
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1444221
You could create your own with a form and several shape controls.
0
 
LVL 4

Accepted Solution

by:
zsi earned 100 total points
ID: 1444222
Check out ftp://ftp.cgvb.com/pub/misc/palette.zip for a complete code-based color picker.

zsi
0
 
LVL 4

Expert Comment

by:zsi
ID: 1444223
Here is a description of the program:

Written by Keith Maune
        Email: Keith.Maune@Nashville.com
        WWW Homepage:  http://www.nashville.com/~keith.maune/
  Please write to me about my programs, whether you have a
  question, or just tell me if you like it.

This program allows selecting of 16.7 million colors in a
variety of ways.  You can use scrollbars to change the green,
blue, and red intensities of a color, select the color from
a grid of common colors, or type the hexadecimal code for
the color.  The program displays the seperate red, blue,
and green intensities of the color, the intensity of the color
in decimal form (0-255), the hexadecimal code for the color,
the nearest solid color, and the current color at all times.
You can use this program to select colors for a variety of
purposes.  Or, you can add the included source code to a
Visual Basic project for a complete, ready-to-go color
selection form.

Hope this helps!
zsi
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cellphone
ID: 1444224
That Was FAST! but his site is down. Can you email me the zip? safari@nbn.com. THANKS!
0
 

Author Comment

by:cellphone
ID: 1444225
Pallette is nice, but I'm looking for something that I don't have to code myself.To use this, I'd have to basicall redo this from scratch to make it compatable with the rest of the app. Is there a way to call the color picker via API or is there a 3rd party control that does the job?
0
 
LVL 4

Expert Comment

by:zsi
ID: 1444226
Oh, that.  Well, the code from the sample app that I referred to isn't complex, but if you want to invoke the color picker from the Common Dialog without using an OCX try this:

Create a form with a command button on it (Commad1) and insert the following code:


Add the following code to the General Declarations section of the form:

Option Explicit

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

   Dim CustomColors() As Byte

   Private Sub Command1_Click()
       Dim cc As CHOOSECOLOR
       Dim Custcolor(16) As Long
       Dim lReturn As Long
       cc.lStructSize = Len(cc)
       cc.hwndOwner = Me.hWnd
       cc.hInstance = 0
       cc.lpCustColors = StrConv(CustomColors, vbUnicode)
       cc.flags = 0
       lReturn = ChooseColorAPI(cc)
       If lReturn <> 0 Then
           Me.Caption = "RGB Value User Chose: " & Str$(cc.rgbResult)
           Me.BackColor = cc.rgbResult            ' Visual Basic only ****
           CustomColors = StrConv(cc.lpCustColors, vbFromUnicode)
       Else
           MsgBox "User chose the Cancel Button"
       End If
   End Sub

   Private Sub Form_Load()
       ReDim CustomColors(0 To 16 * 4 - 1) As Byte
       Dim i As Integer

       For i = LBound(CustomColors) To UBound(CustomColors)
           CustomColors(i) = 0
       Next i
   End Sub
0
 
LVL 4

Expert Comment

by:zsi
ID: 1444227
There is a much nicer way to do it.  FIll a picture box with a gradient fill offering the entire spectrum available from the color depth (dithered if necessary).  A lot of profrssional graphics packages do this.  

If someone has the code to fill such a box, I will finish out the code to pick the actual color.

zsi
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 52
VB error "Type mismatch" 2 49
Sending a email via excel using vba 6 71
VB6 ListBox Question 4 32
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now