Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a ColorName to its RGB values... 2

Status
Not open for further replies.

XPPROGRAMMER

Programmer
Nov 15, 2004
44
0
0
US
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.

 
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:




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'.
 
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
However, the code would be in VB. Is that any good to you?
 
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'.
 
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.
 
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:
[blue]Private Function GetColourByName(strColorName As String) As String
    With New HTMLDocument
        .bgColor = strColorName
        GetColourByName = Replace(.bgColor, "#", "&h") [green]'To get it in a VB hex format rather than web hex format[/green]
    End With
End Function[/blue]
 
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)
 
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

***












 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top