Last year I createde ColRef addin for RadAsm. It was later replaced by InsertColor addin. Now I have had need of picking colors from the screen so I improved my old ColRef addin. For those who are interested you can either choos color from the common dialog or pick a color from the screen. It is tested on win 2000.

Dll and source code are attached.

Posted on 2003-06-18 05:51:26 by minor28

This is it. I'm sure minor28 will like the new look. I got rid of the dual window idea and consolidated everything onto the ChooseColor dialog. I painted the dialog to make it look nicer. The choosecolor dialog is a template now, if you've never done a common dialog template this is how. The messages are all handled in the callback for the ChooseColor dialog, another good example on how to do something. Pressing OK on the dialog will not close it, only copy the color info to the edit controls. Use the insert buttons to insert the color number. New feaatures:

Saves the custom colors.

The top row of custom colors is saved to RadASM.ini and is available to all projects.
The bottom row is available to the current project and is saved in the Rap file.
Will capture a number at the cursor for the initial color

< use minor28's version at the bottom of the thread :) >

It's his addin after all...
Posted on 2003-06-22 16:10:21 by donkey
For those of you who would like to use the dialog templates to modify the common dialogs (I like to do this) I use a res file that I generated from the common dialog dll. Use res2dlg to extract the dialogs and then modify them in RadASM. I've only tested the find and choose color dialogs but they should all be ok.

(Be sure to get the new Res2Dlg the one in RadASM will crash)
Posted on 2003-06-22 23:49:56 by donkey
Yes donkey,

I like the new look. I am sure your intention of the dialog title is not to take the credit from me, but personly I would prefer a more neutral title as "Color reference". I think you are too modest. Why not begin the colref.asm and colref.txt with

"Code by minor28 and donkey in cooperation".

If I may wish, it would be nice if the captured color also could be added to the custom colors.

Best regards
Posted on 2003-06-23 01:18:41 by minor28

It's your addin, I just worked on the interface, you deserve the credit. As for the title, don't be shy, you did good work, everybody should know. ;).

I left my nick in the source (and the upcoming help file), it's ok there. I'll leave the adding of the captured colours to you, it should just be a matter of copying the RGB values into the dialog text boxes (SetDlgItemInt)
Posted on 2003-06-23 01:44:47 by donkey
One more idea for your addin that I had is you can add text capture that will copy the text at the cursor into the dialog and display the colour. You can check BitMask to see how I handled it with both hex and decimal numbers. That way if you have a colour in hex format in your code and you want to know what it is you just put the cursor on it and press the button.

