VBA, MS Access MS Access в примерах

Прорисовка формы - Отмена и Включение (API - SendMessage)

' -------------------------------------------------------------------------------------------------/
' Name:     modFormReDrawOffAndOn_API
' Kind:     Module
' Purpose:  Отключение перерисовки формы
' Author:   es
' Date:     03.04.2024
' -------------------------------------------------------------------------------------------------/
Option Compare Database
Option Explicit

#If VBA7 Then ' SendMessage API declaration
    Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
#Else
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
#End If

Private Const WM_SETREDRAW = &HB

Public Sub FormReDraw(frm As Form, blnReDrawON As Boolean)
' Процедура для предотвращения перерисовки или обновления окна указанной в аргументе формы.
' es - 03.04.2024 v003
' -------------------------------------------------------------------------------------------------/
' Пример эксплуотации:
'    FormReDraw Me, False ' Отключение перерисовки формы
'    ' ... код обновления формы  ...
'    FormReDraw Me, True  ' Включение перерисовки формы
' -------------------------------------------------------------------------------------------------/
On Error GoTo FormReDraw_Err
    Call SendMessage(frm.hwnd, WM_SETREDRAW, blnReDrawON, 0&)

FormReDraw_End:
    Exit Sub

FormReDraw_Err:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Sub :" & _
        "FormReDraw", vbCritical, "Error!"
    On Error Resume Next
    Call SendMessage(frm.hwnd, WM_SETREDRAW, True, 0&)
    Err.Clear
End Sub


Назад ToTop
L.E. 04.04.2024
Рейтинг@Mail.ru