Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Getting hWnd for API call or Color choosing dialog

Hi All


I am using an API function and have to pass the Excel window handle. I have,
in vain, tried to figure this out. How do you get the window handle. I tried
xlGetHwnd which seemed to work but now it doesn't, which is really strange?

The API function is ChooseColor. This is so I can display a dialog for
choosing a color. If anybody knows another way of displaying a colour
choosing dialog this would also be good.

Jeff


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Getting hWnd for API call or Color choosing dialog

Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Dim hWnd As Long
hWnd = FindWindow("XLMAIN", Application.Caption)

However, since Excel can only handle the 56 colors that are in the palette
associated with each workbook, I'm not sure how useful the ChooseColor
function will be.

--

Vasant

"Jeff" wrote in message
...
Hi All


I am using an API function and have to pass the Excel window handle. I

have,
in vain, tried to figure this out. How do you get the window handle. I

tried
xlGetHwnd which seemed to work but now it doesn't, which is really

strange?

The API function is ChooseColor. This is so I can display a dialog for
choosing a color. If anybody knows another way of displaying a colour
choosing dialog this would also be good.

Jeff




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Getting hWnd for API call or Color choosing dialog

Hi Vasant

Is there a better way of doing this? I can't find any other way, short of
building a custom for, to display a suitable dialog.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Dim hWnd As Long
hWnd = FindWindow("XLMAIN", Application.Caption)

However, since Excel can only handle the 56 colors that are in the palette
associated with each workbook, I'm not sure how useful the ChooseColor
function will be.

--

Vasant

"Jeff" wrote in message
...
Hi All


I am using an API function and have to pass the Excel window handle. I

have,
in vain, tried to figure this out. How do you get the window handle. I

tried
xlGetHwnd which seemed to work but now it doesn't, which is really

strange?

The API function is ChooseColor. This is so I can display a dialog for
choosing a color. If anybody knows another way of displaying a colour
choosing dialog this would also be good.

Jeff






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Getting hWnd for API call or Color choosing dialog

Hi

Add a commandbutton on a worksheet

Private Sub CommandButton1_Click()
Dim cnt&, NewColor&
If Not Init Then
' Intialise le tableau les couleurs personnalisées
avec du blanc
For cnt = 0& To 15&
dwCustClrs(cnt) = RGB(255&, 255&, 255&)
Next
CommandButton1.BackColor = RGB(95&, 191&, 240&)
CommandButton1.Caption = "Cliquez-moi !"
Init = True
End If
NewColor = ChooseColorDialog(CommandButton1.BackColor)
If NewColor < -1 Then
CommandButton1.BackColor = NewColor
End If
End Sub

In a module

' Déclaration des API
Public Declare Function GetActiveWindow Lib "user32.dll"
() As Long
Public Declare Function ChooseColorDlg Lib "comdlg32.dll"
Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

' Constantes utilisées par ChooseColor
Public Const CC_RGBINIT = &H1&
Public Const CC_FULLOPEN = &H2&
Public Const CC_PREVENTFULLOPEN = &H4&
Public Const CC_SHOWHELP = &H8&
Public Const CC_ENABLEHOOK = &H10&
Public Const CC_ENABLETEMPLATE = &H20&
Public Const CC_ENABLETEMPLATEHANDLE = &H40&
Public Const CC_SOLIDCOLOR = &H80&
Public Const CC_ANYCOLOR = &H100&

Public Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public dwCustClrs(0 To 15) As Long ' Tableau statique
contenant les couleurs personnalisées
Public Init As Boolean
'----------------------------------------------------------
-----------------------------
' Function : ChooseColorDialog
' DateTime : 29/08/2002 21:44
' Auteur : Pierre Alexis
' Type-retour : Long (représentant une couleur)
' But : Cette fonction affiche la boîte de
dialogue "ChooseColor" et retourne
' une couleur.
'----------------------------------------------------------
-----------------------------
Public Function ChooseColorDialog(DefaultColor As Long) As
Long
Dim lpChoosecolor As CHOOSECOLOR
With lpChoosecolor
.lStructSize = Len(lpChoosecolor)
.hwndOwner = GetActiveWindow
.rgbResult = DefaultColor
.lpCustColors = VarPtr(dwCustClrs(0))
.flags = CC_ANYCOLOR Or CC_RGBINIT Or CC_FULLOPEN
End With
If ChooseColorDlg(lpChoosecolor) Then
ChooseColorDialog = lpChoosecolor.rgbResult
Else
ChooseColorDialog = -1
End If
End Function

