View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Alain CROS Alain CROS is offline
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


.