|
-
Jul 6th, 2002, 03:03 AM
#1
Thread Starter
PowerPoster
Integer to Hexadecimal
I am using a structure who has its three parameters declared as "COLOR16". I didn't find any documentation for it on MSDN but it says the value of COLOR16 can range from 0x0000 to 0xff00. This is hex but I have an integer that I want to pass it. Example:
PHP Code:
TRIVERTEX vert[2] ;
vert [0] .Red = GetRValue(mycolor);
vert [0] .Green = GetGValue(mycolor);
//.....
.Red and .Green are decalred as COLOR16. But GetRValue is either BYTE or int. It just doesn't work if I use the above method of typecast it like "(COLOR16)GetRValue(mycolor)". It only works if I provide a haxadecimal value.
How can I make it work WITH a variable instead of just passing it a non-declared hex value?
-
Jul 6th, 2002, 03:06 AM
#2
Thread Starter
PowerPoster
Hmmm, I just tried declaring the RGB values as COLOR16 but it still doesn't work.
PHP Code:
COLOR16 r1, g1, b1;
r1 = (COLOR16)GetRValue(crColour1);
g1 = (COLOR16)GetRValue(crColour1);
b1 = (COLOR16)GetGValue(crColour1);
TRIVERTEX vert[2] ;
vert [0] .x = 0;
vert [0] .y = 0;
vert [0] .Red = r1;
vert [0] .Green = g1;
vert [0] .Blue = b1;
vert [0] .Alpha = 0x0000;
//....continued....
-
Jul 6th, 2002, 11:56 AM
#3
This might help, I haved tested it and it work if you change the int x =1 to unsigned int x =1
http://planet-source-code.com/vb/scr...=4064&lngWId=3
-
Jul 6th, 2002, 12:38 PM
#4
Thread Starter
PowerPoster
-
Jul 7th, 2002, 01:32 PM
#5
Why ? You just want to convert the number isn't?
-
Jul 8th, 2002, 12:22 AM
#6
Thread Starter
PowerPoster
Yes, but I don't want to convert that number to a string which contains the hexdecimal value of it. Because there's no variable type of hold hexadecimal, I won't be able to store this number and then pass it as a colour.
It's just weird that the structure isn't accepting any integer although it's happily using its hexadecimal form (0x....).
-
Jul 8th, 2002, 05:13 AM
#7
COLOR16 is unsigned short (USHORT) - a two byte unsigned integer.
-
Jul 8th, 2002, 03:56 PM
#8
Thread Starter
PowerPoster
ya, it's USHORT after I looked at the wingdi.h header file. But how would I do the conversion?
-
Jul 9th, 2002, 12:12 PM
#9
Maybe what I will said it's idiot but you can not simply cast it?
-
Jul 9th, 2002, 01:53 PM
#10
Thread Starter
PowerPoster
Yes, that's what I did but it didn't work.
(COLOR16)GetRValue(crColour);
-
Jul 9th, 2002, 02:13 PM
#11
Lively Member
try using (USHORT)GetRValue(crColour);
-
Jul 10th, 2002, 08:20 PM
#12
What does GetRValue return?
What is the error?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 10th, 2002, 09:26 PM
#13
Thread Starter
PowerPoster
GetRValue returns a BYTE which is the value of red colour in a colour. I don't get any error but the function just does draw the correct gradient (it doesn't use the values I provide) unless I provide it a hex value (0x****).
-
Jul 11th, 2002, 02:51 AM
#14
Hyperactive Member
from MSDN
Code:
//declaraction of GetRValue
BYTE GetRValue(
DWORD rgb // RGB value
);
Just convert your parameter variables to DWORD will do.
DWORD is double word, meaning it is unsigned integer(32bit) alias.
For your FYI, hex, octal and based 10 representation are the same in binary so there is no reason that they cannot be interchangeable.
The reason 0x**** works is bcos it is a constant implicitly casted into DWORD.
When u put variables in, it couldn't work, meaning the variables u used cannot be cast into DWORD.
Another reason is GetRValue takes it that (assuming u put in 16bit variable) every colour component in the parameter is 8 bit, but in 16bit variable, every colour compnent is not 8 bit, rather than 565, so when u put in 16bit(implictly casted and zero-extended to 32bit), GetRValue() extracts 8 bits(5 of red + 3 of green), insteads of 5bits for red.
Of course, when u put in hex constants, it worked ,but in a wrong way for u.
Do I make myself clear?
-
Jul 11th, 2002, 02:54 AM
#15
Hyperactive Member
If u previously had put in a DWORD, then I have nothing to say.
-
Jul 11th, 2002, 04:08 AM
#16
Thread Starter
PowerPoster
There is no problem with GetRValue(). I returns the correct red value and I can use this value with many many other functions which also works. The only problem is that I can't assign this value to the structure I just talked about above because it takes it as COLOR16.
Weird thing is that typecasting isn't work here either.
-
Jul 11th, 2002, 11:31 AM
#17
Hyperactive Member
Why dun u just change the structure members, Red, Green and Blue to BYTE?
You doesn't need them to be COLOR16, right?
-
Jul 11th, 2002, 02:14 PM
#18
Thread Starter
PowerPoster
The structure is defined in Windows API - not by me.
-
Jul 13th, 2002, 09:11 PM
#19
You can't cast from different color systems just like that.
You need to recalculate the values. e.g. if you have the color value 4 when 16 are possible, it becomes 16 when 64 are possible. You can't simply change their type.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|