Alain CROS


-----Original Message-----
Hi All


I am using an API function and have to pass the Excel

window handle. I have,
in vain, tried to figure this out. How do you get the

window handle. I tried
xlGetHwnd which seemed to work but now it doesn't, which

is really strange?

The API function is ChooseColor. This is so I can display

a dialog for
choosing a color. If anybody knows another way of

displaying a colour
choosing dialog this would also be good.

Jeff


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Getting hWnd for API call or Color choosing dialog

Jeff, there may be a better way depending on what you are trying to
accomplish with the color picker. Can you provide a little more detail on
what you want to use the color for?

Also, John Walkenbach's Color Picker may do the trick for you:

http://j-walk.com/ss/excel/tips/tip49.htm

--

Vasant

"Jeff" wrote in message
...
Hi Vasant

Is there a better way of doing this? I can't find any other way, short of
building a custom for, to display a suitable dialog.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Dim hWnd As Long
hWnd = FindWindow("XLMAIN", Application.Caption)

However, since Excel can only handle the 56 colors that are in the

palette
associated with each workbook, I'm not sure how useful the ChooseColor
function will be.

--

Vasant

"Jeff" wrote in message
...
Hi All


I am using an API function and have to pass the Excel window handle. I

have,
in vain, tried to figure this out. How do you get the window handle. I

tried
xlGetHwnd which seemed to work but now it doesn't, which is really

strange?

The API function is ChooseColor. This is so I can display a dialog for
choosing a color. If anybody knows another way of displaying a colour
choosing dialog this would also be good.

Jeff










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Getting hWnd for API call or Color choosing dialog

Basically, just provide the user with the ability to select a colour. I am
building a dialog for modifying cell properties and part of that is the
ability to choose a font and back colour. There's quite a bit more to it
than that, but that is the basic need for a colour chooser.

I would love to be able to access built-in dialogs for what I am doing, such
as the Format Cells dialog, that then returns the users selections, so I can
then apply them as I want, but can't find a way of doing that.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Jeff, there may be a better way depending on what you are trying to
accomplish with the color picker. Can you provide a little more detail on
what you want to use the color for?

Also, John Walkenbach's Color Picker may do the trick for you:

http://j-walk.com/ss/excel/tips/tip49.htm

--

Vasant

"Jeff" wrote in message
...
Hi Vasant

Is there a better way of doing this? I can't find any other way, short

of
building a custom for, to display a suitable dialog.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Dim hWnd As Long
hWnd = FindWindow("XLMAIN", Application.Caption)

However, since Excel can only handle the 56 colors that are in the

palette
associated with each workbook, I'm not sure how useful the ChooseColor
function will be.

--

Vasant

"Jeff" wrote in message
...
Hi All


I am using an API function and have to pass the Excel window handle.

I
have,
in vain, tried to figure this out. How do you get the window handle.

I
tried
xlGetHwnd which seemed to work but now it doesn't, which is really
strange?

The API function is ChooseColor. This is so I can display a dialog

for
choosing a color. If anybody knows another way of displaying a

colour
choosing dialog this would also be good.

Jeff










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Getting hWnd for API call or Color choosing dialog

Hi Alain

That is cool. It all works great.

Vasant did raise the question of how useful it is because Excel only deals
with 56 colours. The funny thing is, you can apply other colours to a button
face as in this example, but not to the fill colour for a cell.

Is there another dialog that just has the restricted pallet?

Jeff

"Alain CROS" <Personne@ICI wrote in message
...
Hi

Add a commandbutton on a worksheet

Private Sub CommandButton1_Click()
Dim cnt&, NewColor&
If Not Init Then
' Intialise le tableau les couleurs personnalisées
avec du blanc
For cnt = 0& To 15&
dwCustClrs(cnt) = RGB(255&, 255&, 255&)
Next
CommandButton1.BackColor = RGB(95&, 191&, 240&)
CommandButton1.Caption = "Cliquez-moi !"
Init = True
End If
NewColor = ChooseColorDialog(CommandButton1.BackColor)
If NewColor < -1 Then
CommandButton1.BackColor = NewColor
End If
End Sub

In a module

' Déclaration des API
Public Declare Function GetActiveWindow Lib "user32.dll"
() As Long
Public Declare Function ChooseColorDlg Lib "comdlg32.dll"
Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

' Constantes utilisées par ChooseColor
Public Const CC_RGBINIT = &H1&
Public Const CC_FULLOPEN = &H2&
Public Const CC_PREVENTFULLOPEN = &H4&
Public Const CC_SHOWHELP = &H8&
Public Const CC_ENABLEHOOK = &H10&
Public Const CC_ENABLETEMPLATE = &H20&
Public Const CC_ENABLETEMPLATEHANDLE = &H40&
Public Const CC_SOLIDCOLOR = &H80&
Public Const CC_ANYCOLOR = &H100&

Public Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public dwCustClrs(0 To 15) As Long ' Tableau statique
contenant les couleurs personnalisées
Public Init As Boolean
'----------------------------------------------------------
-----------------------------
' Function : ChooseColorDialog
' DateTime : 29/08/2002 21:44
' Auteur : Pierre Alexis
' Type-retour : Long (représentant une couleur)
' But : Cette fonction affiche la boîte de
dialogue "ChooseColor" et retourne
' une couleur.
'----------------------------------------------------------
-----------------------------
Public Function ChooseColorDialog(DefaultColor As Long) As
Long
Dim lpChoosecolor As CHOOSECOLOR
With lpChoosecolor
.lStructSize = Len(lpChoosecolor)
.hwndOwner = GetActiveWindow
.rgbResult = DefaultColor
.lpCustColors = VarPtr(dwCustClrs(0))
.flags = CC_ANYCOLOR Or CC_RGBINIT Or CC_FULLOPEN
End With
If ChooseColorDlg(lpChoosecolor) Then
ChooseColorDialog = lpChoosecolor.rgbResult
Else
ChooseColorDialog = -1
End If
End Function

Alain CROS


-----Original Message-----
Hi All


I am using an API function and have to pass the Excel

window handle. I have,
in vain, tried to figure this out. How do you get the

window handle. I tried
xlGetHwnd which seemed to work but now it doesn't, which

is really strange?

The API function is ChooseColor. This is so I can display

a dialog for
choosing a color. If anybody knows another way of

displaying a colour
choosing dialog this would also be good.

Jeff


.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Getting hWnd for API call or Color choosing dialog

Hi Jeff,

This uses the palette. It's a simple function to return a chosen colour.

Function ReturnColorindex(Optional Text As Boolean = False) As Long
Dim rngCurr As Range
Set rngCurr = Selection
Application.ScreenUpdating = False
Range("IV1").Select
Application.Dialogs(xlDialogPatterns).Show
ReturnColorindex = ActiveCell.interior.ColorIndex
If ReturnColorindex = xlColorIndexAutomatic And Not Text Then
ReturnColorindex = xlColorIndexNone
End If
ActiveCell.interior.ColorIndex = xlColorIndexAutomatic
rngCurr.Select
Set rngCurr = ActiveSheet.UsedRange
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jeff" wrote in message
...
Hi Alain

That is cool. It all works great.

Vasant did raise the question of how useful it is because Excel only deals
with 56 colours. The funny thing is, you can apply other colours to a

button
face as in this example, but not to the fill colour for a cell.

Is there another dialog that just has the restricted pallet?

Jeff

"Alain CROS" <Personne@ICI wrote in message
...
Hi

Add a commandbutton on a worksheet

