Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Newbie here, please have patience. I have a loop that checks if a program opens a (windows standard) color dialog, and if that happens, gets the handle of the color dialog and does things to it. I've managed to add controls to this color dialog, but I need to get and set the active color of the dialog and I can't figure how to do it.

Can I convert the handle of the color dialog to a ColorDialog object and set the color with ColorDialog.Color or can I set the color using SendMessage somehow? In the end I want to set the color and programatically "click" the ok button, so that it closes. Any help appreciated.

Edit: Background: I'm making a color picker replacement. When finished it will sit in the background and listen for calls to the windows color picker (from any program), intercept it, get color from it, pass color to my program, let user create/choose a color in my custom color picker and then finally sending that color to the windows color picker and programatically press the "ok" button.
Posted
Updated 27-Nov-15 1:41am
v2
Comments
Sinisa Hajnal 27-Nov-15 6:13am    
Or you could make your own form and pull ColorPicker control on the form:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd940495(v=vs.85).aspx
https://yetcolorpicker.codeplex.com/
https://msdn.microsoft.com/library/ms771620(v=vs.90).aspx

It would make it easier for you to add controls to it too as it would be fully under your control.

1 solution

Here is the solution for your original question:
Create CHOOSECOLOR structure[^]

set CC_RGBINIT flag and set rgbResult to wanted color.

this is the original text from MSDN:
"rgbResult
Type: COLORREF
If the CC_RGBINIT flag is set, rgbResult specifies the color initially selected when the dialog box is created. If the specified color value is not among the available colors, the system selects the nearest solid color available. If rgbResult is zero or CC_RGBINIT is not set, the initially selected color is black. If the user clicks the OK button, rgbResult specifies the user's color selection. To create a COLORREF color value, use the RGB macro.
"


This is the link to
Open color dialog[^]
 
Share this answer
 
v3
Comments
[no name] 27-Nov-15 7:37am    
Thanks for your answer, but what you're quoting is for creating new color dialogs (it I'm not mistaken). I need a way to get and set the color of a color dialog that already exists. I have a handle to the color dialog, I just need a way to communicate with it.
Sinisa Hajnal 27-Nov-15 8:37am    
The answer above contains setting the color shown...isn't that what you need? True, it says initially, but you can try setting it and see what happens.
[no name] 27-Nov-15 9:56am    
Like I said, I'm a newbie, and the info you provided might be useful if I knew how to use it. If I have a handle to a color dialog, how do I set the color using the info above? Do you happen to have an example?
Sinisa Hajnal 27-Nov-15 16:17pm    
Unfortunately, no, I've never needed it, I just used color picker control.
It is simpler (read my comment under the question). Becoming an expert includes many hours of reading and experimenting, taking examples from MSDN or other sources and tweaking them until you understand how it works.

For now, I suggest you try one of the custom controls in the form you control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900