Created
October 23, 2012 20:28
-
-
Save brigand/3941326 to your computer and use it in GitHub Desktop.
Helper Library for GDIp library Based On Tic's tutorial #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JustTheBasics() { | |
global | |
; Start gdi+ | |
If !pToken := Gdip_Startup() | |
{ | |
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system | |
ExitApp | |
} | |
OnExit, Exit | |
return | |
Exit: | |
; gdi+ may now be shutdown on exiting the program | |
Gdip_Shutdown(pToken) | |
ExitApp | |
Return | |
} | |
SetUpGDIP(iWidth=-1, iHeight=-1) { | |
global | |
Width := iWidth | |
Height := iHeight | |
If (iWidth < 0) { | |
Width := A_ScreenWidth | |
} | |
if (iHeight < 0) { | |
height := A_ScreenHeight | |
} | |
JustTheBasics() | |
; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption | |
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs | |
; Show the window | |
Gui, 1: Show, NA | |
; Get a handle to this window we have created in order to update it later | |
hwnd1 := WinExist() | |
return | |
} | |
StartDrawGDIP() { | |
global | |
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything | |
hbm := CreateDIBSection(Width, Height) | |
; Get a device context compatible with the screen | |
hdc := CreateCompatibleDC() | |
; Select the bitmap into the device context | |
obm := SelectObject(hdc, hbm) | |
; Get a pointer to the graphics of the bitmap, for use with drawing functions | |
G := Gdip_GraphicsFromHDC(hdc) | |
} | |
EndDrawGDIP() { | |
global | |
; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen | |
; So this will position our gui at (0,0) with the Width and Height specified earlier | |
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height) | |
; Select the object back into the hdc | |
SelectObject(hdc, obm) | |
; Now the bitmap may be deleted | |
DeleteObject(hbm) | |
; Also the device context related to the bitmap may be deleted | |
DeleteDC(hdc) | |
; The graphics may now be deleted | |
Gdip_DeleteGraphics(G) | |
} | |
ClearDrawGDIP() { | |
global | |
Gdip_GraphicsClear(G) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment