Skip to content

Instantly share code, notes, and snippets.

@zamabuvaraeu
Created April 13, 2024 17:13
Show Gist options
  • Select an option

  • Save zamabuvaraeu/29a1ed4f30a8ffb03bbc4d3da733b754 to your computer and use it in GitHub Desktop.

Select an option

Save zamabuvaraeu/29a1ed4f30a8ffb03bbc4d3da733b754 to your computer and use it in GitHub Desktop.
Sleep без блокировки GUI
#include once "windows.bi"
Const MSGF_SLEEPMSG = &h5300
Private Function SleepMsg(ByVal dwTimeout As DWORD) As Boolean
Dim dwStart As DWORD = GetTickCount()
Dim dwFinish As DWORD = dwStart
Dim dwElapsed As DWORD = dwFinish - dwStart
Do
Dim dwTimes As DWORD = dwTimeout - dwElapsed
Dim dwStatus As DWORD = MsgWaitForMultipleObjectsEx( _
0, _
NULL, _
dwTimes, _
QS_ALLINPUT, _
MWMO_WAITALL Or MWMO_INPUTAVAILABLE _
)
If dwStatus = WAIT_OBJECT_0 Then
Dim m As MSG = Any
Dim resPeek As BOOL = PeekMessage(@m, NULL, 0, 0, PM_REMOVE)
Do While resPeek
If m.message = WM_QUIT Then
PostQuitMessage(m.wParam)
Return False
End If
Dim resCallFilter As BOOL = CallMsgFilter(@m, MSGF_SLEEPMSG)
If resCallFilter = 0 Then
TranslateMessage(@m)
DispatchMessage(@m)
End If
resPeek = PeekMessage(@m, NULL, 0, 0, PM_REMOVE)
Loop
End If
dwFinish = GetTickCount()
dwElapsed = dwFinish - dwStart
Loop While dwElapsed < dwTimeout
Return True
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment