Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GDI+ standard library 1.45 by tic


  • Please log in to reply
1385 replies to this topic
noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

 

if somone can respond il post what im working on here, you might like it

 

You show first!!!  ;)

 

It depends what controls you want and if you use a layered window or just bitbild things on a standard Gui like this example from Tic

https://ahknet.autoh...tandard.gui.ahk

 

I only created buttons and a simple edit control on a layered window but you have to code the controls from scratch!

 

 

NwJeP7p.png


winXP  and ahk unicode


Icyhate
  • Members
  • 26 posts
  • Last active: Mar 29 2015 09:21 PM
  • Joined: 06 Aug 2013

You show first!!!  ;)

 

It depends what controls you want and if you use a layered window or just bitbild things on a standard Gui like this example from Tic

https://ahknet.autoh...tandard.gui.ahk

 

I only created buttons and a simple edit control on a layered window but you have to code the controls from scratch!

 

 

NwJeP7p.png

lol k :D its pretty much a copy but im liking the progress :D, hold shift, it brings up the sexiest of windows, i wanna do somthing with it but i dont know what, UGH i was thinking of displaying cpu load and ram usage but i could'nt find a way to get the values :CCC

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
CoordMode, Mouse, Screen

;Remove if Gdip.ahk is in your standard library
#Include Gdip.ahk
~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

Width := 35, Height := 35
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pPen := Gdip_CreatePen(0x66ff0000, 3)
Gdip_SetCompositingMode(G, 1)

loop, 72
{
GetKeyState,State,Shift,P
If State = U
break
MouseGetPos, mx, my
sa := A_index * 5
Gdip_DrawArc(G, pPen, 2, 2, 30, 30, 270, sa) 

UpdateLayeredWindow(hwnd1, hdc, mx-13, my-9, Width, Height)
sleep 25
}

gui, destroy
Gdip_DeletePen(pPen)

SelectObject(hdc, obm)

DeleteObject(hbm)

DeleteDC(hdc)

Gdip_DeleteGraphics(G)

Width := 73, Height := 73
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pbrush:= Gdip_BrushCreateSolid(0xffff0000)

loop 42
{
GetKeyState,State,Shift,P
If State = U
break
wh := A_Index + 30
Gdip_DrawArc(G, pPen, 2, 2, 30, 30, 270, sa) 
Gdip_FillEllipse(G, pBrush, 0, 0, wh, wh)
UpdateLayeredWindow(hwnd1, hdc, mx-13, my-9, Width, Height)
sleep 10
}

loop
{
GetKeyState,State,Shift,P
If State = U
{
gui, destroy
Gdip_DeleteBrush(pBrush)

SelectObject(hdc, obm)

DeleteObject(hbm)

DeleteDC(hdc)

Gdip_DeleteGraphics(G)

return
}
}

TrayTip, GDip Example, Press ESC to Close Example, 10, 1

Return


Esc:: 
Exit:

Gdip_DeleteBrush(pBrush)

SelectObject(hdc, obm)

DeleteObject(hbm)

DeleteDC(hdc)

Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return


epiphany
  • Members
  • 1 posts
  • Last active: Dec 07 2013 06:18 AM
  • Joined: 07 Dec 2013

I was wondering is there a way to find the center coordinates to an image.

 

Usage:

  Im using ImageSearch to find if an image is on the screen then I would like to setup a function that randomly clicks around the center of that image, However imagesearch finds the 0, 0 coordinates of the image. 

 

Please help.



noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

@Icyhate

 

That was unexpected! I only wondering how you would turn that in a display of ram/cpu :(

 

you can find the code to extract the info needed from the system here:

http://www.autohotke...mory-load-bars/

 

you can test it ( i use winXP ahk_l )

#Persistent 
SetTimer, check,1000
VarSetCapacity( IdleTicks,    2*4 )
VarSetCapacity( memorystatus, 100 )
return

check:

   IdleTime0 = %IdleTime%
   Tick0 = %Tick%
   DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
   IdleTime := *(&IdleTicks)
   Loop 7
      IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
   Tick := A_TickCount
   load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
   

   DllCall("kernel32.dll\GlobalMemoryStatus", "uint",&memorystatus)
   mem := *( &memorystatus + 4 )    ; 0..100
   tooltip %mem%`n%load%
Return

esc::exitapp

winXP  and ahk unicode


noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

@epiphany

 

It just a bit of maths?

 

example:

gui,add,picture,hwndmypic,c:\image.bmp
controlgetpos,,,width,height,,ahk_id %mypic%  ;to find dimensions of image

coordmode ,pixel ,screen
CoordMode, mouse, screen

ImageSearch, OutputVarX, OutputVarY, 0,0, a_screenwidth, a_screenheight, c:\image.bmp

mousemove,OutputVarX+ width//2,outputvarY+ height//2

winXP  and ahk unicode


mia
  • Members
  • 73 posts
  • Last active: Jul 26 2014 09:28 AM
  • Joined: 05 Aug 2013

hi,

 

help

 

below code is from rhys from page 1  #14 for your guide

 

it will show a circle when you press/hold shift key

 

can someone please edit this code for me

1. what i wanted is when left-mouse-button is press/hold the circle is intantly shown without animation

2. when i resize the circle larger it cant show the whole circle

3. how about fullscreen horizontal line

 

 

thanks in advance

 

mia

 

 

 

;============================ start script ===================================

#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

;============================ end script ===================================



Smurth
  • Members
  • 120 posts
  • Last active: Feb 23 2014 09:58 PM
  • Joined: 13 Dec 2006

Hi,

 

My two cents about this great library...

I've rewrote the DrawImage function to make use of the matrix stuff easier.


Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, alpha=1, s="0,1,0,0")
{
	VarSetCapacity(ColourMatrix, 100, 0)
	Loop, 25
		NumPut(Mod(A_Index-1, 6) ? 0 : 1, ColourMatrix, (A_Index-1)*4, "float")
	NumPut(alpha, ColourMatrix, 72, "float")
	if (s!="0,1,0,0")
	{
		StringSplit, s, s, `,
		s1 := s2*sin(s1)
		sc := 1-s2
		r := 0.3086*sc-s1
		g := 0.6094*sc-s1
		b := 0.0820*sc-s1

		NumPut(r+s2+3*s1,	ColourMatrix, 0,	"float")
		NumPut(r,			ColourMatrix, 4,	"float")
		NumPut(r,			ColourMatrix, 8,	"float")
		NumPut(g,			ColourMatrix, 20,	"float")
		NumPut(g+s2+3*s1,	ColourMatrix, 24,	"float")
		NumPut(g,			ColourMatrix, 28,	"float")
		NumPut(b,			ColourMatrix, 40,	"float")
		NumPut(b,			ColourMatrix, 44,	"float")
		NumPut(b+s2+3*s1,	ColourMatrix, 48,	"float")
		NumPut(s3,			ColourMatrix, 80,	"float")
		NumPut(s3,			ColourMatrix, 84,	"float")
		NumPut(s3,			ColourMatrix, 88,	"float")

		if s4
		{
			NumPut(s4,		ColourMatrix, 12,	"float")
			NumPut(s4,		ColourMatrix, 16,	"float")
			NumPut(s4,		ColourMatrix, 32,	"float")
			NumPut(s4,		ColourMatrix, 36,	"float")
			NumPut(s4,		ColourMatrix, 52,	"float")
			NumPut(s4,		ColourMatrix, 56,	"float")
			NumPut(s4,		ColourMatrix, 60,	"float")
			NumPut(s4,		ColourMatrix, 64,	"float")
			NumPut(s4,		ColourMatrix, 68,	"float")
			NumPut(alpha*(1-s4),ColourMatrix, 72,	"float")
		}
	}

	DllCall("gdiplus\GdipCreateImageAttributes", "UInt*", ImageAttr)
	DllCall("gdiplus\GdipSetImageAttributesColorMatrix", "UInt", ImageAttr, "Int", 1, "Int", 1, "UInt", &ColourMatrix, "Int", 0, "Int", 0)

	DllCall("gdiplus\GdipDrawImageRectRect", "UInt", pGraphics, "UInt", pBitmap
	, "Float", dx, "Float", dy, "Float", dw, "Float", dh
	, "Float", sx, "Float", sy, "Float", sw, "Float", sh
	, "Int", 2, "UInt", ImageAttr, "UInt", 0, "UInt", 0)
	DllCall("gdiplus\GdipDisposeImageAttributes", "UInt", ImageAttr)
}

