Shoutbox

WriteDWORD - sending hex value from 3 decimal values - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: WriteDWORD - sending hex value from 3 decimal values (/showthread.php?tid=79840)

WriteDWORD - sending hex value from 3 decimal values by MeEtc on 12-09-2007 at 09:04 PM

code:
CHOOSECOLOR.WriteDWORD(12, 0x00000000); //COLORREF rgbResult (COLORREF = 0x00bbggrr)

How can I pass RGB colour values in a string to this function?


I swear I'm not making all these posts to get a higher post count, honest!
RE: WriteDWORD - sending hex value from 3 decimal values by ShawnZ on 12-09-2007 at 09:23 PM

var blue = 0xFF;
var green = 0xFF;
var red = 0xFF;

var color = (blue<<16)+(green<<8)+(red)

i think.


RE: WriteDWORD - sending hex value from 3 decimal values by MeEtc on 12-09-2007 at 09:56 PM

that doesn't help, if the values are coming from a string, like "#RRGGBB". So I use substr to separate the 3 colour values, but that doesn't turn it into a hex value

EDIT: mynetx provided me a solution

code:
CHOOSECOLOR.WriteDWORD(12, eval('0x00'+b+g+r));

RE: WriteDWORD - sending hex value from 3 decimal values by Matti on 12-10-2007 at 11:47 AM

Noes! You do know that eval() is evil? :O
You can simply use parseInt() on the different parts and choose 16 as base. This way, JScript will convert the string itself from hexadecimal to a decimal number. ;)

code:
var sColor = "#001122";
var r = parseInt(sColor.substr(1, 2), 16);
var g = parseInt(sColor.substr(3, 2), 16);
var b = parseInt(sColor.substr(5, 2), 16);

var color = (b<<16) + (g<<8) + r;

CHOOSECOLOR.WriteDWORD(12, color);

RE: WriteDWORD - sending hex value from 3 decimal values by Felu on 12-10-2007 at 11:52 AM

quote:
Originally posted by Mattike
var color = (blue<<16) + (green<<8) + red;
Rather
code:
var color = (b<<16) + (g<<8) + r;

Just saw that both the methods give different results :S.
code:
var color = (b<<16) + (g<<8) + r; // #001122 => 1444608
var color = eval('0x00'+b+g+r); // #001122 => 139536

RE: WriteDWORD - sending hex value from 3 decimal values by Matti on 12-10-2007 at 12:10 PM

Riiiiight!

We'll need a hexadecimal-to-decimal conversion instead of a multiply-by-one! :D
Now fixing post...