Adding a gdip bitmap to a mshtml Active-x control

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 08:52

***Warning*** I don't speak geek/nerd so I will mess up my terminology etc.

I am trying to find out if there is a way that I can directly add a gdip drawing to a mshtml: Active-x control without first saving it as a png, jpg, ect

I know how to add it if I first save it as a png etc, but adding it without saving it is a miss.

This is with a png.

Code: Select all

Place_New_Bot_On_Map()
	{
		global
		XBot:= (oBot[Bot_Slot].2-1)*10
		YBot:= (oBot[Bot_Slot].1-1)*10
		Arena_Grid[oBot[Bot_Slot].1,oBot[Bot_Slot].2]:=2
		img:=wb.CreateElement("img")
		oBot[Bot_Slot].img:=img
		img.src:=Bot_PNG[oBot[Bot_Slot].4]
		Style:=img.Style
		for a,b in {left:XBot,top:YBot,position:"absolute",width:10,height:10}
			Style[a]:=b
		wb.Body.AppendChild(oBot[Bot_Slot].img)
	}
Thanks.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 20:20

Alternatively, perhaps someone knows how to draw simple shapes into the ActiveX control. Would prefer to add a bitmap, but there are things I can do with just simple shapes.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 21:33

Would you mind showing a example?

Code: Select all

Add_AutoBot_Layer() ;GUI 5
	{
		global
		Gui,5:+AlwaysOnTop -Caption +Owner1
		Gui,5:Color,010101
		Gui,5:Add,ActiveX,x0 y0 w1300 h600 vwb,mshtml:
		wb.Body.Style.Position:="Absolute"
		style:=wb.Body.Style
		for k,v in {margin:"0px"}
		Style[k]:=V
		wb.Body.Style.BackgroundColor:="#010101" 
		Gui,5:Show,x3 y26 w1300 h600
		Gui,5:+LastFound
		WinSet,TransColor,010101
	}
	
	
	Place_New_Bot_On_Map()
	{
		global
		XBot:= (oBot[Bot_Slot].2-1)*10
		YBot:= (oBot[Bot_Slot].1-1)*10
		Arena_Grid[oBot[Bot_Slot].1,oBot[Bot_Slot].2]:=2
		img:=wb.CreateElement("img")
		oBot[Bot_Slot].img:=img
		img.src:=Bot_PNG[oBot[Bot_Slot].4]
		Style:=img.Style
		for a,b in {left:XBot,top:YBot,position:"absolute",width:10,height:10}
			Style[a]:=b
		wb.Body.AppendChild(oBot[Bot_Slot].img)
	}
	
	Move_Up_Left_Normal()
	{
		global
		Arena_Grid[oBot[g].1,oBot[g].2]:=0
		Arena_Grid[oBot[g].1-1,oBot[g].2-1]:=2
		oBot[g].2-=1
		oBot[g].1-=1
		XXBot:=(oBot[g].2-1)*10
		YYBot:=(oBot[g].1-1)*10
		Style:=oBot[g].img.Style
		Style.Left:=XXBot
		Style.Top:=YYBot
	}	
	
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 21:52

I have no idea what you want to draw. There is a bunch of material on that site I posted. See the Guides and Tutorials section for links.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 21:57

That site is not written in ahk, I have no idea how to translate what it says.
As for what I would like to draw, how about a rectangle or ellipse or even a line.

If I see an example of one of those, I will have a way of translating much of the rest of the stuff from that site.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 22:15

Simple example:

Code: Select all

html =
(
<!DOCTYPE html>
<html>
    <head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta charset="utf-8" />
	<title>HTMLFile</title>
	<script>
	function test() {
	var canvas = document.getElementById('canvas');
	var ctx = canvas.getContext('2d');
	ctx.fillStyle = 'green';
	ctx.fillRect(10, 10, 100, 100);
	}
	function setColor(__color) {
	var canvas = document.getElementById('canvas');
	var ctx = canvas.getContext('2d');
	ctx.fillStyle = __color;
	ctx.fillRect(10, 10, 100, 100);
	}
	</script>
    </head>
<body>
<canvas id="canvas"></canvas>
</body>
</html>
)

Gui, Add, ActiveX, w400 h400 vDoc, about:<!DOCTYPE html><meta http-equiv="X-UA-Compatible" content="IE=edge">
Doc.document.Open()
Doc.document.Write(html)
Doc.document.Close()
Gui, Show
Doc.document.parentWindow.test()
return

!i::Doc.document.parentWindow.setColor("red")
@kczx3 many thanks for sharing the idea of using canvas.


[EDIT] same as above using ahk functions:

Code: Select all

html =
(
<!DOCTYPE html>
<html>
    <head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta charset="utf-8" />
	<title>HTMLFile</title>
    </head>
<body>
<canvas id="canvas"></canvas>
</body>
</html>
)

Gui, Add, ActiveX, w400 h400 vDoc, about:<!DOCTYPE html><meta http-equiv="X-UA-Compatible" content="IE=edge">
Doc.document.Open()
Doc.document.Write(html)
Doc.document.Close()
Gui, Show
canvas := Doc.document.getElementById("canvas")
init()
return

!i::setColor("red")

init() {
global canvas
ctx := canvas.getContext("2d")
ctx.fillStyle := "green"
ctx.fillRect(10, 10, 100, 100)
}
setColor(__color) {
global canvas
ctx := canvas.getContext("2d")
ctx.fillStyle := __color
ctx.fillRect(10, 10, 100, 100)
}
Last edited by A_AhkUser on 22 Nov 2017, 22:19, edited 1 time in total.
my scripts
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 22:16

If it helps



This is made using a mshtml Activex control, but it uses .pngs, I am tired of using pngs and want to use gdip bitmaps with a mshtml control or at the least to draw some other way.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 22:24

That game already seems pretty good if you are just using bitmaps. I think it would be quite a lot of work using a canvas element to create that. Though I’m sure it’s possible.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 22:33

kczx3 wrote:That game already seems pretty good if you are just using bitmaps. I think it would be quite a lot of work using a canvas element to create that. Though I’m sure it’s possible.

That's the thing, it's not using bitmaps, it's using pngs which limits the amount of things that I can do.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

22 Nov 2017, 22:40

A_AhkUser wrote:Simple example:
Thanks, that should help get me started.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Adding a gdip bitmap to a mshtml Active-x control

23 Nov 2017, 09:49

There is a very basic example of what you want to do on W3Schools - https://www.w3schools.com/graphics/game_intro.asp

Edit: This is even closer to what you want - https://www.w3schools.com/graphics/tryi ... lt_gravity
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Adding a gdip bitmap to a mshtml Active-x control

23 Nov 2017, 11:58

kczx3 wrote:There is a very basic example of what you want to do on W3Schools - https://www.w3schools.com/graphics/game_intro.asp

Edit: This is even closer to what you want - https://www.w3schools.com/graphics/tryi ... lt_gravity

There is nothing there about adding a bitmap made with gdip being added to a ActiveX Gui control "MSHTML:",
without first converting it to a saved image file such as a .png which is what I am looking for.


Thank you for the link and trying to help though, I do appreciate the effort.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Adding a gdip bitmap to a mshtml Active-x control

23 Nov 2017, 13:35

You’re missing the point. With the Canvas, you don’t need to use grip at all. You could completely draw everything on the Canvas or you can use the drawImage method that draws an image from a file onto the Canvas.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Adding a gdip bitmap to a mshtml Active-x control

23 Nov 2017, 20:30

And just to round it out... there are tons of these made with an HTML canvas. Just google “html5 canvas flappy bird”

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot] and 298 guests