I don't really want to ask but I'm stuck. I'm using the ChooseColor API to display the common color dialog. This part works great but dealing with the result is giving me problems. I'm trying display the RGB speratly in their own edits so I'm trying to split the hex value result into three like so, if they had chossen White, FF in one FF in another and FF in the last one (RGB). This should be easy, I can't see it being so difficult, I must be over looking something here!

Anyways now after I display the three values I want to put them back into hex form. Converting them I can do but, but how to I get three hex values into one afterwards?

I'm understanding assembly but I'm having troubles doing data manipulation like above.

Thanks for any pointers! I hope haven't confused you,
Posted on 2002-02-12 16:07:21 by JamesE
To put them back together as an RGB value, do this:

- do not destroy the original RGB value, then you will not need to reassemble it :)

- use the RGB macro that is supplied with the MASM install that hutch puts together. Using that, your code will look something like this:

RGB redVal, blueVal, greenVal
mov newRGBValue, eax

If you use the macro, note that it accepts byte values, not DWORDs.
Posted on 2002-02-12 17:00:56 by sluggy
Im not sure if the clocks go by how many bits you roll by, but if it does, than this is an improvement.... I think.

Hutch's macro:
RGB MACRO red, green, blue
xor eax, eax
mov al, blue ; blue
rol eax, 8
mov al, green ; green
rol eax, 8
mov al, red ; red

My macro:
RGB MACRO red, green, blue
xor eax, eax
mov ah, blue ; blue
shl eax, 8
mov ah, green ; green
mov al, red ; red

A little smaller and a little faster.... maybe
Posted on 2002-02-12 21:16:28 by CsnWltr
hi again,

This might sound stupid :rolleyes: but how to I pass the numbers to the macro?

local buffer1[3]:byte
local buffer2[3]:byte
local buffer3[3]:byte

invoke GetDlgItemText, hWnd, IDC_FOREB, addr buffer1, 3
invoke GetDlgItemText, hWnd, IDC_FOREG, addr buffer2, 3
invoke GetDlgItemText, hWnd, IDC_FORER, addr buffer3, 3

RGB buffer1, buffer1, buffer1

This doesn't work...

Thanks for the idea though!
Posted on 2002-02-12 22:15:06 by JamesE

The important part is that the macro must be filled with 3 single BYTE values, as you can see with it or the 1 instruction smaller one posted by CsnWltr, the 3 byte values are added to a 32 bit register that has been XORRED so the first BYTE is zero, you add the next three to make a DWORD in the register filled in COLORREF format.

Now this is simple enough stuff once u have the reference,

COLORREF = 00GGBBRR where GG = the green value, BB = the blue value and RR is the red value.

This gives you a COLORREF value in the EAX register in both macros.

Now having a quick look at your code, you are not converting the buffer with the three calls to "GetDlgItemText" into a number first. Use the MASM32 library to do this, then use the low BYTE of the DWORD return value for each parameter in the macro.


Posted on 2002-02-12 23:33:30 by hutch--
okay... so heres the code now with the converting strings but I don't know how to get the low byte of eax into a variable.

local buffer1[3]:byte
local buffer2[3]:byte
local buffer3[3]:byte
local MyR:byte
local MyG:byte
local MyB:byte

invoke GetDlgItemText, hWnd, IDC_FOREB, addr buffer1, 3
invoke atodw, addr buffer1
mov MyB, al

invoke GetDlgItemText, hWnd, IDC_FOREG, addr buffer2, 3
invoke atodw, addr buffer2
mov MyG, al

invoke GetDlgItemText, hWnd, IDC_FORER, addr buffer3, 3
invoke atodw, addr buffer3
mov MyR, al


I also tried some thing like mov MyR, al I'm so confused:confused:

Okay I got it to accept the values using
mov MyR, al
but al doesn't seem to be big enough. When the edits all have 255, the color doesn't turn white it's a darkish green.
Posted on 2002-02-13 11:08:42 by JamesE
AL is the low byte of EAX

You really should read the Intel Manual - life as an ASM programmer would be so much easier; you'd be amazed at what is possible. :tongue:
Posted on 2002-02-13 11:26:49 by bitRAKE
I am using al, I just never changed the code above... I do that now... but I'm still having the problem of getting a dark green instead of white
Posted on 2002-02-13 11:30:34 by JamesE
Perhaps you should try GetDlgItemInt instead, if you know the edit boxes only hold numbers....

I'd also suggest "IDC_FOREB" would hold your blue value, so moving it to MyR would be wrong (not that that will affect your white colour)!

al is definitely big enough to hold an unsigned value between 0 and 255 (it fact that is exactly what it holds with it being 8 bits wide n all).


Just thinking... Are you holding the number in your edit boxes as hex?
Posted on 2002-02-13 11:38:34 by Mirno
Oops.. I forgot I switched those values around... I fixed.... I'll try your idea using GetDlgItemInt after I get home from work...

Thanks for all the replys lets hope it works!;)
Posted on 2002-02-13 11:46:29 by JamesE
Hey it works!!:alright: I don't know why I had to make it more difficult than it had to be. I even seen that api mentioned on the MSDN CD next to the GetDlgItemText? arrgghh.... I guess I was too tired!

Thanks to you all eh ;),
James Emmrich
Posted on 2002-02-13 20:07:33 by JamesE