Results 1 to 15 of 15

Thread: API Colour Dialog

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    UK - Liverpool
    Posts
    113

    API Colour Dialog

    Anyway to use the Colour Dialog Selector with out a control?

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Yes
    VB Code:
    1. Private Type CHOOSECOLOR
    2.     lStructSize As Long
    3.     hwndOwner As Long
    4.     hInstance As Long
    5.     rgbResult As Long
    6.     lpCustColors As String
    7.     flags As Long
    8.     lCustData As Long
    9.     lpfnHook As Long
    10.     lpTemplateName As String
    11. End Type
    12. Private Declare Function CHOOSECOLOR Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
    13. Private Function ShowColor() As Long
    14.     Dim cc As CHOOSECOLOR
    15.     Dim Custcolor(16) As Long
    16.     Dim lReturn As Long
    17.  
    18.     'set the structure size
    19.     cc.lStructSize = Len(cc)
    20.     'Set the owner
    21.     cc.hwndOwner = Me.hWnd
    22.     'set the application's instance
    23.     cc.hInstance = App.hInstance
    24.     'set the custom colors (converted to Unicode)
    25.     cc.lpCustColors = StrConv(CustomColors, vbUnicode)
    26.     'no extra flags
    27.     cc.flags = 0
    28.  
    29.     'Show the 'Select Color'-dialog
    30.     If CHOOSECOLOR(cc) <> 0 Then
    31.         ShowColor = cc.rgbResult
    32.         CustomColors = StrConv(cc.lpCustColors, vbFromUnicode)
    33.     Else
    34.         ShowColor = -1
    35.     End If
    36. End Function
    37.  
    38. Private Sub Command1_Click()
    39.  
    40. Dim NewColor As Long
    41.    
    42. NewColor = ShowColor
    43.  
    44. If NewColor <> -1 Then
    45.     Me.BackColor = NewColor
    46. Else
    47.     MsgBox "You chose cancel"
    48. End If
    49.  
    50. End Sub

  3. #3
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    This code generating me an error. Can anybody help?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: API Colour Dialog

    What error is it generating and on what line?

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: API Colour Dialog

    He forgot to include something. Add the following lines to the ShowColor Function
    VB Code:
    1. Dim CustomColors() As Byte
    2.     ReDim CustomColors(0 To 16 * 4 - 1) As Byte

  6. #6
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    Quote Originally Posted by Hack
    What error is it generating and on what line?
    It writes me: "Invalid use of Me keyword". I am using visual basic editor 6.3. The "Me" is used in .Net?

    I also do not understand what should this macro do.

    Boris

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: API Colour Dialog

    Make sure all the code is in the form and not a module.

  8. #8
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    Quote Originally Posted by moeur
    Make sure all the code is in the form and not a module.
    I have created an userform and commandbutton. The code is inside this userform. Now writes me an error: "Method or data member not found" at the line:
    cc.hwndOwner = Me.hwnd

    I have tryed to write me. again, but VB is not offering me hwnd.

  9. #9
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: API Colour Dialog

    If your form is called "Form1" then try Form1.hWnd

  10. #10
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    Quote Originally Posted by moeur
    If your form is called "Form1" then try Form1.hWnd
    I have changed Me to Userform2, but it still do not offering me hwnd

  11. #11
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    Quote Originally Posted by moeur
    If your form is called "Form1" then try Form1.hWnd

    I have changed:
    cc.hwndOwner = Useform1.Hwnd

    to

    cc.hwndOwner = Application.Hwnd

    and

    cc.hInstance = App.hInstance

    to

    cc.hInstance = Application.hInstance

    Now it works. When I click commandbutton a color definition form is opened.
    My intention was to place the rainbow rectangle (I do not know the official name) inside my own userform.

    Can anybody help.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: API Colour Dialog

    Quote Originally Posted by bolcskei
    I have changed Me to Userform2, but it still do not offering me hwnd
    Are you attempting to do this in VB6 or VBA?

  13. #13
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    Quote Originally Posted by Hack
    Are you attempting to do this in VB6 or VBA?
    Please red my last quote. I would like to make an add-ins in Excel and I am using Visual Basic Editor, version 6.3.

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: API Colour Dialog

    When you say "Visual Basic Editor" it's a bit ambigious. The actual language you are using is VBA and it is not the same as VB6 the desktop production language. VBA has more limitations, one of which you have probably just found.

  15. #15
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: API Colour Dialog

    Quote Originally Posted by penagate
    When you say "Visual Basic Editor" it's a bit ambigious. The actual language you are using is VBA and it is not the same as VB6 the desktop production language. VBA has more limitations, one of which you have probably just found.
    I do not dispute with you. I am not very experienced in VB. I have started to use it approximately a year before.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width