AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GDI+ standard library 1.22 by tic
Goto page 1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Wed May 28, 2008 3:27 am    Post subject: GDI+ standard library 1.22 by tic Reply with quote

Download: Gdip.ahk

I know there is already one of these, but I aim to give an easy to use and full featured gdi+ library.

A big thank you to Lexikos for his massive help with this!

This is not a complete (or even nearly finished) release. I am only posting this as a way to easily keep track of which version I am up to and to give help related to gdi+ so please no complaining at the "library".

If your OS is not >= XP then you will need gdiplus.dll: gdiplus.dll

You will need to place it in the same directory as the script
Minimum OS is Windows 2000

Examples

Example 1: Gdip.Tutorial.1-Draw.Shapes.ahk - Create a simple gui and draw an ellipse and a rectangle

Example 2: Gdip.Tutorial.2-Draw.Outlined.Shapes.ahk - Create a simple gui and draw the outlines of an ellipse and a rectangle

Example 3: Gdip.Tutorial.3-Create.Gui.From.Image.ahk - Create a gui from an existing image on disk

Example 4: Gdip.Tutorial.4-Draw.Circles.ahk - Create a fullscreen gui and fill it with random ellipses

Example 5: Gdip.Tutorial.5-Create.Bitmap.ahk - Put a few shapes into a bitmap and save to a ".png" filetype

Example 6: Gdip.Tutorial.6-Image.Editing.ahk - Take files from disk, load them onto a background and save to a ".png" filetype

Example 7: Gdip.Tutorial.7-Draw.draggable.rounded.rectangle.ahk - Draw a rounded rectangle for a gui and allow it to be dragged with the left click of the mouse

Example 8: Gdip.Tutorial.8-Write.text.onto.a.gui.ahk - Take the rounded rectangle gui and add text to it, showing all the text options possible

Example 9: Gdip.Tutorial.9-Create.a.progress.bar.on.standard.gui.ahk - Create a nice looking progress bar using the library in a standard gui


Last edited by tic on Sun Oct 05, 2008 11:58 pm; edited 39 times in total
Back to top
View user's profile Send private message
Trikster



Joined: 15 Jul 2007
Posts: 1187
Location: Enterprise, Alabama

PostPosted: Wed May 28, 2008 3:36 am    Post subject: Reply with quote

Examples? Laughing

Or please get in the IRC.
_________________
ScriptPad/~dieom/dieom/izwian2k7/Ian/God

Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Wed May 28, 2008 3:42 am    Post subject: Reply with quote

Well the 1st example I have just posted is how to set a pixel to any colour in an image and save it as any filetype:

Code:
#SingleInstance, Force
SetBatchLines, -1
SetWorkingDir %A_ScriptDir%

#Include Gdip.ahk

pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile("in.png")
Gdip_SetPixel(pBitmap, 100, 100, 0xffff0000)
Gdip_SaveBitmap(pBitmap, "out.png")
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
ExitApp
Return


Very simple example, but more will come. If you see one you like the look of then ask and I'm sure I'll already have an existing example lying around
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Sat May 31, 2008 1:37 am    Post subject: Reply with quote

Example 1 released: This will create a "screensaver" like effect by drawing random circles on the screen, that are randomly filled with different hatched brushes.

Gdip updated to 1.01
Back to top
View user's profile Send private message
Guest






PostPosted: Sat May 31, 2008 2:12 pm    Post subject: Reply with quote

I just d/l and ran it, and... - nothing happens.
Back to top
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Sat May 31, 2008 10:42 pm    Post subject: Reply with quote

Which OS are you on? If you are Win2000 then you will also need to download gdiplus.dll from the 1st post. Please redownload the example and library
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Sun Jun 01, 2008 9:56 pm    Post subject: Reply with quote

Please download version 1.02 of the library! There are more than just cosmetic changes.

Also example 2 has been added. Could people please repond with how they useful/hard they are finding them or else I don't know if there's any point continuing! Razz

Example 2 will show you how to create a bitmap, fill it with shapes and save to any supported filetype
Back to top
View user's profile Send private message
k3ph



Joined: 21 Jul 2006
Posts: 127

PostPosted: Mon Jun 02, 2008 3:13 am    Post subject: Reply with quote

fast & furious gdi+ manipulation!
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2419

PostPosted: Mon Jun 02, 2008 5:08 am    Post subject: Reply with quote

Cool Smile
Back to top
View user's profile Send private message Visit poster's website
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Thu Jun 12, 2008 5:07 pm    Post subject: Reply with quote

thanks for sharing this well organized library and kind tutorials
gdi is always been an inviolable area for beginners (non-programmers)
seems it will take me to the sweet gdi world
i like the tutorials Smile
Thanks tic!!
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Fri Jun 13, 2008 12:06 am    Post subject: Reply with quote

Thank you for your kind words. As there is at least some enthusiasm (Razz) I have decided to rejiggle the examples. I have made a new 1st example and moved the other ones onwards. The new example is much easier to understand. The same method is used for any gui using gdi+

Please comment if you want some more examples at this level! I guarantee anyone else can be a master of gdi+ in a matter of hours!
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Fri Jun 13, 2008 1:39 am    Post subject: Reply with quote

people like me who never learn gdi before, must try 1st tutorial on top post.
after following 1st tutorial with 0% knowledge of gdi.
i could draw a frame, filled rectangle in only 20 mins
how easy tic made it for us. this is awesome Smile
thank you so much tic
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Rhys



Joined: 17 Apr 2007
Posts: 730
Location: Florida

PostPosted: Fri Jun 13, 2008 6:03 am    Post subject: Reply with quote

Tic, I'm gonna go through your examples tomorrow - Here's the video I mentioned of the press+hold for right click in vista - The quality is crap but you can see what I'm talking about at least: http://www.youtube.com/watch?v=uvJE7vgw3ts

That's what I'd like to try to emulate once I get better. Difficulty on a scale of 1-10?
_________________
[Join IRC!]
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1364

PostPosted: Fri Jun 13, 2008 10:52 am    Post subject: Reply with quote

I've watched the video. If you need a custom texture on the circle as in that example then its a 7/10 but if you just want to draw a circle and fill it with a brush (can be a pre-textured brush) then 3/10. I'll get onto giving an example soon...

Edit:

I have updated the library again. Make sure you always have the latest one!
There is another simple example now using pens rather than brushes!
Back to top
View user's profile Send private message
Rhys



Joined: 17 Apr 2007
Posts: 730
Location: Florida

PostPosted: Tue Jun 24, 2008 3:55 am    Post subject: Reply with quote

What I've gotten so far... Hold Shift down to draw a circle around your mouse - It will stay as long as you hold shift.

Forgive the code, still testing (even if I'm just hacking up tic's example)!

Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk
Return
~Shift::
; 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 := 56, Height := 56
;Width := A_ScreenWidth, Height := A_ScreenHeight

; 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()

; 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)

; 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 brush (ARGB = Transparency, red, green, blue) to draw a circle
hBrush := Gdip_BrushCreateSolid(0xffff0000)


; Fill the graphics of the bitmap with an ellipse using the brush created
; Filling from coordinates (100,50) an ellipse of 200x300
;Gdip_FillEllipse(G, hBrush, 100, 50, 600, 600)

; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(hBrush)

; Create a slightly transparent (66) blue brush (ARGB = Transparency, red, green, blue) to draw a rectangle
hBrush := Gdip_BrushCreateSolid(0x660000ff)
hBrush:=Gdip_BrushCreateHatch(0x660000ff, 0xff0000ff, 47)

; Fill the graphics of the bitmap with a rectangle using the brush created
; Filling from coordinates (250,80) a rectangle of 300x200
;Gdip_FillRectangle(G, hBrush, 250, 80, 300, 200)

; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(hBrush)


hBrush:=Gdip_BrushCreateSolid(0xEEff0000)
hPen:=Gdip_CreatePen(0xEEFFFFee0, 2)
fatPen:=Gdip_CreatePen(0xEE0000FF, 5)
CoordMode, Mouse, Screen

Loop,60
{
GetKeyState,State,Shift,P
If State = U
   Break
MouseGetPos,MX,MY
;Gdip_DrawArc(pGraphics, hPen, x, y, w, h, StartAngle, SweepAngle)
Gdip_SetCompositingMode(G, 1)
Gdip_Drawarc(G, FatPen, 2, 2, 50, 50, 270, A_Index*6)
Gdip_SetCompositingMode(G, 0)
Gdip_Drawarc(G, hPen, 2, 2, 50, 50, 270, A_Index*6)
UpdateLayeredWindow(hwnd1, hdc, MX-25, MY-25, Width, Height)
Sleep,10
}
Gdip_SetCompositingMode(G, 0)
Loop,
{
   GetKeyState,State,Shift,P
   If State = U
      Break
   MouseGetPos,MX,MY
   UpdateLayeredWindow(hwnd1, hdc, MX-25, MY-25, Width, Height)
   Sleep,10
}
; 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)
Gui,Destroy

; 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

;#######################################################################
Esc::
Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

_________________
[Join IRC!]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3, 4, 5, 6  Next
Page 1 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group