Hey,
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,
James
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,
James
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:
If you use the macro, note that it accepts byte values, not DWORDs.
- 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.
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
ENDM
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
ENDM
A little smaller and a little faster.... maybe
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
ENDM
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
ENDM
A little smaller and a little faster.... maybe
hi again,
This might sound stupid :rolleyes: but how to I pass the numbers to the macro?
This doesn't work...
Thanks for the idea though!
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!
James,
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.
Regards,
hutch@movsd.com
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.
Regards,
hutch@movsd.com
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.
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.
.code
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
RGB MyR, MyG, MyB
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.
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:
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:
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
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).
Mirno
Just thinking... Are you holding the number in your edit boxes as hex?
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).
Mirno
Just thinking... Are you holding the number in your edit boxes as hex?
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!;)
James
Thanks for all the replys lets hope it works!;)
James
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
Thanks to you all eh ;),
James Emmrich