Re: GDI+ standard library 1.45 by tic
Posted: 15 Nov 2017, 12:12
i will start to work on it.nnnik wrote:I think instead of waiting for them it would be faster to implement AHK v1.1 backwards compatability.
Let's help each other out
https://www.autohotkey.com/boards/
i will start to work on it.nnnik wrote:I think instead of waiting for them it would be faster to implement AHK v1.1 backwards compatability.
Thanks. I found the following, taken from the last github link above, to be helpful in interpreting the above. I reproduce it here for reference:guest3456 wrote:just for reference for people reading:
tic's original:
https://github.com/tariqporter/Gdip/blo ... r/Gdip.ahk
Rseding's unicode and x64 Gdip_All fixes:
https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk
AHK v2 version (now also backward compatible with v1 thanks to @nnnik):
https://github.com/mmikeww/AHKv2-Gdip
History
- @tic created the original Gdip.ahk library
- @Rseding91 updated it to make it compatible with unicode and x64 AHK versions and renamed the file Gdip_All.ahk
- this repository updates @Rseding91's Gdip_All.ahk to make it compatible with AHK v2
That is meant to be used for AHK v2, but it should also be compatible with AHK 1.1. You can use that or you can use the normal Gdip_All.ahk, which ever you chooseJoeSchmoe wrote:Am I correct in understanding that everyone should use the mmikeww AHKv2-Gdip version? It seems to be the most compatible. (I actually use AHK 1.1)
Code: Select all
DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
Code: Select all
DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt", Region)
Code: Select all
;CfgSigrokJSJ = -d fx2lafw:conn=7.2 -O binary -o jsj.txt -c samplerate=20k --samples 1000
CfgSigrokJSJ = -d demo -O binary -o jsj.txt -c samplerate=20k --samples 10
run sigrok-cli.exe %CfgSigrokJSJ%,,hide
loopcount:=0
Gui,scopejsj:+Resize +caption
Gui,scopejsj:Add, Text ,x0 y0 h12 w2000 hwndhwnd1 +wrap vctrlv1 ;h w create disp area
Gui,scopejsj:Show,H300 W300 ;h w set window frame hight width
DC:=DllCall("GetDC",UInt,hwnd1)
MouseGetPos,x,y
DllCall("SelectObject",UInt,DC,UInt,DllCall("gdi32.dll\CreatePen","int",0,"int",1,"uint",0x00aa00))
DllCall("MoveToEx",UInt,DC,Uint,x,Uint,y,Uint,0)
SetTimer dispUp,500
;******main graph loop loop
DrawLine:
++loopcount
;MouseGetPos,x,y
inloop:
++y
StringMid,xx,hp,1
xx=Asc(xx)
DllCall("SelectObject",UInt,DC,UInt,DllCall("gdi32.dll\CreatePen","int",0,"int",1,"uint",0xffffff))
DllCall("MoveToEx",UInt,DC,Uint,y,Uint,0)
DllCall("LineTo",uint,DC,Uint,y,uint,200)
DllCall("MoveToEx",UInt,DC,Uint,y,Uint,xx_old,Uint,0)
DllCall("SelectObject",UInt,DC,UInt,DllCall("gdi32.dll\CreatePen","int",0,"int",1,"uint",0x00aa00))
DllCall("LineTo",uint,DC,Uint,y,uint,xx,int,0)
xx_old:=xx
;DllCall("ScrollWindow",uInt,DC,Int,0,Int,-1,Int,NULL,Int,NULL)
if y< 1000
goto inloop
y:=0
GOTO DrawLine
return
;********update status display sub call timer
dispUp:
aaa:=strlen(jsj)
run sigrok-cli.exe %CfgSigrokJSJ%,,hide
FileRead,jsj,jsj.txt
GuiControl scopejsj:,ctrlv1,%aaa%_%jsj%_%x%_%jsj%(XX=%xx%_X=%X%_Y=%Y%_Z=%Z%_loops=%loopcount%)
esc::
GuiClose: ; User clicked "x" or pressed alt+f4 to closed the window.
ExitApp
Code: Select all
loopcount:=0,x:=100,y:=100
Gui,1:+LastFound +Resize +caption
Gui,1: Add, Text ,h12 w200 x0 y0 vcunt1,
Gui,1:Show,H300 W300, vcunt
GuiHwnd := WinExist()
hDC:=DllCall("GetDC",UInt,GuiHwnd)
pen:=DllCall("gdi32.dll\CreatePen","int",0,"int",1,"uint",0x0000ff)
MouseGetPos,x,y
DllCall("SelectObject",UInt,hdc,UInt,(pen))
DllCall("MoveToEx",UInt,hdc,Uint,x,Uint,y,Uint,0)
DrawLine:
loopcount:=loopcount+1
MouseGetPos, x, y
Gui, 1:Show,,(XX=%xx%_X=%X%_Y=%Y%_Z=%Z%_loops=%loopcount%)
GuiControl 1:,cunt1,(XX=%xx%_X=%X%_Y=%Y%_Z=%Z%_loops=%loopcount%)
DllCall("LineTo",uint,hdc,Uint,x-3,Uint,y-28)
GOTO DrawLine
esc::
GuiClose: ; User clicked "x" or pressed alt+f4 to closed the window.
ExitApp
Code: Select all
;copyright jonathanscottjames the great
loopcount:=0,x:=100,y:=100
Gui,1:+LastFound +Resize HwndScopehwd
Gui,1: Add, Text ,h12 w200 x0 y0 vScopev
Gui,1:Show,H300 W1024,
hDC:=DllCall("GetDC",UInt,Scopehwd)
pen:=DllCall("CreatePen","int",0,"int",1,"uint",0x0000ff)
MouseGetPos,x,y
DllCall("SelectObject",UInt,hdc,UInt,(pen))
DllCall("MoveToEx",UInt,hdc,Uint,y,Uint,x,Uint,0)
SetTimer statdisp,100
DrawLine:
loopcount:=loopcount+1
y:=y+1-1007*(y>1007),x:=x+1-50*(x>50)
DllCall("SelectObject",UInt,hdc,UInt,DllCall("CreatePen","int",0,"int",1,"uint",0xffffff))
DllCall("MoveToEx",UInt,hdc,Uint,y,Uint,0)
DllCall("LineTo",uint,hdc,Uint,y,Uint,51)
DllCall("SelectObject",UInt,hdc,UInt,DllCall("CreatePen","int",0,"int",1,"uint",0x0000ff))
DllCall("LineTo",uint,hdc,Uint,y,Uint,x)
;sleep ,1
GOTO DrawLine
statdisp:
GuiControl 1:, Scopev,(%Scopehwd%_X=%X%_Y=%Y%_loops=%loopcount%)
Gui, 1:Show,,(X=%X%_Y=%Y%_loops=%loopcount%)
return
esc::
GuiClose: ; User clicked "x" or pressed alt+f4 to closed the window.
ExitApp
;MouseGetPos, x, y
Code: Select all
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk
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
; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 5100, Height := 6600
; 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
bhdc := CreateCompatibleDC()
; Select the bitmap into the device context
obm := SelectObject(bhdc, hbm)
; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(bhdc)
; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)
; Create a fully opaque red pen (ARGB = Transparency, red, green, blue) of width 3 (the thickness the pen will draw at) to draw a circle
pPen := Gdip_CreatePen(0xffff0000, 3)
; Draw an ellipse into the graphics of the bitmap (this being only the outline of the shape) using the pen created
; This pen has a width of 3, and is drawing from coordinates (100,50) an ellipse of 200x300
Gdip_DrawEllipse(G, pPen, 50, 50, 5000, 6500)
; Delete the pen as it is no longer needed and wastes memory
Gdip_DeletePen(pPen)
; Create a slightly transparent (66) blue pen (ARGB = Transparency, red, green, blue) to draw a rectangle
; This pen is wider than the last one, with a thickness of 10
pPen := Gdip_CreatePen(0x660000ff, 10)
; Draw a rectangle onto the graphics of the bitmap using the pen just created
; Draws the rectangle from coordinates (250,80) a rectangle of 300x200 and outline width of 10 (specified when creating the pen)
Gdip_DrawRectangle(G, pPen, 50, 50, 5000, 6500)
; Delete the brush as it is no longer needed and wastes memory
Gdip_DeletePen(pPen)
StringToPrint := "Defenestration can be hazardous"
Document_Name :="print test"
DllCall("LoadLibrary","str","comdlg32.dll")
;PRINTDIALOG_STRUCT
VarSetCapacity(PRINTDIALOG_STRUCT,66,0), NumPut(66,PRINTDIALOG_STRUCT)
; PD_RETURNDEFAULT: Return hDevMode and hDevNames for default printer,
; instead of displaying the dialog.
; PD_RETURNDC: Return a printer device context.
NumPut((PD_RETURNDC:=0x100),PRINTDIALOG_STRUCT,20) ; (PD_RETURNDC:=0x100)|(PD_RETURNDEFAULT:=0x400)
if !DllCall("comdlg32\PrintDlgA","uint",&PRINTDIALOG_STRUCT)
return
; Free unneeded (for now) structures created by PrintDlg().
if (hDevMode := NumGet(PRINTDIALOG_STRUCT,8))
DllCall("GlobalFree","uint",hDevMode)
if (hDevNames := NumGet(PRINTDIALOG_STRUCT,12))
DllCall("GlobalFree","uint",hDevNames)
; Get the newly created printer device context.
if (hDC := NumGet(PRINTDIALOG_STRUCT,16))
{
VarSetCapacity(DOCUMENTINFO_STRUCT,20,0), NumPut(20,DOCUMENTINFO_STRUCT), NumPut(&Document_Name,DOCUMENTINFO_STRUCT,4)
if DllCall("StartDoc","uint",hDC,"uint",&DOCUMENTINFO_STRUCT,"int") > 0
{
if DllCall("StartPage","uint",hDC,"int") > 0
{
DllCall("TextOut","uint",bhDC,"int",xPos,"int",yPos ,"str",StringToPrint,"int",StrLen(StringToPrint))
BitBlt(hDC, 0, 0, width, height, bhDC, 0, 0)
DllCall("EndPage","uint",hDC,"int")
}
DllCall("EndDoc","uint",hDC)
}
DllCall("DeleteDC","uint",hDC)
}
; 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)
Return
Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return
gdi.ahk != gdip.ahkjonathan scott james wrote:i copied gdi.ahk into the directoryCode: Select all
#Include, Gdip.ahk