AutoHotkey Community

It is currently May 27th, 2012, 8:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: April 23rd, 2006, 10:07 pm 
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/issue ... lorPicker/

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


Report this post
Top
  
Reply with quote  
PostPosted: April 23rd, 2006, 11:53 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear AGU, :D

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, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2006, 12:53 pm 
Offline

Joined: November 15th, 2005, 11:15 am
Posts: 537
Location: Germany
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 April 25th, 2006, 11:21 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 24th, 2006, 8:49 pm 
Offline

Joined: February 12th, 2005, 8:31 pm
Posts: 82
Goyyah wrote:
Is this request related to your topic CMS for autohotkey.net ? Just curious!

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. :D

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
BBCodeWriterToDo-ListCopyPassage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2006, 10:19 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2008, 12:26 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2008, 1:05 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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 
}

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2008, 1:40 pm 
SKAN - you are my hero!
you saved my day! Thanks a lot!!!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 1:55 am 
Offline

Joined: June 24th, 2008, 8:30 am
Posts: 126
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 5:48 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
smikkelsen wrote:
Do you know of a way to change the window position when it opens?


:arrow: 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
}

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 3:36 pm 
Offline

Joined: October 18th, 2006, 8:07 pm
Posts: 169
That's a great function - thanks! Any idea how to store custom colours for future use using this?

Cheers.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 4:31 pm 
Offline

Joined: October 18th, 2006, 8:07 pm
Posts: 169
Also, is there any way to tell the difference between someone selecting black and pressing cancel ...?

Thank you!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 18th, 2012, 2:42 pm 
Offline

Joined: July 29th, 2011, 9:09 pm
Posts: 16
daorc wrote:
Also, is there any way to tell the difference between someone selecting black and pressing cancel ...?

daorc wrote:
That's a great function - thanks! Any idea how to store custom colours for future use using this?


As I just ran into the same problems, here's an adapted version that stores the custom colors and returns the exit code of the dialog:

Code:
; Example:
; Start with some random colors (optional)
Col:=0xFF0000
CColors:=Object()
Loop 16
  CColors.Insert(A_Index,A_Index*1036335)

If ChooseColor(Col,CColors)=1
{
  SetFormat, Integer, HEX
  b:=Col
  a:="Chosen: " b "`r`nCustom:`r`n"
  Loop 16
  a .= A_Index ": " CColors[A_Index] "`r`n"
  MsgBox, %a%
}
else Msgbox, Cancel!

; Function:

ChooseColor( ByRef Color, ByRef CustColors, hWnd=0x0, Flags=0x103 )
{
;  CC_FULLOPEN := 0x2  CC_RGBINIT := 0x1
  VarSetCapacity(CC,36+64,0)
  NumPut(36,CC)
  NumPut(hWnd,CC,4)
  NumPut(Color,CC,12)
  Loop 16
    NumPut(CustColors[A_Index],CC,32+A_Index*4)
  NumPut(&CC+36,CC,16)
  NumPut(Flags,CC,20)
  RVal:=DllCall( "comdlg32\ChooseColorW", Str,CC )
  Color:=NumGet(CC,12,"UInt")
  CustColors:=
  CustColors:=Object()
  Loop 16
  {
    CustColors.Insert(A_Index,Numget(CC,32+A_Index*4,"UInt"))
  }
  Return RVal ; 1 if OK; 0 if Cancel or Closed
}


Just in case anyone ever looks for this kind of thing again...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], sjc1000, specter333, Yahoo [Bot] and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group