VB and VBA Users Source Code: Locking/disabling dialog and screen updating
[
Home
|
Contents
|
Search
|
Reply
|
Previous
| Next ]
VB/VBA Source Code
Locking/disabling dialog and screen updating
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, September 06, 2000
Hits:
1538
Category:
Windows API
Article:
This function is a more powerful version of the LockWindow routine. Please read the notes before using this routine. 'Example usuage Private Sub CommandButton1_Click() ScreenUpdate True For i = 1 To 10000 DoEvents Next ScreenUpdate False End Sub '---------Main Routine------------- Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal lErase As Long) As Long Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type 'Purpose : Completely Locks window updating at the desktop 'Inputs : bLockUpdating If True Locks desktop and all GUI 'Outputs : N/A 'Author : Andrewb 'Date : 17/08/2000 'Notes : This routine locks all GUI updating and MUST be unlocked through code, ' as all GUI will stop working while this is on. Use this cautiously! 'Revisions : Sub ScreenUpdate(bLockUpdating As Boolean) Dim lHwnd As Long, tRegion As RECT Const WM_SETREDRAW = &HB lHwnd = GetDesktopWindow If bLockUpdating Then 'Lock screen updating at desktop level SendMessage lHwnd, WM_SETREDRAW, 0, ByVal 0& Else 'Unlock screen updating SendMessage lHwnd, WM_SETREDRAW, 1, ByVal 0& 'Force Repaint GetClientRect lHwnd, tRegion InvalidateRect lHwnd, tRegion, 1 End If End Sub 'Purpose : Locks window updating for the specified dialog 'Inputs : lHwnd The handle to the dialog ' bLockUpdating If True disables dialog repainting/updating, else enables updating. 'Outputs : N/A 'Author : Andrew Baker 'Date : 17/08/2000 'Notes : 'Revisions : Sub DialogLockUpdating(lHwnd As Long, bLockUpdating As Boolean) Dim tRegion As RECT Const WM_SETREDRAW = &HB If bLockUpdating Then 'Lock screen updating at desktop level SendMessage lHwnd, WM_SETREDRAW, 0, ByVal 0& Else 'Unlock screen updating SendMessage lHwnd, WM_SETREDRAW, 1, ByVal 0& 'Force Repaint GetClientRect lHwnd, tRegion InvalidateRect lHwnd, tRegion, 1 End If End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder