Conversion principle:
The calculation is: (65536 * Blue) + (256 * Green) + (Red)
' Convert RGB to LONG:
LONG = B * 65536 + G * 256 + R
' Convert LONG to RGB:
B = LONG \ 65536
G = (long-b * 65536) \ 256
R = long-b * 65536-G * 256
Conversion function: (inside VS2010 debugging Pass)
BOOL Convertcolor_longtorgb (const __int64 L_COLOR_SCR, int& r_des, int& g_des,int&);
BOOL Mainapp::convertcolor_longtorgb (const __int64 L_COLOR_SCR, int& r_des, int& g_des,int&)
{
int color_long_min = 65536;
int color_rgb_max = 256;
if (l_color_scr<color_long_min)
{return
false;
}
B_des = l_color_scr/color_long_min;
G_des = (L_color_scr-b_des * color_long_min)/Color_rgb_max;
R_des = l_color_scr-b_des * color_long_min-g_des * COLOR_RGB_MAX;
return true;
}
Call Method:
LONG color_long=0;
Color_long = 12632256;
int r=0;
int g=0;
int b=0;
Convertcolor_longtorgb (color_long,r,g,b);
cout<< "R:" <<R<<endl;
cout<< "G:" <<G<<endl;
cout<< "B:" <<B<<endl;
The above mainly uses, when extracts the BackColor value from the webpage, will obtain is the long type color value, this time needs to convert to the RGB use.
For example:
VARIANT Pcmdvalue;
:: VariantInit (&pcmdvalue);
BSTR BSTR = SysAllocString (OleStr (""));
Range->querycommandvalue (SysAllocString (Command.wc_str ()), &pcmdvalue); Get Pcmdvalue
if (PCMDVALUE.VT!= vt_empty) and your code ...
............................
Http://www.pbdr.com/pbtips/ps/rgblong.htm
The above page describes the relationship between long and RGB.
My test example is: 192,192,192 Gray.
Add: Inside the control to get color RGB, how to convert to the Web page needs to #ff00ff it. Please see below
Wxstring fontcolor=wxt ("");
Wxcolor Wxcolor_font = Retdata.getcolour ();
FontColor = Fontcolor.format (Wxt ("#%02x%02x%02x"),
Wxcolor_font.red (),
Wxcolor_font.green (),
Wxcolor_font.blue ());
Finish.