Private Sub CommandButton1_Click()
Dim cnt&, NewColor&
If Not Init Then
' Intialise le tableau les couleurs personnalisées
avec du blanc
For cnt = 0& To 15&
dwCustClrs(cnt) = RGB(255&, 255&, 255&)
Next
CommandButton1.BackColor = RGB(95&, 191&, 240&)
CommandButton1.Caption = "Cliquez-moi !"
Init = True
End If
NewColor = ChooseColorDialog(CommandButton1.BackColor)
If NewColor < -1 Then
CommandButton1.BackColor = NewColor
End If
End Sub

In a module

' Déclaration des API
Public Declare Function GetActiveWindow Lib "user32.dll"
() As Long
Public Declare Function ChooseColorDlg Lib "comdlg32.dll"
Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

' Constantes utilisées par ChooseColor
Public Const CC_RGBINIT = &H1&
Public Const CC_FULLOPEN = &H2&
Public Const CC_PREVENTFULLOPEN = &H4&
Public Const CC_SHOWHELP = &H8&
Public Const CC_ENABLEHOOK = &H10&
Public Const CC_ENABLETEMPLATE = &H20&
Public Const CC_ENABLETEMPLATEHANDLE = &H40&
Public Const CC_SOLIDCOLOR = &H80&
Public Const CC_ANYCOLOR = &H100&

Public Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public dwCustClrs(0 To 15) As Long ' Tableau statique
contenant les couleurs personnalisées
Public Init As Boolean
'----------------------------------------------------------
-----------------------------
' Function : ChooseColorDialog
' DateTime : 29/08/2002 21:44
' Auteur : Pierre Alexis
' Type-retour : Long (représentant une couleur)
' But : Cette fonction affiche la boîte de
dialogue "ChooseColor" et retourne
' une couleur.
'----------------------------------------------------------
-----------------------------
Public Function ChooseColorDialog(DefaultColor As Long) As
Long
Dim lpChoosecolor As CHOOSECOLOR
With lpChoosecolor
.lStructSize = Len(lpChoosecolor)
.hwndOwner = GetActiveWindow
.rgbResult = DefaultColor
.lpCustColors = VarPtr(dwCustClrs(0))
.flags = CC_ANYCOLOR Or CC_RGBINIT Or CC_FULLOPEN
End With
If ChooseColorDlg(lpChoosecolor) Then
ChooseColorDialog = lpChoosecolor.rgbResult
Else
ChooseColorDialog = -1
End If
End Function

Alain CROS


-----Original Message-----
Hi All


I am using an API function and have to pass the Excel

window handle. I have,
in vain, tried to figure this out. How do you get the

window handle. I tried
xlGetHwnd which seemed to work but now it doesn't, which

is really strange?

The API function is ChooseColor. This is so I can display

a dialog for
choosing a color. If anybody knows another way of

displaying a colour
choosing dialog this would also be good.

Jeff


.





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Getting hWnd for API call or Color choosing dialog

Jeff,

That should be ... return a ColorIndex.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob Phillips" wrote in message
...
Hi Jeff,

This uses the palette. It's a simple function to return a chosen colour.

Function ReturnColorindex(Optional Text As Boolean = False) As Long
Dim rngCurr As Range
Set rngCurr = Selection
Application.ScreenUpdating = False
Range("IV1").Select
Application.Dialogs(xlDialogPatterns).Show
ReturnColorindex = ActiveCell.interior.ColorIndex
If ReturnColorindex = xlColorIndexAutomatic And Not Text Then
ReturnColorindex = xlColorIndexNone
End If
ActiveCell.interior.ColorIndex = xlColorIndexAutomatic
rngCurr.Select
Set rngCurr = ActiveSheet.UsedRange
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jeff" wrote in message
...
Hi Alain

That is cool. It all works great.

Vasant did raise the question of how useful it is because Excel only

deals
with 56 colours. The funny thing is, you can apply other colours to a

button
face as in this example, but not to the fill colour for a cell.

Is there another dialog that just has the restricted pallet?

Jeff

"Alain CROS" <Personne@ICI wrote in message
...
Hi

Add a commandbutton on a worksheet

