Code: Select all
hdc2 := CreateCompatibleDC()
hbm2 := Gdip_CreateCompatibleBitmap(hdc2, 100, 100)
obm2 := SelectObject(hdc2, hbm2)
BitBlt(hdc2, 0, 0, 100, 100, hdc, 0, 0)
Code: Select all
Gui, +HwndhWin +E0x80000
Gui, Show
pToken := Gdip_Startup()
hdc := CreateCompatibleDC()
hbm := CreateDIBSection(100, 100)
obm := SelectObject(hdc, hbm)
; draw something in hdc
G := Gdip_GraphicsFromHDC(hdc)
pPen := Gdip_CreatePen(0xffff0000, 3)
Gdip_DrawEllipse(G, pPen, 0, 0, 80, 80)
Gdip_DeletePen(pPen)
; display hdc
UpdateLayeredWindow(hWin, hdc, A_ScreenWidth//2, A_ScreenHeight//2, 100, 100)
; i want to save hdc to hdc2, so i can quickly restore hdc from hdc2 later
hdc2 := CreateCompatibleDC()
hbm2 := Gdip_CreateCompatibleBitmap(hdc2, 100, 100)
obm2 := SelectObject(hdc2, hbm2)
; try to copy hdc to hdc2, but it faild
BitBlt(hdc2, 0, 0, 100, 100, hdc, 0, 0)
gosub, displayDC
return
displayDC:
w:=500, h:=150
Gui, 2:+HwndhWin2
Gui, 2:Show, w%w% h%h% x0 y0
; source_hdc := hdc ; success
source_hdc := hdc2 ; only black
dest_hdc := GetDC(hWin2)
BitBlt(dest_hdc, 0, 0, w, h, source_hdc, 0, 0)
return
2GuiClose:
Gdip_Shutdown(pToken)
Gdip_DeleteGraphics(G)
SelectObject(hdc, obm)
DeleteDC(hdc)
DeleteObject(hbm)
ExitApp
return
Gdip_CreateCompatibleBitmap(hdc, w, h) {
return DllCall("gdi32\CreateCompatibleBitmap", "UPtr", hdc, "Int", w, "Int", h)
}
#Include Gdip_All.ahk