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
'// The SendMessage function sends the specified message to a window or windows.
'// The function calls the window procedure for the specified window and does not
'// return until the window procedure has processed the message.
'// The PostMessage function, in contrast, posts a message to a thread’s message
'// queue and returns immediately.
'//
'// PARAMETERS:
'//
'// -hwnd
'// Identifies the window whose window procedure will receive the message.
'// If this parameter is HWND_BROADCAST, the message is sent to all top-level
'// windows in the system, including disabled or invisible unowned windows,
'// overlapped windows, and pop-up windows; but the message is not sent to child windows.
'// -Msg
'// Specifies the message to be sent.
'// -wParam
'// Specifies additional message-specific information.
'// -lParam
'// Specifies additional message-specific information.
'//////////////////////////////////////////////////////////////////////////
'// The IsWindow function determines whether the specified window handle
'// is Valid.
Private Declare Function IsWindow _
Lib "user32" ( _
ByVal hwnd As Long) _
As Long
'// PARAMETERS:
'// -hWnd
'// Specifies the window handle.
'//////////////////////////////////////////////////////////////////////////
'//
'// The InvalidateRect function specifies weather all or part of
'// a rectangle has been updated OR requires updating in a window.
'// The process of notifying a window that an update/refresh is needed
'// is done by this function.
'// hwnd: handle of Window to Invalidate
'// lpRect: Set to 0 to invalidate Entire Window
'// bErase: TRUE causes specified area to be erased before it is redrawn
Private Declare Function InvalidateRect _
Lib "user32" ( _
ByVal hwnd As Long, _
lpRect As Long, _
ByVal bErase As Long) _
As Long
Private Declare Function UpdateWindow _
Lib "user32" ( _
ByVal hwnd As Long) _
As Long
Private Declare Function GetDesktopWindow _
Lib "user32" () _
As Long
Public Function PrtScreenUpDate(bShowState As Boolean) As Boolean
Dim Wndhdl As Long
Const WM_SETREDRAW = &HB
Const WM_PAINT = &HF
Wndhdl = GetDesktopWindow
If IsWindow(Wndhdl) = False Then Exit Function
If bShowState Then
SendMessage Wndhdl, WM_SETREDRAW, 1, 0
InvalidateRect Wndhdl, 0, True
UpdateWindow Wndhdl
Else
SendMessage Wndhdl, WM_SETREDRAW, 0, 0
End If
End Function
'Call it like this.....
'-----------------------------
Sub PrintTestDisableDialog()
PrtScreenUpDate False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
PrtScreenUpDate True
End Sub
'-----------------------------