PDA

Vollständige Version anzeigen : Wie rufe ich den Farbauswahldialog auf?


Stefan Kulpa
27.01.2003, 19:59
Um den Farbauswahldialog aufrufen zu können, muss man sich des Win32-API bedienen.

<div><link href="http://www.ms-office-forum.de/ubb/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Type</span> CHOOSECOLOR
lStructSize <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
hwndOwner <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
hInstance <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
rgbResult <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpCustColors <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
flags <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lCustData <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpfnHook <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpTemplateName <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">End</span> <span class="TOKEN">Type</span>
&nbsp;
<span class="TOKEN">Declare</span> <span class="TOKEN">Function</span> GetActiveWindow <span class="TOKEN">Lib</span> &quot;user32.dll&quot; () <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
<span class="TOKEN">Declare</span> <span class="TOKEN">Function</span> ChooseColor_API <span class="TOKEN">Lib</span> &quot;comdlg32.dll&quot; <span class="TOKEN">Alias</span> _
&quot;ChooseColorA&quot; _
(lpChoosecolor <span class="TOKEN">As</span> CHOOSECOLOR) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
<span class="TOKEN">Function</span> ColorSelected(<span class="TOKEN">Optional</span> lCurrentColor <span class="TOKEN">As</span> <span class="TOKEN">Long</span> = -1) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
<span class="REM">'// ----------------------------------------------------------------------------</span>
<span class="REM">'// Funktion: |Aufruf des Farbauswahldialoges.</span>
<span class="REM">'// ----------------------------------------------------------------------------</span>
<span class="REM">'// Voraussetzungen: |-</span>
<span class="REM">'// ----------------------------------------------------------------------------</span>
<span class="REM">'// Parameter: |optional lCurrentColor als aktuelle Farbe zur</span>
<span class="REM">'// |Voreinstellung im Auswahldialog</span>
<span class="REM">'// ----------------------------------------------------------------------------</span>
<span class="REM">'// R&uuml;ckgabe: |Ausgew&auml;hlte Fabe als Long-Wert</span>
<span class="REM">'// ----------------------------------------------------------------------------</span>
<span class="TOKEN">Const</span> CC_SOLIDCOLOR <span class="TOKEN">As</span> <span class="TOKEN">Long</span> = &amp;H80&amp;
<span class="TOKEN">Const</span> CC_ANYCOLOR <span class="TOKEN">As</span> <span class="TOKEN">Long</span> = &amp;H100&amp;
<span class="TOKEN">Const</span> CC_RGBINIT <span class="TOKEN">As</span> <span class="TOKEN">Long</span> = &amp;H1&amp;
&nbsp;
<span class="TOKEN">Dim</span> uChooseColor <span class="TOKEN">As</span> CHOOSECOLOR
<span class="TOKEN">Dim</span> alColorRef(15) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
<span class="TOKEN">Dim</span> hWnd <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
hWnd = GetActiveWindow()
<span class="TOKEN">With</span> uChooseColor
.lStructSize = Len(uChooseColor)
.hwndOwner = hWnd
.lpCustColors = VarPtr(alColorRef(0))
.flags = CC_SOLIDCOLOR <span class="TOKEN">Or</span> CC_ANYCOLOR <span class="TOKEN">Or</span> CC_RGBINIT
<span class="TOKEN">End</span> <span class="TOKEN">With</span>
<span class="TOKEN">If</span> lCurrentColor &gt;= 0 <span class="TOKEN">Then</span>
uChooseColor.rgbResult = lCurrentColor
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
<span class="TOKEN">If</span> ChooseColor_API(uChooseColor) <span class="TOKEN">Then</span>
ColorSelected = uChooseColor.rgbResult
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
<span class="TOKEN">End</span> <span class="TOKEN">Function</span></pre></div>
Code eingefügt mit dem MOF Code Converter (http://www.ms-office-forum.net/forum/codeconverter.php)

Bei dieser Funktion besteht die Möglichkeit, beim Aufruf einen Farbcode zu übergeben, um den Dialog mit dieser Farbe als Voreinstellung aufzurufen.