Private Sub CommandButton1_Click()
Dim cnt&, NewColor&
If Not Init Then
' Intialise le tableau les couleurs personnalisées
avec du blanc
For cnt = 0& To 15&
dwCustClrs(cnt) = RGB(255&, 255&, 255&)
Next
CommandButton1.BackColor = RGB(95&, 191&, 240&)
CommandButton1.Caption = "Cliquez-moi !"
Init = True
End If
NewColor = ChooseColorDialog(CommandButton1.BackColor)
If NewColor < -1 Then
CommandButton1.BackColor = NewColor
End If
End Sub

In a module

' Déclaration des API
Public Declare Function GetActiveWindow Lib "user32.dll"
() As Long
Public Declare Function ChooseColorDlg Lib "comdlg32.dll"
Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

' Constantes utilisées par ChooseColor
Public Const CC_RGBINIT = &H1&
Public Const CC_FULLOPEN = &H2&
Public Const CC_PREVENTFULLOPEN = &H4&
Public Const CC_SHOWHELP = &H8&
Public Const CC_ENABLEHOOK = &H10&
Public Const CC_ENABLETEMPLATE = &H20&
Public Const CC_ENABLETEMPLATEHANDLE = &H40&
Public Const CC_SOLIDCOLOR = &H80&
Public Const CC_ANYCOLOR = &H100&

Public Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public dwCustClrs(0 To 15) As Long ' Tableau statique
contenant les couleurs personnalisées
Public Init As Boolean
'----------------------------------------------------------
-----------------------------
' Function : ChooseColorDialog
' DateTime : 29/08/2002 21:44
' Auteur : Pierre Alexis
' Type-retour : Long (représentant une couleur)
' But : Cette fonction affiche la boîte de
dialogue "ChooseColor" et retourne
' une couleur.
'----------------------------------------------------------
-----------------------------
Public Function ChooseColorDialog(DefaultColor As Long) As
Long
Dim lpChoosecolor As CHOOSECOLOR
With lpChoosecolor
.lStructSize = Len(lpChoosecolor)
.hwndOwner = GetActiveWindow
.rgbResult = DefaultColor
.lpCustColors = VarPtr(dwCustClrs(0))
.flags = CC_ANYCOLOR Or CC_RGBINIT Or CC_FULLOPEN
End With
If ChooseColorDlg(lpChoosecolor) Then
ChooseColorDialog = lpChoosecolor.rgbResult
Else
ChooseColorDialog = -1
End If
End Function

Alain CROS


-----Original Message-----
Hi All


I am using an API function and have to pass the Excel

window handle. I have,
in vain, tried to figure this out. How do you get the

window handle. I tried
xlGetHwnd which seemed to work but now it doesn't, which

is really strange?

The API function is ChooseColor. This is so I can display

a dialog for
choosing a color. If anybody knows another way of

displaying a colour
choosing dialog this would also be good.

Jeff


.







  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Getting hWnd for API call or Color choosing dialog

Suggested is the following:

***** Step 1 *****
Create a Class module and paste the following code:

Public WithEvents ColorBtn As MSForms.Label
Private Sub ColorBtn_Click()
ColorBtn.SpecialEffect = fmSpecialEffectSunken
DoEvents
Sleep 100
ColorBtn.SpecialEffect = fmSpecialEffectFlat
ChosenColor = ColorBtn.BackColor
MsgBox "Your color choice was: " & ChosenColor
End Sub

***** Step 2 *****
Paste the following code to a standard module and run it
to create the UF. You only need to run it once. You can
delete the code after if you like. Correct for word wrap.

Sub MakeUF()
Dim UF As Object, NewFrame As Object, Ctrl As Object
Dim i As Integer, ii As Integer, iii As Integer
Dim Code As String, Line As Integer

