|
-
Sep 30th, 2001, 12:15 PM
#1
Thread Starter
Lively Member
API Colour Dialog
Anyway to use the Colour Dialog Selector with out a control?
-
Sep 30th, 2001, 12:21 PM
#2
PowerPoster
Yes
VB Code:
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 Declare Function CHOOSECOLOR Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
Private Function ShowColor() As Long
Dim cc As CHOOSECOLOR
Dim Custcolor(16) As Long
Dim lReturn As Long
'set the structure size
cc.lStructSize = Len(cc)
'Set the owner
cc.hwndOwner = Me.hWnd
'set the application's instance
cc.hInstance = App.hInstance
'set the custom colors (converted to Unicode)
cc.lpCustColors = StrConv(CustomColors, vbUnicode)
'no extra flags
cc.flags = 0
'Show the 'Select Color'-dialog
If CHOOSECOLOR(cc) <> 0 Then
ShowColor = cc.rgbResult
CustomColors = StrConv(cc.lpCustColors, vbFromUnicode)
Else
ShowColor = -1
End If
End Function
Private Sub Command1_Click()
Dim NewColor As Long
NewColor = ShowColor
If NewColor <> -1 Then
Me.BackColor = NewColor
Else
MsgBox "You chose cancel"
End If
End Sub
-
Nov 9th, 2005, 12:18 AM
#3
Addicted Member
Re: API Colour Dialog
This code generating me an error. Can anybody help?
-
Nov 9th, 2005, 09:49 AM
#4
Re: API Colour Dialog
What error is it generating and on what line?
-
Nov 9th, 2005, 11:29 AM
#5
Re: API Colour Dialog
He forgot to include something. Add the following lines to the ShowColor Function
VB Code:
Dim CustomColors() As Byte
ReDim CustomColors(0 To 16 * 4 - 1) As Byte
-
Nov 10th, 2005, 01:30 AM
#6
Addicted Member
Re: API Colour Dialog
 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
-
Nov 10th, 2005, 01:39 AM
#7
Re: API Colour Dialog
Make sure all the code is in the form and not a module.
-
Nov 10th, 2005, 02:08 AM
#8
Addicted Member
Re: API Colour Dialog
 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.
-
Nov 10th, 2005, 02:22 AM
#9
Re: API Colour Dialog
If your form is called "Form1" then try Form1.hWnd
-
Nov 10th, 2005, 02:41 AM
#10
Addicted Member
Re: API Colour Dialog
 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
-
Nov 10th, 2005, 05:22 AM
#11
Addicted Member
Re: API Colour Dialog
 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.
-
Nov 10th, 2005, 08:50 AM
#12
Re: API Colour Dialog
 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?
-
Nov 10th, 2005, 08:59 AM
#13
Addicted Member
Re: API Colour Dialog
 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.
-
Nov 10th, 2005, 10:23 AM
#14
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.
-
Nov 14th, 2005, 01:05 AM
#15
Addicted Member
Re: API Colour Dialog
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|