So, what changes ?

Instead of passing a complex matrix as argument, you can pass 2 parameters:

- Alpha transparency

- Hue, Saturation, Brightness, Alpha

 

The first Alpha is the global alpha of the image; the second one let you remove the dark parts of the image ( if <0 ) or the bright parts of the image ( if >0 ).

The Hue value goes from -PI/2 to PI/2 (0=no hue)

The Saturation goes from 0 (greyscale) to 1 (normal) and beyond (over-saturation)

The Brightness can be 0 (normal) , >0 (bright) or <0 (dark)

 

Hope you will like it...



cmann
  • Members
  • 1 posts
  • Last active: Jan 20 2014 01:31 PM
  • Joined: 19 Jan 2014

I cannot get any of the tutorials to work and the GDI+ library itself gives off a lot of warnings.

When I run the tutorials nothing happens, the script shows up in the tray but nothing happens on screen.

The two different warnings that I get from the GDI script are:

 

C:\My Documents\Downloads\New folder\Gdip.ahk (413) : ==> Warning: This local variable has the same name as a global variable.
     Specifically: hbm  (in function CreateDIBSection)
 
and
 
C:\My Documents\Downloads\New folder\Gdip.ahk (319) : ==> Warning: This local variable has the same name as a global variable.
     Specifically: hbm  (in function Gdip_BitmapFromHWND)


tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007

smurth

 

I think it would be better to have a helper function to create the matrix rather than changing the function for compatibility's sake. You can already change the transparency by just passing a single number.

 

cmann

 

Strange. Has ahk changed in some way? Perhaps an update? I guess it's only a warning so hopefully the function is altering the local variable rather than the global. Have you installed the x64 version of ahk? That could be a reason it's not working. The x64 compatible version of the ahk library is in this thread somewhere. I'll add it to the first link if someone gets it for me.

 

Thanks



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
@ tic

Here you go https://ahknet.autoh...ll/Gdip_All.ahk

:)
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007

 

Thanks Blackholyman. Tried updating the initial post but I get an error:

 

You are not allowed to use that image extension on this community.

 

A bit upsetting that the one time I come back to make an edit, I have problems again with the reason I left: The state of the forum.

I'm guessing it's either the .dll or the .bra extension.



xZomBie
  • Members
  • 42 posts
  • Last active: Jan 07 2016 06:46 AM
  • Joined: 12 Jul 2013

O.o that's why I can't get any examples to work...

 

Hi tic! Can you please create a topic in the new forum?



Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008

It is a good idea to restart or duplicate your thread in the other forum... We miss you !


"You annoy me, therefore I exist."

WeezerOhio
  • Members
  • 59 posts
  • Last active: Jun 20 2014 10:27 PM
  • Joined: 20 Dec 2010

I have downloaded into the folder and #Include'd the BRA.ahk file, but when I try to do Example 11, it does not work.  It says "Could not load the image specified".  What could be my problem?



alcapowned
  • Members
  • 3 posts
  • Last active: Feb 18 2014 12:34 AM
  • Joined: 15 Feb 2014

None of the tutorial files seem to work for me. Running them (or other ahk scripts I made to draw test objects) don't result in anything happening.

 

There are no compilation errors and the log makes it seem like everything is working.

 

Could anyone help me out? (I'm using Windows 7, no desktop view modifications or workspaces).

 

 

edit:

 

Nevermind. The issue was that I needed to use the Gdip_All.ahk library instead of just Gdip.