Office中国论坛/Access中国论坛

标题: 如何用API调用颜色选择对话框?[求助] [打印本页]

作者: Trynew    时间: 2002-11-25 06:54
标题: 如何用API调用颜色选择对话框?[求助]
如何用API调用颜色选择对话框?
作者: zhengjialon    时间: 2002-11-25 20:35
在ACCESS2000的开发版里带的示例文件里有。
作者: cg1    时间: 2002-11-25 21:39
奥?能否贴上来?
作者: Trynew    时间: 2002-11-26 01:24
郑板主也不放上来,只好自己到MVPS网站照了一个:
If you want this function to simply return the value of the Color the user selected from the Dialog, then  just change the function declaration in modColorPicker to something like:

Public Function DialogColor(ctl As Control) As Long
' Remember to add the line of code at the
' end of the Function
' DialogColor = CS.rgbResult

Then call it from your Form with code like:

'***Code Start ***
Private Sub CmdChooseBackColor_Click()
    ' Pass the TextBox Control to the function
    Me.textCtl.BackColor = DialogColor(Me.textCtl)
End Sub
'***Code End ***
' ******** Code Start ********
'This code was originally written by Terry Kreft,
'and modified by Stephen Lebans
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
' Contact Stephen@lebans.com
'
Private Type COLORSTRUC
  lStructSize As Long
  hwnd 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 Const CC_SOLIDCOLOR = &H80

Private Declare Function ChooseColor _
    Lib "comdlg32.dll" Alias "ChooseColorA" _
    (pChoosecolor As COLORSTRUC) As Long

Public Function aDialogColor(prop As Property) As Boolean
  Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long

  CS.lStructSize = Len(CS)
  CS.hwnd = hWndAccessApp
  CS.Flags = CC_SOLIDCOLOR
  CS.lpCustColors = String$(16 * 4, 0)
  x = ChooseColor(CS)
  If x = 0 Then
    ' ERROR - use Default White
    prop = RGB(255, 255, 255) ' White
    aDialogColor = False
    Exit Function
  Else
    ' Normal processing
     prop = CS.rgbResult
  End If
  aDialogColor = True
End Function
' ********* Code End ***********

作者: zhengjialon    时间: 2002-11-26 01:28
标题: 回复
呵呵,中午不方便传,刚要传,你已找到,其实这个已经有人传过了,我暂时找不到地址。
文件下载
作者: Trynew    时间: 2002-11-26 01:40
谢谢,你这个我也下了,应该是个好例子,不过挺大的(500K),呵呵.
作者: zhengjialon    时间: 2002-11-26 01:48
2000开发版里的很全面的例子,如果有时间全都能了解,会发现有很多东西有用,一二年前我就有了(公司里买了一套开发版),真正看起来才近一年的事,不过才看了一点点。




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3