Solved

A better color picker

Posted on 1998-05-08
7
240 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now