I added this myself as I'm familiar with the code and it was fairly easy for me. I updated the file in my original link. I did the capture color to chooser thingy as well so you put the captured colors into the favourites, I had nothing else to do and my air conditioning is broken, can't sleep at 28c :(
Posted on 2003-06-23 02:09:49 by donkey
Now the captured color is inserted in the common dlg part and can be saved as custom colors.

Posted on 2003-06-23 11:38:27 by minor28
Whoops, I added that to my version in the end, couldn't sleep last nite :eek:

I've removed my copy so there is no confusion.
Posted on 2003-06-23 11:43:08 by donkey
Hi Minor28,

Maybe have the color dialog updated only when a color has been selected. It is a little hard on the eyes to see all of that flashing when it is being updated on each mousemove. Outside of that nice job :alright:
Posted on 2003-06-23 11:54:54 by donkey
First I was going to update the dialog only when a color had been selected. But then I found that it is easier to hit the right spot if you can see the color. You don't have to look at the dialog all the time only when you are near the spot you are interested in.
Posted on 2003-06-23 12:07:14 by minor28
Yes, you're right. it is much better to see the transitions.
Posted on 2003-06-23 12:26:43 by donkey
Maybe put turning it off as an option :
;Write pic color to common dialog

.IF Opt != 2
xor eax,eax
mov al,byte ptr [color + 2]
push eax
invoke wsprintf,addr colref,SADD('%ld')
invoke SetDlgItemText,hCCDlg,708,addr colref
mov al,byte ptr [color + 1]
push eax
invoke wsprintf,addr colref,SADD('%ld')
invoke SetDlgItemText,hCCDlg,707,addr colref
mov al,byte ptr color
push eax
invoke wsprintf,addr colref,SADD('%ld')
invoke SetDlgItemText,hCCDlg,706,addr colref
This way if you have an LCD screen (like I do) it isn't as hard on the eyes. I'm trying to think of a way to use the WM_PAINT message to have just the colour box updated but it doesn't go well.

In this case option 2 will tun it off
Posted on 2003-06-23 13:00:37 by donkey
I added the turning off option. Testing the option turned the flashing off but to my surprise the dialog was updated with the captured color. Then I found your "SelectToDialog" function. So I suppose I downloaded your version before you
Whoops, I added that to my version in the end, couldn't sleep last nite

I've removed my copy so there is no confusion.
Posted on 2003-06-23 14:02:48 by minor28
I added a button "Color ref" to utilize donkey's facility to capture a color reference in RadAsm by the mousepointer and show the color in the dialog. Now you can show the color not only at dialog start up but also by pushing the button. I think that's all

Posted on 2003-06-24 13:30:22 by minor28

I found it annoying that choosing a color from the color picker window always result in black. So I wanted to set Lum: to 120. Not to interfere with the start up color reference I choose WM_LBUTTONUP
.elseif uMsg==WM_LBUTTONUP

mov eax,lParam
and eax,0ffffh
mov lpPoint.x,eax
mov eax,lParam
shr eax,16
mov lpPoint.y,eax
.if (lpPoint.x>225 && lpPoint.y<415 && lpPoint.y>3 && lpPoint.y<187)
invoke SetDlgItemInt,hCCDlg,705,120,FALSE

How should I do to get the rectangle values from code and not as I did from the property list in RadAsm. I have tried several ways but all fails.

Posted on 2003-06-26 12:27:18 by minor28
I think that you can verify that there is no number present at the cursor and set a default value for the luminosity to say 120 (50%) when the dialog starts. You can pick a neutral color like light gray if no rgbinit value is supplied. The cursor capture of the number is capable of returning a default color if there is not a valid number at the cursor. Altering the choice after initializing the dialog would not be a good idea as it might interfere with the selection of colors.
ParseInput proc InputMask:DWORD

LOCAL buffer[256] :BYTE

invoke lstrcpy,ADDR buffer,InputMask
lea eax,buffer
mov InputMask,eax

mov edx,InputMask
mov al,[edx]
.IF al >= "0" && al <= "9"
invoke StrLen,InputMask
mov edx,InputMask
add edx,eax
sub edx,1
mov al,[edx]
.IF al == "h" || al == "H"
mov [edx],BYTE PTR 0
mov edx,InputMask
invoke htodw,edx
invoke atodw,InputMask
[color=red][b]mov eax,DefaultColor[/b][/color]
ParseInput endp
Posted on 2003-06-26 13:51:33 by donkey
Ok donkey

The easy way is to do what you proposed. Just replace "xor eax,eax" with "mov eax,007F7F7Fh". But I couldn't give up the thought of the WM_LBUTTONUP idea. This is a code that works.
.elseif uMsg==WM_LBUTTONUP

invoke GetDlgItem,hCCDlg,710
mov hwnd,eax
invoke GetClientRect,hwnd,addr rect
;Convert upper left corner to POINT structure
mov eax,rect.left
mov lpPoint.x,eax
mov eax,rect.top
mov lpPoint.y,eax
mov times,1
;Convert client coordinates to screen coordinates
invoke ClientToScreen,hwnd,addr lpPoint
push lpPoint.y ;Store y-coordinate
push lpPoint.x ;Store x-coordinate
;Convert upper left corner point of the dialog window
mov lpPoint.y,0
mov lpPoint.x,0
;Convert to Screen coordinates
invoke ClientToScreen,hCCDlg,addr lpPoint
pop eax ;Restore x-coordinate of Client rect (Screen coordinates)
sub eax,lpPoint.x ;Sub dialog x-coordinat from client x-coordinat
mov lpPoint.x,eax ;Client x-coordinat with origo on upper left corner of the dialog
mov eax,lParam
and eax,0ffffh ;Get lowword of lParam = x-coordinate of mousepointer
cmp times,0
je @1
cmp eax,lpPoint.x
jle @F ;if less or equal jump out
jmp @2
cmp eax,lpPoint.x
jge @F
pop eax ;Restore y-coordinate of client rect (Screen coordinates)
sub eax,lpPoint.y ;Sub dialog y-coordinat from client y-coordinat
mov lpPoint.y,eax ;Client y-coordinat with origo on upper left corner of the dialog
mov eax,lParam
shr eax,16 ;Get hiword of lParam = y-coordinate of mousepointer
cmp times,0
je @3
cmp eax,lpPoint.y
jle @F ;if less or equal jump out
jmp @4
cmp eax,lpPoint.y
jge @F
invoke SetDlgItemInt,hCCDlg,705,120,FALSE
jmp @F
mov eax,rect.right
mov lpPoint.x,eax
mov eax,rect.bottom
mov lpPoint.y,eax
mov times,0
jmp @B

Does it have to be so complecated? I would be very interested if there is a simplier and better way to go, i.e. the point way.

Posted on 2003-06-26 17:06:04 by minor28
This is much less complicated :
.elseif uMsg==WM_LBUTTONUP

invoke GetCursorPos,ADDR lpPoint
invoke ChildWindowFromPoint,hCCDlg,lpPoint.x,lpPoint.y
push eax
invoke GetDlgItem,hCCDlg,710
pop ecx
.IF eax==ecx
invoke SetDlgItemInt,hCCDlg,705,120,FALSE
Posted on 2003-06-26 18:58:48 by donkey
As a matter of fact I have already made an attempt on that one and several others but none works only my complicated code. Why your code not works I suppose is due to GetCursorPos gives values in screen coordinates and ChildWindowFromPoint requires client coordinates values.
Posted on 2003-06-27 00:35:14 by minor28
Works for me, if you select a color from the dither static it automatically sets the luminosity to 120, anywhere else it takes it at the selected value unaltered. That is by far the most elegant solution, otherwise you are changing values that the user might want to retain. Yes, it is supposed to be client coords but it seems to work, I wonder why. Oh well, just but in a screentoclient and it should be 100%
Posted on 2003-06-27 00:49:00 by donkey