 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
AGU Guest
|
Posted: Sun Apr 23, 2006 9:07 pm Post subject: How to call the standard Choose-Color-dialog? |
|
|
Hi,
I'm looking a for a way to call the standard color picker from Windows.
Here's an article in MSDN:
MSDN - Color DialogBox
And another one. Don't know if this is useful
http://msdn.microsoft.com/msdnmag/issues/03/07/GDIColorPicker/
I already found this posting about the standard ChooseFont dialog. Chris said there, this method could be used to call the standard color picker, too.
http://www.autohotkey.com/forum/topic5039.html
But I'm not good at DllCall, Structures and all this things. I would appreciate any help.
During a forum search I also found this 'dirty' color picker. But it just offers three sliders and doesn't show any basic colors for easier orientation like in the standard dialogue. I want a color picker like the standard one that lets you choose a color (by mouse?) and returns the RGB HEX value. (it should work at least in W2k and newer versions)
http://www.autohotkey.com/forum/topic6693.html
So, anybody out there who is interested in doing some nice DllCall
___________________
Cheers
AGU |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Sun Apr 23, 2006 10:53 pm Post subject: Re: How to call the standard Choose-Color-dialog? |
|
|
Dear AGU,
Is this request related to your topic CMS for autohotkey.net ? Just curious!
| You wrote: | | During a forum search I also found this 'dirty' color picker. But it just offers three sliders and doesn't show any basic colors for easier orientation like in the standard dialogue. |
That is the script that I have been using extensively. I have modified it to a large extent, into a Function. I have not modified the GUI much, just to keep it simple.. Now after your post, I wonder If I should include the basic Websafe colours into the GUI.
Basic Color Codes: http://www.computerhope.com/htmcolor.htm
I will be posting my improved version of ColorPicker in forum's Script section soon. This is for your information.
I wish you all the success in bringing out an another fine utility like BBcode Writer.
Regards,  _________________ Suresh Kumar A N |
|
| Back to top |
|
 |
