PDA

Vollständige Version anzeigen : Aktualisierung für eine Userform ausschalten


jinx
29.06.2001, 05:09
<font size="2" face="Century Gothic">Moin @ all,

auf einer Userform wirkt sich leider der Befehl <i>Application.ScreenUpdaring = False</i> nicht auf das Ausschalten der Bildschirmaktualisierung aus: das Bildschirmflimmern ist wahrzunehmen, und die Dauer der Ausführung verlängert sich durch die Aktualisierung.

Zum Ausschalten dieses Flimmern kann man sich API bedienen, wie im folgenden Beispiel anhand einer UserForm mit einer Listbox (lstDarstellung] und drei Schaltflächen (cmdOhneAPI, cmdMitAPI und cmdCancel) dargestellt wird. Folgender Code gehört in das Klassenmodul <b>CFreezeForm</b>:

<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="REM">'******************************************************************************* ********</span>
<span class="REM">'PUT FOLLOWING CODE IN A CLASS MODULE CFreezeForm</span>
<span class="REM">'******************************************************************************* ********</span>
<span class="TOKEN">Option</span> <span class="TOKEN">Explicit</span>
&nbsp;
<span class="REM">'Find a window</span>
<span class="TOKEN">Private</span> <span class="TOKEN">Declare</span> <span class="TOKEN">Function</span> FindWindow <span class="TOKEN">Lib</span> &quot;user32&quot; _
<span class="TOKEN">Alias</span> &quot;FindWindowA&quot; ( _
<span class="TOKEN">ByVal</span> lpClassName <span class="TOKEN">As</span> String, _
<span class="TOKEN">ByVal</span> lpWindowName <span class="TOKEN">As</span> <span class="TOKEN">String</span>) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
<span class="REM">'Freeze the window to prevent continuous redraws</span>
<span class="TOKEN">Private</span> <span class="TOKEN">Declare</span> <span class="TOKEN">Function</span> LockWindowUpdate <span class="TOKEN">Lib</span> &quot;user32&quot; ( _
<span class="TOKEN">ByVal</span> hwndLock <span class="TOKEN">As</span> <span class="TOKEN">Long</span>) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
<span class="TOKEN">Public Sub</span> Freeze(oForm <span class="TOKEN">As</span> UserForm)
<span class="TOKEN">Dim</span> hWnd <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
<span class="REM"> 'Get a handle to the userform window,</span>
<span class="REM"> 'using the class name appropriate for the XL version</span>
<span class="TOKEN">If</span> Val(Application.Version) &gt;= 9 <span class="TOKEN">Then</span>
hWnd = FindWindow(&quot;ThunderDFrame&quot;, oForm.Caption)
<span class="TOKEN">Else</span>
hWnd = FindWindow(&quot;ThunderXFrame&quot;, oForm.Caption)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
<span class="REM"> 'If we got a handle, freeze the window</span>
<span class="TOKEN">If</span> hWnd &gt; 0 <span class="TOKEN">Then</span> LockWindowUpdate hWnd
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span><hr>&nbsp;
<span class="REM">'Allow the calling routine to unfreeze the userform</span>
<span class="TOKEN">Public Sub</span> UnFreeze()
LockWindowUpdate 0
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span><hr>&nbsp;
<span class="REM">'If they forget to unfreeze the form, do it at the end</span>
<span class="REM">'of the calling routine (when we go out of scope)</span>
<span class="TOKEN">Private Sub</span> Class_Terminate()
UnFreeze
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span></pre></div>

Hinter der Userform liegt für die Schaltflächen der folgende Code:

<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Option</span> <span class="TOKEN">Explicit</span>
&nbsp;
<span class="TOKEN">Private Sub</span> cmdCancel_Click()
Unload Me
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span><hr>&nbsp;
<span class="TOKEN">Private Sub</span> cmdOhneAPI_Click()
<span class="REM">' aus: John Green / Stephen Bullen / Felipe Martins: Excel 2000 VBA Programmer´s Reference</span>
<span class="REM">' Wrox Press Ltd., Birmingham, 1999, 3. Reprint Novemder 2000</span>
<span class="REM">' Kapitel 18: Programming with Windows API, Seite 337ff</span>
<span class="TOKEN">Dim</span> i <span class="TOKEN">As</span> <span class="TOKEN">Integer</span>
&nbsp;
lstDarstellung.Clear
<span class="TOKEN">For</span> i = 1 <span class="TOKEN">To</span> 1000
lstDarstellung.AddItem &quot;Item &quot; &amp; i
DoEvents
<span class="TOKEN">Next</span> i
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span><hr>&nbsp;
<span class="TOKEN">Private Sub</span> cmdMitAPI_Click()
<span class="TOKEN">Dim</span> obFF <span class="TOKEN">As</span> <span class="TOKEN">New</span> CFreezeForm
<span class="TOKEN">Dim</span> i <span class="TOKEN">As</span> <span class="TOKEN">Integer</span>
&nbsp;
lstDarstellung.Clear
DoEvents
&nbsp;
<span class="REM">' Freeze the userform</span>
obFF.Freeze Me
&nbsp;
<span class="TOKEN">For</span> i = 1 <span class="TOKEN">To</span> 1000
lstDarstellung.AddItem &quot;Item &quot; &amp; i
DoEvents
<span class="TOKEN">Next</span> i
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span></pre></div>

Aufgerufen wird die Userform über eine Schaltfläche aus der Symbolleiste Formular mit folgendem Makro:

<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Option</span> <span class="TOKEN">Explicit</span>
&nbsp;
<span class="TOKEN">Sub</span> aufruf()
UserForm1.Show
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span></pre></div>
Code eingefügt mit dem MOF Code Converter (http://www.ms-office-forum.net/forum/codeconverter.php)</font>