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
Lazylimey
  • Members
  • 9 posts
  • Last active: Jun 27 2013 11:13 PM
  • Joined: 30 May 2013

Hi again Subsequent to my above message:-

 

 

I tried Javascript injection on IE window and received - IE has disabled cross injection - looking to see if that can be disabled in IE 9

 

No Activate did indeed stop gui  from deactivating main window - however it still steals focus from the input box on the main window which is annoying - cos its almost all I need to fix now

 

Any ideas?



Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010

That should not happen. What browser are you using? The text entry field in the flash object loses focus when the GUI shows up?



Lazylimey
  • Members
  • 9 posts
  • Last active: Jun 27 2013 11:13 PM
  • Joined: 30 May 2013

Hi,

 

Tested on Firefox 21.0 and IE 9.0.15  - select input box on Flash Game window (whatever size) - start .ahk app which displays the Gui and cursor is lost in input box and typing is interrupted which seems to be because the control focus is lost. Click focus back to the input box and next Gui display removes cursor once again.

 

This also happens if a msgbox is shown - which is expected I believe since in that case focus does go to the msgbox window.

 

I have not yet tested on a non flash window but I suspect it would act the same.

 

Thanks



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

Here's an example I gave a long time ago. Ateroids within the client area of a notepad window

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Persistent

;#Include, Gdip.ahk

If !pToken := Gdip_Startup()
{
	MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	ExitApp
}
OnExit, Exit

Run, Notepad,,, PID
WinWait ahk_pid %PID%
WinGet, list, List, ahk_pid %PID%
Loop, %list%
{
	WinGetTitle, title, % "ahk_id " list%A_Index%		;%
	if InStr(title, "Notepad") 
		hwnd1 := list%A_Index%
}
if !hwnd1
{
	MsgBox, 48, No window found!, No matching Notepad window found!
	ExitApp
}
WinGetPos,,, Width, Height, ahk_id %hwnd1%

hwnddc := GetDC(hwnd1)
hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4)

pBrushSHIP1 := Gdip_BrushCreateSolid(0xffa39f9f)
pBrushSHIP2 := Gdip_BrushCreateSolid(0xff7f7575)
pBrushSHIP3 := Gdip_BrushCreateSolid(0xff4c4a4a)

pBitmapBackground := CreateBackground(Width, Height)

Ship = 5|0|20|10|0|-50|-20|10
x := Width//2, y := Height//2, Vx := Vy := Va := 0
SetTimer, Update, 30
return

;#######################################################################

Update:
arr := ""
Va += GetKeyState("Left") ? -0.1 : GetKeyState("Right") ? 0.1 : 0
Loop, Parse, Ship, |
	Mod(A_Index, 2) ? xt := A_LoopField : arr .= xt*cos(Va)-A_LoopField*Sin(Va) "|" xt*Sin(Va)+A_LoopField*Cos(Va) "|"
StringTrimRight, arr, arr, 1

Vs := GetKeyState("Up") ? 0.4 : GetKeyState("Down") ? -0.2 : 0
Vx := Vx*0.95+Sin(Va)*Vs, Vy := Vy*0.95-Cos(Va)*Vs
x := x < 0 ? Width : x > Width ? 0 : x+Vx , y := y < 0 ? Height : y > Height ? 0 : y+Vy

Gdip_DrawImage(G, pBitmapBackground, 0, 0, Width, Height)