Micha
Joined: 15 Nov 2005 Posts: 500 Location: Germany
|
Posted: Mon Apr 24, 2006 11:53 am Post subject: |
|
|
Hi,
I've changed the original script a little bit...and it works.
Very interesting, what can be done with structs (Extract/insertinteger)
| Code: | Gui, Add, Button, Default gButtonSelectFont, Press this to show font-picker dialog
Gui, Add, Text, w60 right xm, RGB Color:
Gui, Add, Edit, x+10 ReadOnly vColor
; Most of the setup for the font picker dialog needs to be done only once,
; which is why this section is here rather than in the button's subroutine.
/*
typedef struct tagCHOOSECOLOR {
DWORD lStructSize;
HWND hwndOwner;
HINSTANCE hInstance;
COLORREF rgbResult;
COLORREF* lpCustColors;
DWORD Flags;
LPARAM lCustData;
LPCCHOOKPROC lpfnHook;
LPCTSTR lpTemplateName;
} CHOOSECOLOR, *LPCHOOSECOLOR;
*/
SizeOfStructForChooseColor = 0x24
VarSetCapacity(StructForChooseColor, SizeOfStructForChooseColor, 0)
VarSetCapacity(StructArrayForChooseColor, 64, 0)
Gui, +LastFound
GuiHWND := WinExist() ; Relies on the line above to get the unique ID of GUI window.
InsertInteger(SizeOfStructForChooseColor, StructForChooseColor, 0) ; DWORD lStructSize
InsertInteger(GuiHWND, StructForChooseColor, 4) ; HWND hwndOwner (makes dialog "modal").
InsertInteger(0x0 , StructForChooseColor, 8) ; HINSTANCE hInstance
InsertInteger(0x0 , StructForChooseColor, 12) ; clr.rgbResult = 0;
InsertInteger(&StructArrayForChooseColor , StructForChooseColor, 16) ; COLORREF *lpCustColors
InsertInteger(0x00000100 , StructForChooseColor, 20) ; Flag: Anycolor
InsertInteger(0x0 , StructForChooseColor, 24) ; LPARAM lCustData
InsertInteger(0x0 , StructForChooseColor, 28) ; LPCCHOOKPROC lpfnHook
InsertInteger(0x0 , StructForChooseColor, 32) ; LPCTSTR lpTemplateName
Gui, Show
return
ButtonSelectFont:
nRC := DllCall("comdlg32\ChooseColorA", str, StructForChooseColor) ; Display the dialog.
if (errorlevel <> 0) || (nRC = 0)
{
MsgBox error while calling ChooseColor Errorlevel: %errorlevel% - RC: %nRC%
return
}
; Otherwise, the user pressed OK in the dialog, so determine what was selected.
;GuiControl,, Color, % BGRtoRGB(ExtractInteger(StructForChooseColor, 12))
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
GuiControl,, Color, % BGRtoRGB(ExtractInteger(StructForChooseColor, 12))
SetFormat, integer, d
return
#h::reload
GuiClose:
ExitApp
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; See DllCall documentation for details.
{
SourceAddress := &pSource + pOffset ; Get address and apply the caller's offset.
result := 0 ; Init prior to accumulation in the loop.
Loop %pSize% ; For each byte in the integer:
{
result := result | (*SourceAddress << 8 * (A_Index - 1)) ; Build the integer from its bytes.
SourceAddress += 1 ; Move on to the next byte.
}
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result ; Signed vs. unsigned doesn't matter in these cases.
; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
return -(0xFFFFFFFF - result + 1)
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; To preserve any existing contents in pDest, only pSize number of bytes starting at
; pOffset are altered in it. The caller must ensure that pDest has sufficient capacity.
{
mask := 0xFF ; This serves to isolate each byte, one by one.
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
{
DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index - 1, UInt, 1 ; Write one byte.
, UChar, (pInteger & mask) >> 8 * (A_Index - 1)) ; This line is auto-merged with above at load-time.
mask := mask << 8 ; Set it up for isolation of the next byte.
}
}
BGRtoRGB(oldValue)
{
Value := (oldValue & 0x00ff00)
Value += ((oldValue & 0xff0000) >> 16)
Value += ((oldValue & 0x0000ff) << 16)
return Value
}
return
|
Ciao
Micha
Last edited by Micha on Tue Apr 25, 2006 10:21 am; edited 1 time in total |
|
| Back to top |
|
 |
AGermanUser
Joined: 12 Feb 2005 Posts: 81
|
Posted: Mon Apr 24, 2006 7:49 pm Post subject: Re: How to call the standard Choose-Color-dialog? |
|
|
Nope, sorry . It's for another release (6.1) of BBCodeWriter. I just found out, that phpbb supports hex values for colors. Therefore I want to integrate some color picker into the font color GUI that lets the user pick a custom color if he likes
| Quote: | I will be posting my improved version of ColorPicker in forum's Script section soon. This is for your information.
| Thx. I'm looking forward to it.
| Quote: | I wish you all the success in bringing out an another fine utility like BBcode Writer.
| Concerning CMS for autohotkey.net. As for my person this project is still in first stage. Gathering ideas. Next step would be to create a first version of the website template. I will look into that after release of version 6.1 of BBCodeWriter in case no one else is interested in this project. Have to fix a little displaying bug and integrate that color picker. _________________ Cheers
BBCodeWriter • ToDo-List • CopyPassage |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Wed Apr 26, 2006 9:19 pm Post subject: |
|
|
Dear AGU,
I have posted my AHK ColorPicker @ http://www.autohotkey.com/forum/viewtopic.php?p=57968#57968
The above post was edited/created using BBCodeWrtiter 6.1 . The system Color Picker has been nicely integrated.
Keep the good work going.
Thanks a lot.
Regards,  _________________ Suresh Kumar A N |
|
| Back to top |
|
 |
