- 中查找“使用API获取颜色”更多相关内容
- 中查找“使用API获取颜色”更多相关内容
- ·上一篇文章:如何用api检查任务栏中有多少种输入法
- ·下一篇文章:如何隐藏鼠标指针?
使用API获取颜色
除了使用CommonDialog的方法,还有一种使用API函数的方法进可以实现获取颜色。 参见本例:
>>步骤1----建立新工程,在窗体上放置一个CommandButton,一个PictureBox,一个TextBox;
>>步骤2----编写如下代码:
private Declare Function ChooseColor Lib "comdlg32.dll" Alias _
"ChooseColorA" (pChoosecolor As ChooseColor) As Long
private Type ChooseColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub Command1_Click()
Dim cc As ChooseColor
cc.lStructSize = Len(cc)
cc.hwndOwner = Me.hWnd
cc.hInstance = App.hInstance
cc.flags = 0
cc.lpCustColors = String$(16 * 4, 0)
if ChooseColor(cc) >= 1 Then
Picture1.BackColor = cc.rgbResult
Text1.Text = "颜色值:" & cc.rgbResult
Else
Text1.Text = "你取消了。"
End If
End Sub
>>步骤3----编译运行,看,出来了吧.