StringSplit, narr, arr, |
1narr := narr1+x "," narr2+y "|" narr3+x "," narr4+y "|" narr5+x "," narr6+y
2narr := narr5+x "," narr6+y "|" narr7+x "," narr8+y "|" narr1+x "," narr2+y
3narr := narr1+x "," narr2+y "|" narr3+x "," narr4+y "|" narr1+x "," ((narr4-narr2)//2)+y "|" narr7+x "," narr8+y

Gdip_FillPolygon(G, pBrushSHIP1, 1narr)
Gdip_FillPolygon(G, pBrushSHIP2, 2narr)
Gdip_FillPolygon(G, pBrushSHIP3, 3narr)
Gdip_DrawImage(G, pBitmap1)
BitBlt(hwnddc, 0, 0, Width, Height, hdc, 0, 0)
return

;#######################################################################

CreateBackground(Width, Height)
{
	pBitmap := Gdip_CreateBitmap(Width, Height)
	G := Gdip_GraphicsFromImage(pBitmap), Gdip_SetSmoothingMode(G, 4)

	pBrushBlack := Gdip_BrushCreateSolid(0xff000000)
	Gdip_FillRectangle(G, pBrushBlack, 0, 0, Width, Height)
	Gdip_DeleteBrush(pBrushBlack)

	pBrushStar := Gdip_BrushCreateSolid(0xffeeeeee)
	Loop, % (Width*Height)/400		;%
	{
		Random, s, 1, 4
		Random, x, -s//2, Width+(s//2)
		Random, y, -s//2, Height+(s//2)
		Gdip_FillEllipse(G, pBrushStar, x, y, s, s)
	}
	Gdip_DeleteGraphics(G)
	Gdip_DeleteBrush(pBrushStar)
	return pBitmap
}

;#######################################################################

GuiClose:
Exit:
Gdip_DeleteBrush(pBrushSHIP1), Gdip_DeleteBrush(pBrushSHIP2), Gdip_DeleteBrush(pBrushSHIP3)
Gdip_DisposeImage(pBitmapBackground)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
WinKill, ahk_id %hwnd1%
ExitApp
return


skwire
  • Moderators
  • 279 posts
  • Last active: Aug 12 2014 05:16 PM
  • Joined: 18 Jan 2006

Is it possible to retrieve the bits per pixel (BPP) value of an image using gdip?  If so, how?



Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010

Yes. The BITMAPINFOHEADER structure in the header of a DIB has the field biBitCount, which is a Short containing the bits per pixel. These links may be helpful in dealing with this structure:

 

http://www.autohotke...tmap-gradients/

http://www.autohotke...oheader-bisize/

 

Some of the above scripts work with BMP files; they can be made to work with DIBs by subtracting 14 bytes from all offsets, the size of the bitmap file header.



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Trying to get some exposure here. I was looking at the examples, but many of them don't seem to work for me. One such example is Example 3: Gdip.Tutorial.3-Create.Gui.From.Image.ahk. Am I doing something wrong, or is the example too dated?


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

Trying to get some exposure here. I was looking at the examples, but many of them don't seem to work for me. One such example is Example 3: Gdip.Tutorial.3-Create.Gui.From.Image.ahk. Am I doing something wrong, or is the example too dated?

Use this all compatible GDIP lib.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

That worked. Thank you!


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Hi all,

 

I am working on drawing a rounded GUI, similar to the one in Example 7. The only real difference is that I want to draw a bitmap from an image onto the GUI. I am new to this all, so I am not sure where I am going wrong. From debugging, it looks like SelectObject is failing. Would someone mind helping me out?

 

 

Edit: Actually, here's an approach where I successfully have a rounded GUI + pic, but the pic itself is not rounded.

Script:

Spoiler

Edited by Verdlin, 16 August 2013 - 11:17 PM.

Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


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

Hey Verdlin....I haven't been here for a while! Unfortunately it's not as simple as you're wanting. The easiest approach would be to use the DrawRoundedRectangle function and then use machine code to draw the bitmap by applying the rectangle's alpha channel onto the image. Let me know if you need an example...otherwise study the GDI+ ImageSearch thread to learn more about machine code with GDI+



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Hey, tic! Thank you for the quick reply!

 

I am glad to hear that it is difficult simply because, if it was easier, that means there was a chance I would've figured it out! Anyway, I most likely will need an example, but I will do my best to search that thread and see what I can learn.


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


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

In fact....I think somewhere in these 83 pages (!!) I have already written a function that could be used for exactly that. It would take 2 bitmaps; One as the image and one as the transparency mask. I'll need to have a look through some time to find it...



iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009
could someone tell me if I use GDI+ commands correctly in my script or not?

The thing is that my script crashes upon 3rd upload and I need to be sure that it's not because of incorrect GDI+ usage, because yet no one (and even Lexikos) can define what causes my script to crash.

guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

could someone tell me if I use GDI+ commands correctly in my script or not?

The thing is that my script crashes upon 3rd upload and I need to be sure that it's not because of incorrect GDI+ usage, because yet no one (and even Lexikos) can define what causes my script to crash.


you are calling Gdip_Startup() at the top of the script, but then you call it again during the PrntScrn hotkey? that makes no sense.

similarly you have 3 separate spots where you are calling Gdip_Shutdown()

stop doing all of that. simply call Startup once at the top of the script, and then call Shutdown once before you ExitApp your script. this would be a good use for the OnExit command to specify a specific subroutine where you call Shutdown