Solved

A better color picker

Posted on 1998-05-08
7
245 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

830 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