如何设置从其他程序打开的颜色对话框的颜色? [英] How do I set the color of a color dialog opened from another program?

查看:45
本文介绍了如何设置从其他程序打开的颜色对话框的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手在这里,请耐心等待。我有一个循环,检查程序是否打开一个(Windows标准)颜色对话框,如果发生这种情况,获取颜色对话框的句柄并执行操作。我已设法为此颜色对话框添加控件,但我需要获取并设置对话框的活动颜色,我无法想象如何操作。



我可以将颜色对话框的手柄转换为ColorDialog对象并使用ColorDialog.Color设置颜色,还是可以使用SendMessage以某种方式设置颜色?最后我想设置颜色并以编程方式单击确定按钮,以便关闭。任何帮助表示感谢。



编辑:背景:我正在更换颜色选择器。完成后,它将坐在后台,听取窗口颜色选择器的调用(从任何程序),拦截它,从中获取颜色,将颜色传递给我的程序,让用户在我的自定义颜色选择器中创建/选择颜色然后最后将该颜色发送到Windows颜色选择器并以编程方式按下确定按钮。

解决方案

以下是您原始问题的解决方案:

创建 CHOOSECOLOR结构 [ ^ ]



设置CC_RGBINIT标志并将rgbResult设置为想要的颜色。



这是来自的原始文本MSDN:

rgbResult

类型:COLORREF

如果设置了CC_RGBINIT标志,rgbResult指定对话框i时最初选择的颜色创造了。如果指定的颜色值不在可用颜色中,系统将选择最接近的纯色。如果rgbResult为零或未设置CC_RGBINIT,则最初选择的颜色为黑色。如果用户单击确定按钮,则rgbResult指定用户的颜色选择。要创建COLORREF颜色值,请使用RGB宏。







这是指向的链接

打开彩色对话框 [ ^ ]

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.

解决方案

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[^]


这篇关于如何设置从其他程序打开的颜色对话框的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