-
Notifications
You must be signed in to change notification settings - Fork 71
/
RedrawDB.ahk
69 lines (63 loc) · 3.52 KB
/
RedrawDB.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
; 1) Disable drawing with "WS_Visible", "LockWindowUpdate" or "WM_SETREDRAW"
; 2) Execute ur code
; 3) Enable drawing with "WS_Visible", "LockWindowUpdate" or "WM_SETREDRAW"
; 4) Call RedrawDB(hWnd) where hWnd is handle to window
; IMPORTANT!
; 5)Turn off composition by Ctrl+Shift+a or disable aero effects manually. If you use hotkey then after script close or reload composition will be returned so i reccomend to manually disable aero effects.
;https://autohotkey.com/board/topic/95930-window-double-buffering-redraw-gdi-avoid-flickering/
^+a:: ; Control+Shift+A to Toggle On and Off
if toggle := !toggle
DllCall("dwmapi\DwmEnableComposition", "uint", 0) ; DllCall For Windows Decomposition ; On
else
DllCall("dwmapi\DwmEnableComposition", "uint", 1) ; DllCall For Windows Decomposition ; Off
return
RedrawDB(hWnd) {
;==========================================================================
; Get required coordinates
;==========================================================================
Static SizeOfWINDOWINFO := 60
VarSetCapacity(WINDOWINFO, SizeOfWINDOWINFO, 0)
NumPut(SizeOfWINDOWINFO, WINDOWINFO, "UInt")
DllCall("GetWindowInfo", "Ptr",hWnd, "Ptr",&WINDOWINFO, "UInt")
WindowX := NumGet(WINDOWINFO, 4, "Int") ; X coordinate of the window
WindowY := NumGet(WINDOWINFO, 8, "Int") ; Y coordinate of the window
WindowW := NumGet(WINDOWINFO, 12, "Int") - WindowX ; Width of the window
WindowH := NumGet(WINDOWINFO, 16, "Int") - WindowY ; Height of the window
ClientX := NumGet(WINDOWINFO, 20, "Int") ; X coordinate of the client area
ClientY := NumGet(WINDOWINFO, 24, "Int") ; Y coordinate of the client area
ClientW := NumGet(WINDOWINFO, 28, "Int") - ClientX ; Width of the client area
ClientH := NumGet(WINDOWINFO, 32, "Int") - ClientY ; Height of the client area
;==========================================================================
; Create Buffer
;==========================================================================
hdcDest := DllCall("GetDC", "Ptr",hWnd)
hdcSrc := DllCall("CreateCompatibleDC", "Ptr",hdcDest) ; buffer
hbm_buffer := DllCall("CreateCompatibleBitmap", "Ptr",hdcDest, "Int",WindowW, "Int",WindowH)
DllCall("SelectObject", "Ptr",hdcSrc, "Ptr",hbm_buffer)
;==========================================================================
; Capture - PrintWindow
;==========================================================================
DllCall("PrintWindow", "Ptr",hwnd, "Ptr",hdcSrc, "uint",0) ; PW_CLIENTONLY bugged on XP so GetWindowInfo() or MapWindowPoints() required to capture client area.
;==========================================================================
; Draw - StretchBlt
;==========================================================================
DllCall("StretchBlt"
, "Ptr", hdcDest
, "Int", 0
, "Int", 0
, "Int", ClientW
, "Int", ClientH
, "Ptr", hdcSrc
, "Int", ClientX - WindowX
, "Int", ClientY - WindowY
, "Int", ClientW
, "Int", ClientH
,"UInt", 0xCC0020) ; SRCCOPY
;==========================================================================
; Clear
;==========================================================================
DllCall("DeleteDC", "Ptr",hdcDest)
DllCall("DeleteDC", "Ptr",hdcSrc)
DllCall("DeleteObject", "Ptr",hbm_buffer)
Return TRUE
}