Set UF = ThisWorkbook.VBProject.VBComponents.Add(3)
With UF
.Properties("Caption") = " Color selection"
.Properties("Height") = 112
.Properties("Width") = 110
End With
'***** Add LABELS for color selection *****
Set NewFrame = UF.Designer.Controls.Add("Forms.Frame.1")
With NewFrame
.Left = 3
.Top = 3
.Height = 87
.Width = 99
End With
iii = 0
For i = 0 To 6
For ii = 0 To 7
iii = iii + 1
Set Ctrl = NewFrame.Controls.Add("Forms.Label.1")
With Ctrl
.Left = ii * 12
.Top = i * 12
.Height = 12
.Width = 12
.BackColor = ActiveWorkbook.Colors(iii)
.Caption = ""
.ControlTipText = iii
.BorderStyle = 0
End With
Next
Next
With UF.CodeModule
Line = .CountOfLines
Code = "Dim ColorBtnGroup(1 To 56) As New Class1" &
vbCr & _
"Private Sub UserForm_Initialize()" & vbCr & _
"Dim i As Integer" & vbCr & _
"For i = 1 To 56" & vbCr & _
" Set ColorBtnGroup(i).ColorBtn = Controls(i)" &
vbCr & _
"Next" & vbCr & _
"End Sub"
.InsertLines Line, Code
End With
End Sub

***** Step 3 *****
Paste the following to a standard module. Correct word
wrap. Execute the macro UFShow to demo the color selector.
If the new UF is not named UserForm1 then correct the name.

Public Declare Sub Sleep Lib "kernel32.dll" (ByVal
dwMilliseconds As Long)
Public ChosenColor As Long

Sub UFShow()
UserForm1.Show
End Sub

Regards,
Greg





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Getting hWnd for API call or Color choosing dialog

Try

Application.Dialogs(xlDialogPatterns).Show

Worked for me Xl2000/2003



"Jeff" wrote in message ...
Basically, just provide the user with the ability to select a colour. I am
building a dialog for modifying cell properties and part of that is the
ability to choose a font and back colour. There's quite a bit more to it
than that, but that is the basic need for a colour chooser.

I would love to be able to access built-in dialogs for what I am doing, such
as the Format Cells dialog, that then returns the users selections, so I can
then apply them as I want, but can't find a way of doing that.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Jeff, there may be a better way depending on what you are trying to
accomplish with the color picker. Can you provide a little more detail on
what you want to use the color for?

Also, John Walkenbach's Color Picker may do the trick for you:

http://j-walk.com/ss/excel/tips/tip49.htm

--

Vasant

"Jeff" wrote in message
...
Hi Vasant

Is there a better way of doing this? I can't find any other way, short

of
building a custom for, to display a suitable dialog.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Dim hWnd As Long
hWnd = FindWindow("XLMAIN", Application.Caption)

However, since Excel can only handle the 56 colors that are in the

palette
associated with each workbook, I'm not sure how useful the ChooseColor
function will be.

--

Vasant

"Jeff" wrote in message
...
Hi All


I am using an API function and have to pass the Excel window handle.

I
have,
in vain, tried to figure this out. How do you get the window handle.

I
tried
xlGetHwnd which seemed to work but now it doesn't, which is really

strange?

The API function is ChooseColor. This is so I can display a dialog

for
choosing a color. If anybody knows another way of displaying a

colour
choosing dialog this would also be good.

Jeff








  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Getting hWnd for API call or Color choosing dialog

Just to add/emphasize that built in dialogs perform their designed actions.
They don't provide access to user selections.

--
Regards,
Tom Ogilvy

"Ivan F Moala" wrote in message
om...
Try

Application.Dialogs(xlDialogPatterns).Show

Worked for me Xl2000/2003



"Jeff" wrote in message

...
Basically, just provide the user with the ability to select a colour. I

am
building a dialog for modifying cell properties and part of that is the
ability to choose a font and back colour. There's quite a bit more to it
than that, but that is the basic need for a colour chooser.

I would love to be able to access built-in dialogs for what I am doing,

such
as the Format Cells dialog, that then returns the users selections, so I

can
then apply them as I want, but can't find a way of doing that.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Jeff, there may be a better way depending on what you are trying to
accomplish with the color picker. Can you provide a little more detail

on
what you want to use the color for?

Also, John Walkenbach's Color Picker may do the trick for you:

http://j-walk.com/ss/excel/tips/tip49.htm

--

Vasant

"Jeff" wrote in message
...
Hi Vasant

Is there a better way of doing this? I can't find any other way,

short
of
building a custom for, to display a suitable dialog.

Jeff

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Dim hWnd As Long
hWnd = FindWindow("XLMAIN", Application.Caption)

However, since Excel can only handle the 56 colors that are in the

palette
associated with each workbook, I'm not sure how useful the

ChooseColor
function will be.

--

Vasant

"Jeff" wrote in message
...
Hi All


I am using an API function and have to pass the Excel window

handle.
I
have,
in vain, tried to figure this out. How do you get the window

handle.
I
tried
xlGetHwnd which seemed to work but now it doesn't, which is

really
strange?

The API function is ChooseColor. This is so I can display a

dialog
for
choosing a color. If anybody knows another way of displaying a

colour
choosing dialog this would also be good.

Jeff










  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Getting hWnd for API call or Color choosing dialog

Correction to my post:

The line near the end of macro MakeUF should read:
.InsertLines Line + 1, Code
instead of:
.InsertLines Line, Code

Regards,
Greg


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Getting hWnd for API call or Color choosing dialog

Correction to my post:

The line ".InsertLines Line, Code" should be:
".InsertLines Line + 1, Code"

I posted the correction several hours ago and it has yet
to materialize.

Regards,
Greg


-----Original Message-----
Suggested is the following:

***** Step 1 *****
Create a Class module and paste the following code:

Public WithEvents ColorBtn As MSForms.Label
Private Sub ColorBtn_Click()
ColorBtn.SpecialEffect = fmSpecialEffectSunken
DoEvents
Sleep 100
ColorBtn.SpecialEffect = fmSpecialEffectFlat
ChosenColor = ColorBtn.BackColor
MsgBox "Your color choice was: " & ChosenColor
End Sub

***** Step 2 *****
Paste the following code to a standard module and run it
to create the UF. You only need to run it once. You can
delete the code after if you like. Correct for word wrap.

Sub MakeUF()
Dim UF As Object, NewFrame As Object, Ctrl As Object
Dim i As Integer, ii As Integer, iii As Integer
Dim Code As String, Line As Integer

Set UF = ThisWorkbook.VBProject.VBComponents.Add(3)
With UF
.Properties("Caption") = " Color selection"
.Properties("Height") = 112
.Properties("Width") = 110
End With
'***** Add LABELS for color selection *****
Set NewFrame = UF.Designer.Controls.Add("Forms.Frame.1")
With NewFrame
.Left = 3
.Top = 3
.Height = 87
.Width = 99
End With
iii = 0
For i = 0 To 6
For ii = 0 To 7
iii = iii + 1
Set Ctrl = NewFrame.Controls.Add("Forms.Label.1")
With Ctrl
.Left = ii * 12
.Top = i * 12
.Height = 12
.Width = 12
.BackColor = ActiveWorkbook.Colors(iii)
.Caption = ""
.ControlTipText = iii
.BorderStyle = 0
End With
Next
Next
With UF.CodeModule
Line = .CountOfLines
Code = "Dim ColorBtnGroup(1 To 56) As New Class1" &
vbCr & _
"Private Sub UserForm_Initialize()" & vbCr & _
"Dim i As Integer" & vbCr & _
"For i = 1 To 56" & vbCr & _
" Set ColorBtnGroup(i).ColorBtn = Controls(i)" &
vbCr & _
"Next" & vbCr & _
"End Sub"
.InsertLines Line, Code
End With
End Sub

***** Step 3 *****
Paste the following to a standard module. Correct word
wrap. Execute the macro UFShow to demo the color

selector.
If the new UF is not named UserForm1 then correct the

name.

Public Declare Sub Sleep Lib "kernel32.dll" (ByVal
dwMilliseconds As Long)
Public ChosenColor As Long

Sub UFShow()
UserForm1.Show
End Sub

Regards,
Greg



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofilter dialog boxes - can i call this up in the Mr BT Excel Worksheet Functions 3 January 15th 09 09:23 PM
Dialog For Choosing A File as a string Gjones Excel Programming 2 April 13th 04 07:11 PM
color function causes save dialog? Michael Purcell Excel Programming 2 February 18th 04 09:12 PM
hWnd of UserForm rsmith Excel Programming 3 February 10th 04 12:32 AM
how to get hwnd from application object? Erwin Kalvelagen Excel Programming 2 December 16th 03 07:12 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"