说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB使用API获取颜色

HTML文档下载 WORD文档下载 PDF文档下载
VB使用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----编译运行,看,出来了吧.
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