×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Convert a ColorName to its RGB values...
2

Convert a ColorName to its RGB values...

Convert a ColorName to its RGB values...

(OP)
Hello Everyone,

is there a win32 API function that would convert a color
name into its RGB values? For example, if I provide the
color name "white" --- the function would return the RGB
value (255, 255, 255).

thanks for the help.

RE: Convert a ColorName to its RGB values...

Not that I know of but you could build your own structure or enumeration with some your most frequent colors. Here's a link to some colors and their corresponding RGB values:

http://www.aion-needlecrafts.co.uk/info/dmcvalus.htm



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.

RE: Convert a ColorName to its RGB values...

Of course you can...and we don't use the API to do it...I can put an example together pretty quickly (about 3 lines of code) that can correctly identify and translate all the colour names found on the Web Color Names Chart on this page http://www.globalvillage.net/web_masters_color_chart.htm

However, the code would be in VB. Is that any good to you?

RE: Convert a ColorName to its RGB values...

3 lines of code?!?!?!

RE: Convert a ColorName to its RGB values...

I believe he's using microfocus Cobol.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.

RE: Convert a ColorName to its RGB values...

(OP)
Hello,

DrJavaJoe have a very good Memory, I am using micro focus
cobol compiler (Net Express 4.0) with windows 2000 pro.
however, I can convert any code from C, C++ or VB as long
as it uses a standard win32 API's or C functions, which
uses the pascal calling convention as cobol does.
thanks for the kind help.

RE: Convert a ColorName to its RGB values...

OK, here's the VB function. In the VB environment you would need to add a reference to the  Microsoft HTML Object library, so you'd need to do the same with Microfocus Cobol. Once the reference is added you can do this:

CODE

Private Function GetColourByName(strColorName As String) As String
    With New HTMLDocument
        .bgColor = strColorName
        GetColourByName = Replace(.bgColor, "#", "&h") 'To get it in a VB hex format rather than web hex format
    End With
End Function

RE: Convert a ColorName to its RGB values...

Oh - I should probably point out that the Microsoft HTML Object library is actually just a type library rather than an ActiveX library (I believe the two things are handled slightly differently by Microfocus Cobol)

RE: Convert a ColorName to its RGB values...

(OP)
Hi StrongM,

I've found a cobol library routine that looks very
efficient to use than the VB function provided above,
especially since I don't have to reference an HTML web
document. So, in case someone is wondering, the listed
below code is the cobol library routine.
thanks for the kind help and efforts.  Regards.

call "CBL_SCR_NAME_TO_RGB" using
       by reference color-name
       by reference RGB-values
    returning       status-code
end-call.

color-name = "ColorName" on entry
rgb-values = will receive RGB numbers upon return

***












  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close