Solved

A better color picker

Posted on 1998-05-08
7
244 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…

803 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