ds Guest
|
Posted: Fri Oct 17, 2008 11:26 am Post subject: |
|
|
Hello,
I use the script posted by Micha (see above) to integrate the standard
Windows ColorPicker in my GUI and it works fine for me.
The color output of this script is Hex RGB but I need a “R G B” output
(for example: 255 255 255 for color white). After long time of testing
and reading help files I gave up.
Could someone help me by getting a R G B output?!
Best regards
ds |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Fri Oct 17, 2008 12:05 pm Post subject: |
|
|
| ds wrote: | | The color output of this script is Hex RGB but I need a “R G B” output |
| Code: | MsgBox, % ChooseColor()
ChooseColor( Color=0x0, hWnd=0x0, Flags=0x2 ) { ; CC_FULLOPEN := 0x2
VarSetCapacity(CC,36+64,0), NumPut(36,CC), NumPut(hWnd,CC,4), NumPut(Color,CC,12)
NumPut(&CC+36,CC,16), NumPut(Flags,CC,20), DllCall( "comdlg32\ChooseColorA", Str,CC )
Return NumGet(CC,12,"UChar") "." NumGet(CC,13,"UChar") "." NumGet(CC,14,"UChar")
} |
Edit: In case someone needs it in hex
| Code: | MsgBox, % ChooseColorH()
ChooseColorH( Color=0x0, hWnd=0x0, Flags=0x2 ) { ; CC_FULLOPEN := 0x2
VarSetCapacity(CC,36+64,0), NumPut(36,CC), NumPut(hWnd,CC,4), NumPut(Color,CC,12)
NumPut(&CC+36,CC,16), NumPut(Flags,CC,20), DllCall( "comdlg32\ChooseColorA", Str,CC )
Hex:="123456789ABCDEF0", RGB:=&CC+11
Loop 3
HexColorCode .= SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
Return HexColorCode
} |
_________________ Suresh Kumar A N |
|
| Back to top |
|
 |
ds Guest
|
Posted: Fri Oct 17, 2008 12:40 pm Post subject: |
|
|
SKAN - you are my hero!
you saved my day! Thanks a lot!!! |
|
| Back to top |
|
 |
smikkelsen
Joined: 24 Jun 2008 Posts: 102
|
Posted: Wed Apr 08, 2009 12:55 am Post subject: |
|
|
SKAN, thanks a lot for sharing your color function, it is very useful. Do you know of a way to change the window position when it opens? Obviously i could use something like winmove, but i would probably have to use a timer and stuff. Is there a good way to change any of the settings of the window that comes up?
Thanks again. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Wed Apr 08, 2009 4:48 am Post subject: |
|
|
| smikkelsen wrote: | | Do you know of a way to change the window position when it opens? |
If you specify a parent window, then the color dialog dialog would be shown @ coordinates 0,0 of the parent window.
Here is an example to show the dialog in the middle of user's screen.
| Code: | Gui, 99:+LastFound
Gui, 99:Show, w453 h324 Hide
hwnd := WinExist()
MsgBox, % ChooseColorH( 0x0, hwnd )
ChooseColorH( Color=0x0, hWnd=0x0, Flags=0x2 ) { ; CC_FULLOPEN := 0x2
VarSetCapacity(CC,36+64,0), NumPut(36,CC), NumPut(hWnd,CC,4), NumPut(Color,CC,12)
NumPut(&CC+36,CC,16), NumPut(Flags,CC,20), DllCall( "comdlg32\ChooseColorA", Str,CC )
Hex:="123456789ABCDEF0", RGB:=&CC+11
Loop 3
HexColorCode .= SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
Return HexColorCode
} |
_________________ Suresh Kumar A N |
|
| Back to top |
|
 |
daorc
Joined: 18 Oct 2006 Posts: 89
|
Posted: Thu Dec 17, 2009 2:36 pm Post subject: |
|
|
That's a great function - thanks! Any idea how to store custom colours for future use using this?
Cheers. |
|
| Back to top |
|
 |
daorc
Joined: 18 Oct 2006 Posts: 89
|
Posted: Thu Dec 17, 2009 3:31 pm Post subject: |
|
|
Also, is there any way to tell the difference between someone selecting black and pressing cancel ...?
Thank you! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|