GDIP+ and ActiveX HTML Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

GDIP+ and ActiveX HTML

08 Jan 2023, 16:19

Hello, folks.

I'm working with GDIP+ drawing images and coloring the background of the native AHK GUI.

My problem is my HTML ActiveX content displays behind the painted background. It seems to display directly on the GUI itself, as it should, but below the GDIP+ images or painted background. How do I make my HTML display above a GDIP bitmap?

Of course, leaving the GUI default without GDIP drawings/BG paint, then the HTML text appears as it should.
But still, I don't want use base GUI design.

Alternatively, if I'm using custom windows like in the code below, how do I access and draw on that BITMAP again after window creation? A solution for either would work for me.

Code: Select all

 New Custom_Window( x:= 0 , y:= 0 , w:= 500 , h:= 500 , Name:= "1" , Options:= "-Caption +AlwaysOnTop -DPIScale " , Title:= "Explorer" , Background_Bitmap:=BG_Art())
 

HTML_page =
( Ltrim Join
<!DOCTYPE html>
<html>
	<head>
		<style>
			body{font-family:sans-serif;background-color:#dde4ec;}
			#title{font-size:36px;}
			#corner{font-size:10px;position:absolute;top:8px;right:8px;}
			p{font-size:16px;background-color:#efefef;border:solid 1px #666;padding:4px;}
			#footer{text-align:center;}
		</style>
	</head>
	<body>
			TEXT, GRAPHICS and STUFFFFF!!!!!!!
			
		</p>
	</body>
</html>
)

 
Gui,Font,cWhite s10
Gui, Add, ActiveX, x332 y66 w340 h380 vWB, Shell.Explorer  ; The final parameter is the name of the ActiveX component.
WB.silent := true ;Surpress JS Error boxes
Display(WB,HTML_page)
ComObjConnect(WB, WB_events)  ; Connect WB's events to the WB_events class object.
Gui, Show, w900 h700
 
 BG_ART()
 {
	pBitmap:=Gdip_CreateBitmap( 900 ,900 ) ; CANVAS
	G := Gdip_GraphicsFromImage( pBitmap )
	Gdip_SetSmoothingMode( G , 4 )
	Brush := Gdip_BrushCreateSolid( "0xFF38393C" )
	Gdip_FillRectangle( G , Brush , -2 , -2 , 746+145, 406+100+100 ) 
	Gdip_DeleteBrush( Brush )
	
	Brush := Gdip_BrushCreateSolid( "0xFF333437" )
	Gdip_FillRoundedRectangle( G2 , Brush , 256 , 280+195 , 228 , 38 , 15 )
	Gdip_DeleteBrush( Brush )

	return pBitmap
 
 }
 

BG_ART() contains the pointer information. But still can't draw on the background again.

These functions are a bit different from CreateDIBSection, CreateCompatibleDC, SelectObject, in how you access the bitmap again.
Please advise. Thanks.
User avatar
flyingDman
Posts: 2832
Joined: 29 Sep 2013, 19:01

Re: GDIP+ and ActiveX HTML

08 Jan 2023, 18:01

I don't understand your script. But the following seems to accomplish the desired result (uses the GDIP lib)

Code: Select all

#include <Gdip_all>
gui, margin, 0,0
Gui, Add, ActiveX, x250 y250 w400 h400 vWB1, HTMLfile
WB1.write(HTML())
Gui, Add, Pic, x0 y0 w900 h900 vPic, % "hBitmap:*" BG_ART()
gui, show

BG_ART()
	{
	pToken := Gdip_Startup()
	pBitmap:=Gdip_CreateBitmap(900 ,900)
	G := Gdip_GraphicsFromImage(pBitmap)
	Gdip_SetSmoothingMode(G, 4)
	Brush1 := Gdip_BrushCreateSolid("0xFFFF00FF")
	Gdip_FillRectangle(G, Brush1, 0, 0, 900, 450)
	Gdip_DeleteBrush(Brush1)
	Brush2 := Gdip_BrushCreateSolid("0xFF00FF00")
	Gdip_FillRectangle(G, Brush2, 0, 450, 900, 450)
	Gdip_DeleteBrush(Brush2)
	hBitmap := Gdip_CreatehBitmapFromBitmap(pBitmap)
	return hBitmap
	}

HTML()
	{
	HTML_page =
	(
	<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'/>
	<style>body {font-family: sans-serif; background-color: yellow}</style></head>
	<body><h1>Hello World</h1></body>
	</html>
	)
	return HTML_page
	}
(I handpicked the colors ;))
Last edited by flyingDman on 09 Jan 2023, 11:10, edited 1 time in total.
14.3 & 1.3.7
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

Re: GDIP+ and ActiveX HTML

09 Jan 2023, 10:33

@flyingDman

Hello, thanks for your response. I tried something similar, but just as with your sample, only returns numbers.

If I want to edit the BG_Art bitmap later and add text on top of it, and continuously update it
how would you do that using Gdip_TextToGraphics.

I've tried this code, but to no avail:

Code: Select all

       Options = x10 y30 w500 h500 Centre cbbffffff r4 s20
        pToken := Gdip_Startup()

        G := Gdip_TextToGraphics(pBitmap)
	Gdip_SetSmoothingMode(G, 4)       

        Gdip_TextToGraphics(G, "Game Over. Thank you for Participating in Street Fighter V.", Options, Font, 980, 640)
        UpdateLayeredWindow(hwnd1, hdc, 12, 12, 980, 640)


Thanks for your time, man.
User avatar
flyingDman
Posts: 2832
Joined: 29 Sep 2013, 19:01

Re: GDIP+ and ActiveX HTML

09 Jan 2023, 13:06

Galaxis wrote:
09 Jan 2023, 10:33
only returns numbers.
What do you mean?
14.3 & 1.3.7
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

Re: GDIP+ and ActiveX HTML

09 Jan 2023, 14:46

The whole intent is to update the Superman text information in real-time. But I am unable to do so after the window is drawn. And there is too much flickering when using GuiControl updates, which is why I resorted to ActiveX. Still, ActiveX text is always overlapped by GDIP shapes/colors after window is drawn, which is why I want to access it again, directly and draw text on it via Gdip_TextToGraphics. Returning numbers is verification that the bitmap exists, and that the pointer is valid... But doesn't behave as it should when the intent is to draw that image to canvas.
Last edited by Galaxis on 10 Jan 2023, 19:04, edited 4 times in total.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GDIP+ and ActiveX HTML

10 Jan 2023, 00:25

This is a variation of @flyingDman code.

Code: Select all

;**********************************************************************************************
#Include <Gdip_all> ;<<<<<<<<<<<<<<<<<<---------------------------     gdip.ahk
;**********************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
Gdip_Startup()

Gui, margin, 0,0
Gui, Add, ActiveX, x250 y250 w400 h400 vWB1, HTMLfile
WB1.write(HTML())
w := 900 , h := 900
Gui, Add, Pic, x0 y0 w%w% h%h% hwndPicHwnd 0xE +0x4000000
BG_ART( PicHwnd , w , h )
Gui, show

SetTimer, Change , 1000

return
GuiClose:
GuiContextMenu:
*ESC::ExitApp

Change:
	BG_ART( PicHwnd , w , h )
	return 
	
	
BG_ART( hwnd , w := 900 , h := 900 ){
	static tog , index := 0
	tog := !tog
	pBitmap := Gdip_CreateBitmap(w ,h)
	G := Gdip_GraphicsFromImage(pBitmap)
	Gdip_SetSmoothingMode(G, 4)
	Brush1 := Gdip_BrushCreateSolid( ( tog ) ? ( "0x99FF00FF" ) : ( "0x9900FF00" ) )
	Gdip_FillRectangle(G, Brush1, 0, 0, 900, 450)
	Gdip_DeleteBrush( Brush1 )
	Brush2 := Gdip_BrushCreateSolid( ( tog ) ? ( "0x9900FF00" ) : ( "0x99FF00FF" ) )
	Gdip_FillRectangle(G, Brush2, 0, 450, 900, 450)
	Gdip_DeleteBrush( Brush2 )
	;____________________________________________________________________________
	;Text
	DrawText( G , 11 , 11 , ++index ,  "0xFF000000" , 300 , 150 , options := " Center vCenter Bold s132 " , type := "comic Sans MS" )
	DrawText( G , 10 , 10 , index ,  "0xFFFFFFFF" , 300 , 150 , options := " Center vCenter Bold s132 " , type := "comic Sans MS" )
	;____________________________________________________________________________
	;Display Image and Cleanup
	Gdip_DeleteGraphics( G )
	hBitmap := Gdip_CreatehBitmapFromBitmap( pBitmap )
	Gdip_DisposeImage( pBitmap )
	SetImage( hwnd , hBitmap )
	DeleteObject( hBitmap )
}

HTML(){
	HTML_page =
	(
	<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'/>
	<style>body {font-family: sans-serif; background-color: yellow}</style></head>
	<body><h1>Hello World</h1></body>
	</html>
	)
	return HTML_page
}

DrawText( G , x , y , text ,  color , width , height , options := " Center vCenter Bold s12 " , type := "comic Sans MS" ){
	Brush := Gdip_BrushCreateSolid( color ) , Gdip_TextToGraphics( G , text , options " c" brush " x" x " y" y  , type , width , height ) , Gdip_DeleteBrush( Brush )
}
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GDIP+ and ActiveX HTML  Topic is solved

10 Jan 2023, 01:31

Here is how you would go about adding your other controls.

Code: Select all

;****************************************************************************************************************************************************************************
#Include <GDIP_All> ;<<<<<<<<<<<<<<<<<<---------------------------     gdip.ahk
;~ #Include <Gen 3 Buttons> ;***At The Bottom Of The Script*** - https://www.autohotkey.com/boards/viewtopic.php?f=6&t=88153&p=395985
;****************************************************************************************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
Gdip_Startup()

Gui, margin, 0,0
Gui, Add, ActiveX, x250 y250 w400 h400 vWB1, HTMLfile
WB1.write(HTML())
w := 900 , h := 900

;____________________________________________________________________________
;Custom Buttons / Controls. ~~~ Replace these controls with your other controls

Gui, Font, s16
Gui, Add, DDL, x260 y670 w380 r10 , Item||Item|Item|Item|Item|Item|Item|Item|Item|Item|Item|Item|
Gui, Add, CheckBox, x260 y+20, Check

Theme1 := HBCustomButton()
GuiButtonType1.SetSessionDefaults( Theme1.All , Theme1.Default , Theme1.Hover , Theme1.Pressed )

BackButton := New HButton( { Owner: 1 , X: x := 260 , Y: 250 + 400 + 10 + 100 , W: 120 , H: 55 , Text: "Back" , Label: "TestFunction" } , { BackgroundColor: "0xFFF0F0F0" } )
CancelButton := New HButton( { Owner: 1 , X: x += 130 , Y: 250 + 400 + 10 + 100 , W: 120 , H: 55 , Text: "Cancel" , Label: "TestFunction" } , { BackgroundColor: "0xFFF0F0F0" } )
OkButton := New HButton( { Owner: 1 , X: x += 130 , Y: 250 + 400 + 10 + 100 , W: 120 , H: 55 , Text: "OK" , Label: "TestFunction" } , { BackgroundColor: "0xFFF0F0F0" } )

;____________________________________________________________________________
;Add BG Pic Control ( +0x4000000 = Cut a hole for the controls added before this control )

Gui, Add, Pic, x0 y0 w%w% h%h% hwndPicHwnd 0xE +0x4000000
BG_ART( PicHwnd , w , h )
Gui, show, w%w% h%h%

SetTimer, Change , 1000

return
GuiClose:
GuiContextMenu:
*ESC::ExitApp

Change:
	BG_ART( PicHwnd , w , h )
	return 

;Button press
TestFunction:
	SoundBeep
	return

	
BG_ART( hwnd , w := 900 , h := 900 ){
	static tog , index := 0
	tog := !tog
	pBitmap := Gdip_CreateBitmap( w , h )
	G := Gdip_GraphicsFromImage(pBitmap)
	Gdip_SetSmoothingMode(G, 4)
	Brush1 := Gdip_BrushCreateSolid( ( tog ) ? ( "0x99cc00cc" ) : ( "0x99aa00aa" ) )
	Gdip_FillRectangle(G, Brush1, 0, 0, 900, 450)
	Gdip_DeleteBrush( Brush1 )
	Brush2 := Gdip_BrushCreateSolid( ( tog ) ? ( "0x9900cc00" ) : ( "0x9900aa00" ) )
	Gdip_FillRectangle(G, Brush2, 0, 450, 900, 450)
	Gdip_DeleteBrush( Brush2 )
	Brush3 := Gdip_BrushCreateSolid( "0xFFF0F0F0" )
	Gdip_FillRoundedRectangle( G, Brush3, 250 , 250 + 400 + 5 , 400 , 165 , 10 )
	;~ Gdip_FillRectangle(G, Brush3, 250 , 250 + 400 + 5 , 400 , 65 )
	Gdip_DeleteBrush( Brush3 )
	;____________________________________________________________________________
	;Text
	DrawText( G , 11 , 11 , ++index ,  "0xFF000000" , 300 , 150 , options := " Center vCenter Bold s132 " , type := "comic Sans MS" )
	DrawText( G , 10 , 10 , index ,  "0xFFFFFFFF" , 300 , 150 , options := " Center vCenter Bold s132 " , type := "comic Sans MS" )
	;____________________________________________________________________________
	;Display Image and Cleanup
	Gdip_DeleteGraphics( G )
	hBitmap := Gdip_CreatehBitmapFromBitmap( pBitmap )
	Gdip_DisposeImage( pBitmap )
	SetImage( hwnd , hBitmap )
	DeleteObject( hBitmap )
}

HTML(){
	HTML_page =
	(
	<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'/>
	<style>body {font-family: sans-serif; background-color: yellow}</style></head>
	<body><h1>Hello World</h1></body>
	</html>
	)
	return HTML_page
}

DrawText( G , x , y , text ,  color , width , height , options := " Center vCenter Bold s12 " , type := "comic Sans MS" ){
	Brush := Gdip_BrushCreateSolid( color ) , Gdip_TextToGraphics( G , text , options " c" brush " x" x " y" y  , type , width , height ) , Gdip_DeleteBrush( Brush )
}



HBCustomButton(){
	local MyButtonDesign := {}
	MyButtonDesign.All := {}
	MyButtonDesign.Default := {}
	MyButtonDesign.Hover := {}
	MyButtonDesign.Pressed := {}
	;********************************
	;All
	MyButtonDesign.All.W := 100 , MyButtonDesign.All.H := 40 , MyButtonDesign.All.Text := "Go" , MyButtonDesign.All.BackgroundColor := "0xFFffffff" , MyButtonDesign.All.ButtonAddGlossy := "0"
	;********************************
	;Default
	MyButtonDesign.Default.W := 100 , MyButtonDesign.Default.H := 40 , MyButtonDesign.Default.Text := "Go" , MyButtonDesign.Default.Font := "Arial" , MyButtonDesign.Default.FontOptions := " Bold Center vCenter " , MyButtonDesign.Default.FontSize := "12" , MyButtonDesign.Default.H := "0x0002112F" , MyButtonDesign.Default.TextBottomColor2 := "0x0002112F" , MyButtonDesign.Default.TextTopColor1 := "0xFF32363a" , MyButtonDesign.Default.TextTopColor2 := "0xFFFFFFFF" , MyButtonDesign.Default.TextOffsetX := "0" , MyButtonDesign.Default.TextOffsetY := "0" , MyButtonDesign.Default.TextOffsetW := "0" , MyButtonDesign.Default.TextOffsetH := "0" , MyButtonDesign.Default.BackgroundColor := "0xFFffffff" , MyButtonDesign.Default.ButtonOuterBorderColor := "0xFFc2c6ca" , MyButtonDesign.Default.ButtonCenterBorderColor := "0xFF72767a" , MyButtonDesign.Default.ButtonInnerBorderColor1 := "0xFFFFFFFF" , MyButtonDesign.Default.ButtonInnerBorderColor2 := "0xFFF0F0F0" , MyButtonDesign.Default.ButtonMainColor1 := "0xFFffffff" , MyButtonDesign.Default.ButtonMainColor2 := "0xFFc2c6ca" , MyButtonDesign.Default.ButtonAddGlossy := "0" , MyButtonDesign.Default.GlossTopColor := "0x11FFFFFF" , MyButtonDesign.Default.GlossTopAccentColor := "05FFFFFF" , MyButtonDesign.Default.GlossBottomColor := "33000000"
	;********************************
	;Hover
	MyButtonDesign.Hover.W := 100 , MyButtonDesign.Hover.H := 40 , MyButtonDesign.Hover.Text := "Go" , MyButtonDesign.Hover.Font := "Arial" , MyButtonDesign.Hover.FontOptions := " Bold Center vCenter " , MyButtonDesign.Hover.FontSize := "12" , MyButtonDesign.Hover.H := "0x0002112F" , MyButtonDesign.Hover.TextBottomColor2 := "0x0002112F" , MyButtonDesign.Hover.TextTopColor1 := "0xFF22262a" , MyButtonDesign.Hover.TextTopColor2 := "0xFFFFFFFF" , MyButtonDesign.Hover.TextOffsetX := "0" , MyButtonDesign.Hover.TextOffsetY := "0" , MyButtonDesign.Hover.TextOffsetW := "0" , MyButtonDesign.Hover.TextOffsetH := "0" , MyButtonDesign.Hover.BackgroundColor := "0xFFffffff" , MyButtonDesign.Hover.ButtonOuterBorderColor := "0xFF92969a" , MyButtonDesign.Hover.ButtonCenterBorderColor := "0xFFa2a6aa" , MyButtonDesign.Hover.ButtonInnerBorderColor1 := "0xFF5FE1C8" , MyButtonDesign.Hover.ButtonInnerBorderColor2 := "0xFF166BFF" , MyButtonDesign.Hover.ButtonMainColor1 := "0xFFFFFFFF" , MyButtonDesign.Hover.ButtonMainColor2 := "0x9942E5EC" , MyButtonDesign.Hover.ButtonAddGlossy := "0" , MyButtonDesign.Hover.GlossTopColor := "0x11FFFFFF" , MyButtonDesign.Hover.GlossTopAccentColor := "05FFFFFF" , MyButtonDesign.Hover.GlossBottomColor := "33000000"
	;********************************
	;Pressed
	MyButtonDesign.Pressed.W := 100 , MyButtonDesign.Pressed.H := 40 , MyButtonDesign.Pressed.Text := "Go" , MyButtonDesign.Pressed.Font := "Arial" , MyButtonDesign.Pressed.FontOptions := " Bold Center vCenter " , MyButtonDesign.Pressed.FontSize := "12" , MyButtonDesign.Pressed.H := "0x0002112F" , MyButtonDesign.Pressed.TextBottomColor2 := "0x0002112F" , MyButtonDesign.Pressed.TextTopColor1 := "0xFFFFFFFF" , MyButtonDesign.Pressed.TextTopColor2 := "0xFFFFFFFF" , MyButtonDesign.Pressed.TextOffsetX := "0" , MyButtonDesign.Pressed.TextOffsetY := "0" , MyButtonDesign.Pressed.TextOffsetW := "0" , MyButtonDesign.Pressed.TextOffsetH := "0" , MyButtonDesign.Pressed.BackgroundColor := "0xFFffffff" , MyButtonDesign.Pressed.ButtonOuterBorderColor := "0xFFf0f0f0" , MyButtonDesign.Pressed.ButtonCenterBorderColor := "0xFFa2a6aa" , MyButtonDesign.Pressed.ButtonInnerBorderColor1 := "0xFF0488E6" , MyButtonDesign.Pressed.ButtonInnerBorderColor2 := "0xFFF0F0F0" , MyButtonDesign.Pressed.ButtonMainColor1 := "0xFF42E5EC" , MyButtonDesign.Pressed.ButtonMainColor2 := "0xFFa2a6aa" , MyButtonDesign.Pressed.ButtonAddGlossy := "0" , MyButtonDesign.Pressed.GlossTopColor := "0x11FFFFFF" , MyButtonDesign.Pressed.GlossTopAccentColor := "05FFFFFF" , MyButtonDesign.Pressed.GlossBottomColor := "33000000"
	;********************************
	
	return MyButtonDesign
}


;  | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) | ((( For Demo ))) |
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
Class HButton	{
	;Gen 3 Button Class By Hellbent
	static init , Button := [] , Active , LastControl , HoldCtrl 
	
	__New( Input := "" , All := "" , Default := "" , Hover := "" , Pressed := "" ){
		
		local hwnd 
		
			;If this is the first time the class is being used.
		if( !HButton.init && HButton.init := 1 )
			
				;Set a timer to watch to see if the cursor goes over one of the controls.
			HButton._SetHoverTimer()
			
		This._CreateNewButtonObject( hwnd := This._CreateControl( Input ) , Input )
		
		This._BindButton( hwnd , Input )
		
		This._GetButtonBitmaps( hwnd , Input , All , Default , Hover , Pressed )
		
		This._DisplayButton( hwnd , HButton.Button[hwnd].Bitmaps.Default.hBitmap )
		
		return hwnd
	}

	_DisplayButton( hwnd , hBitmap){
		
		SetImage( hwnd , hBitmap )
		
	}
	
	_GetButtonBitmaps( hwnd , Input := "" , All := "" , Default := "" , Hover := "" , Pressed := "" ){
	
		HButton.Button[hwnd].Bitmaps := GuiButtonType1.CreateButtonBitmapSet( Input , All , Default , Hover , Pressed )
		
	}
	
	_CreateNewButtonObject( hwnd , Input ){
		
		local k , v  
		
		HButton.Button[ hwnd ] := {}
		
		for k , v in Input
			
			HButton.Button[ hwnd ][ k ] := v
		
		HButton.Button[ hwnd ].Hwnd := hwnd
		
	}
	
	_CreateControl( Input ){
		
		local hwnd
		
		Gui , % Input.Owner ":Add" , Pic , % "x" Input.X " y" Input.Y " w" Input.W " h" Input.H " hwndhwnd 0xE"  
		
		return hwnd
		
	}
	
	_BindButton( hwnd , Input ){
		
		local bd
		
		bd := This._OnClick.Bind( This )
		
		GuiControl, % Input.Owner ":+G" , % hwnd , % bd
		
	}
	
	_SetHoverTimer( timer := "" ){
		
		local HoverTimer 

		if( !HButton.HoverTimer ) 
			
			HButton.HoverTimer := ObjBindMethod( HButton , "_OnHover" ) 
		
		HoverTimer := HButton.HoverTimer
		
		SetTimer , % HoverTimer , % ( Timer ) ? ( Timer ) : ( 100 )
		
	}
	
	_OnHover(){
		
		local Ctrl
		
		MouseGetPos,,,,ctrl,2
		
		if( HButton.Button[ ctrl ] && !HButton.Active ){
			
			HButton.Active := 1
			
			HButton.LastControl := ctrl
			
			HButton._DisplayButton( ctrl , HButton.Button[ ctrl ].Bitmaps.Hover.hBitmap )
			
		}else if( HButton.Active && ctrl != HButton.LastControl ){
			
			HButton.Active := 0
			
			HButton._DisplayButton( HButton.LastControl , HButton.Button[ HButton.LastControl ].Bitmaps.Default.hBitmap )

		}
		
	}
	
	_OnClick(){
		
		local Ctrl, last
		
		HButton._SetHoverTimer( "Off" )
		
		MouseGetPos,,,, Ctrl , 2
		last := ctrl
		HButton._SetFocus( ctrl )
		HButton._DisplayButton( last , HButton.Button[ last ].Bitmaps.Pressed.hBitmap )
		
		While(GetKeyState("LButton"))
			sleep, 60
		
		HButton._SetHoverTimer()
		
		loop, 2
			This._OnHover()
		
		MouseGetPos,,,, Ctrl , 2
		
		if(ctrl!=last){
			
			HButton._DisplayButton( last , HButton.Button[ last ].Bitmaps.Default.hBitmap )
		
		}else{
			HButton._DisplayButton( last , HButton.Button[ last ].Bitmaps.Hover.hBitmap )
			if( HButton.Button[ last ].Label ){
			
			if(IsFunc( HButton.Button[ last ].Label ) )
				
				fn := Func( HButton.Button[ last ].Label )
				, fn.Call()
				
			else 
				
				gosub, % HButton.Button[ last ].Label
			}
		
		}
		
	}
	
	_SetFocus( ctrl ){
		
		GuiControl, % HButton.Button[ ctrl ].Owner ":Focus" , % ctrl
		
	}
	
	DeleteButton( hwnd ){
		
		for k , v in HButton.Button[ hwnd ].Bitmaps
				Gdip_DisposeImage( HButton.Button[hwnd].Bitmaps[k].pBitmap )
				, DeleteObject( HButton.Button[ hwnd ].Bitmaps[k].hBitmap )
				
		GuiControl , % HButton.Button[ hwnd ].Owner ":Move", % hwnd , % "x-1 y-1 w0 h0" 
		HButton.Button[ hwnd ] := ""
	}
	
}
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
Class GuiButtonType1	{

	static List := [ "Default" , "Hover" , "Pressed" ]
	
	_CreatePressedBitmap(){
		
		local arr := [] , Bitmap := {} , fObj := This.CurrentBitmapData.Pressed
		
		Bitmap.pBitmap := Gdip_CreateBitmap( fObj.W , fObj.H ) , G := Gdip_GraphicsFromImage( Bitmap.pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
		
		Brush := Gdip_BrushCreateSolid( fObj.BackgroundColor ) , Gdip_FillRectangle( G , Brush , -1 , -1 , fObj.W+2 , fObj.H+2 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_BrushCreateSolid( fObj.ButtonOuterBorderColor ) , Gdip_FillRoundedRectangle( G , Brush , 3 , 4 , fObj.W-7 , fObj.H-7 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , fObj.W , fObj.H , fObj.ButtonInnerBorderColor1 , fObj.ButtonInnerBorderColor2 , 1 , 1 ) , Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , fObj.W-5 , fObj.H-8 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , fObj.W-7 , fObj.H-10 , fObj.ButtonMainColor1 , fObj.ButtonMainColor2 , 1 , 1 ) , Gdip_FillRoundedRectangle( G , Brush , 5 , 5 , fObj.W-11 , fObj.H-12 , 5 ) , Gdip_DeleteBrush( Brush )
			
		Brush := Gdip_CreateLineBrushFromRect( 0 , 2 , fObj.W , fObj.H , fObj.TextBottomColor1 , fObj.TextBottomColor2 , 1 , 1 )
		
		arr := [ { X: -1 , Y: -1 } , { X: 0 , Y: -1 } , { X: 1 , Y: -1 } , { X: -1 , Y: 0 } , { X: 1 , Y: 0 } , { X: -1 , Y: 1 } , { X: 0 , Y: 1 } , { X: 1 , Y: 1 } ]
		
		Loop, % 8
			
			Gdip_TextToGraphics( G , fObj.Text , "s" fObj.FontSize " " fObj.FontOptions " c" Brush " x" 1 + arr[A_Index].X + fObj.TextOffsetX " y" 3 + arr[A_Index].Y + fObj.TextOffsetY , fObj.Font , fObj.W + fObj.TextOffsetW , fObj.H + fObj.TextOffsetH )
	
		Brush := Gdip_CreateLineBrushFromRect( 0 , 2 , fObj.W , fObj.H , fObj.TextTopColor1 , fObj.TextTopColor2 , 1 , 1 )
		
		Gdip_TextToGraphics( G , fObj.Text , "s" fObj.FontSize " " fObj.FontOptions " c" Brush " x" 1 + fObj.TextOffsetX " y" 3 + fObj.TextOffsetY , fObj.Font , fObj.W + fObj.TextOffsetW , fObj.H + fObj.TextOffsetH )
	
	if( fObj.ButtonAddGlossy ){
		
		Brush := Gdip_BrushCreateSolid( fObj.GlossTopColor ) , Gdip_FillRectangle( G , Brush , 5 , 10 , fObj.W-11 , ( fObj.H / 2 ) - 10   ) , Gdip_DeleteBrush( Brush )

		Brush := Gdip_BrushCreateSolid( fObj.GlossTopAccentColor ) , Gdip_FillRectangle( G , Brush , 10 , 12 , fObj.W-21 , fObj.H / 15 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_BrushCreateSolid( fObj.GlossBottomColor ) , Gdip_FillRectangle( G , Brush , 5  , 10 + ( fObj.H / 2 ) - 10 , fObj.W-11 , ( fObj.H / 2 ) - 7 ) , Gdip_DeleteBrush( Brush )
				
	}

		Gdip_DeleteGraphics( G )
		
		Bitmap.hBitmap := Gdip_CreateHBITMAPFromBitmap( Bitmap.pBitmap )
		
		return Bitmap
	}
	
	_CreateHoverBitmap(){
		
		local arr := [] , Bitmap := {} , fObj := This.CurrentBitmapData.Hover
		
		Bitmap.pBitmap := Gdip_CreateBitmap( fObj.W , fObj.H ) , G := Gdip_GraphicsFromImage( Bitmap.pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
		
		Brush := Gdip_BrushCreateSolid( fObj.BackgroundColor ) , Gdip_FillRectangle( G , Brush , -1 , -1 , fObj.W+2 , fObj.H+2 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_BrushCreateSolid( fObj.ButtonOuterBorderColor ) , Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , fObj.W-5 , fObj.H-7 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_BrushCreateSolid( fObj.ButtonCenterBorderColor ) , Gdip_FillRoundedRectangle( G , Brush , 3 , 4 , fObj.W-7 , fObj.H-9 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , fObj.W , fObj.H-10 , fObj.ButtonInnerBorderColor1 , fObj.ButtonInnerBorderColor2 , 1 , 1 ) , Gdip_FillRoundedRectangle( G , Brush , 4 , 5 , fObj.W-9 , fObj.H-11 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_CreateLineBrushFromRect( 5 , 7 , fObj.W-11 , fObj.H-14 , fObj.ButtonMainColor1 , fObj.ButtonMainColor2 , 1 , 1 ) , Gdip_FillRoundedRectangle( G , Brush , 5 , 7 , fObj.W-11 , fObj.H-14 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_CreateLineBrushFromRect( 0 , 2 , fObj.W , fObj.H , fObj.TextBottomColor1 , fObj.TextBottomColor2 , 1 , 1 )
		
		arr := [ { X: -1 , Y: -1 } , { X: 0 , Y: -1 } , { X: 1 , Y: -1 } , { X: -1 , Y: 0 } , { X: 1 , Y: 0 } , { X: -1 , Y: 1 } , { X: 0 , Y: 1 } , { X: 1 , Y: 1 } ]
		
		Loop, % 8
			
			Gdip_TextToGraphics( G , fObj.Text , "s" fObj.FontSize " " fObj.FontOptions " c" Brush " x" 0 + arr[A_Index].X + fObj.TextOffsetX " y" 2 + arr[A_Index].Y + fObj.TextOffsetY , fObj.Font , fObj.W + fObj.TextOffsetW , fObj.H + fObj.TextOffsetH )
	
		Brush := Gdip_CreateLineBrushFromRect( 0 , 2 , fObj.W , fObj.H , fObj.TextTopColor1 , fObj.TextTopColor2 , 1 , 1 )
		
		Gdip_TextToGraphics( G , fObj.Text , "s" fObj.FontSize " " fObj.FontOptions " c" Brush " x" 0 + fObj.TextOffsetX " y" 2 + fObj.TextOffsetY , fObj.Font , fObj.W + fObj.TextOffsetW , fObj.H + fObj.TextOffsetH )
	
		if( fObj.ButtonAddGlossy = 1 ){
			
			Brush := Gdip_BrushCreateSolid( fObj.GlossTopColor ) , Gdip_FillRectangle( G , Brush , 6 , 10 , fObj.W-13 , ( fObj.H / 2 ) - 10   ) , Gdip_DeleteBrush( Brush )
			
			Brush := Gdip_BrushCreateSolid( fObj.GlossTopAccentColor ) , Gdip_FillRectangle( G , Brush , 10 , 12 , fObj.W-21 , fObj.H / 15 ) , Gdip_DeleteBrush( Brush )
			
			Brush := Gdip_BrushCreateSolid( fObj.GlossBottomColor ) , Gdip_FillRectangle( G , Brush , 6  , 10 + ( fObj.H / 2 ) - 10 , fObj.W-13 , ( fObj.H / 2 ) - 7 ) , Gdip_DeleteBrush( Brush )
					
		}
	
		Gdip_DeleteGraphics( G )
		
		Bitmap.hBitmap := Gdip_CreateHBITMAPFromBitmap( Bitmap.pBitmap )
		
		return Bitmap
		
	}
	
	_CreateDefaultBitmap(){
		
		local arr := [] , Bitmap := {} , fObj := This.CurrentBitmapData.Default
		
		Bitmap.pBitmap := Gdip_CreateBitmap( fObj.W , fObj.H ) , G := Gdip_GraphicsFromImage( Bitmap.pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
	
		Brush := Gdip_BrushCreateSolid( fObj.BackgroundColor ) , Gdip_FillRectangle( G , Brush , -1 , -1 , fObj.W+2 , fObj.H+2 ) , Gdip_DeleteBrush( Brush )
	
		Brush := Gdip_BrushCreateSolid( fObj.ButtonOuterBorderColor ) , Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , fObj.W-5 , fObj.H-7 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_BrushCreateSolid( fObj.ButtonCenterBorderColor ) , Gdip_FillRoundedRectangle( G , Brush , 3 , 4 , fObj.W-7 , fObj.H-9 , 5 ) , Gdip_DeleteBrush( Brush )
	
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , fObj.W , fObj.H-10 , fObj.ButtonInnerBorderColor1 , fObj.ButtonInnerBorderColor2 , 1 , 1 ) , Gdip_FillRoundedRectangle( G , Brush , 4 , 5 , fObj.W-9 , fObj.H-11 , 5 ) , Gdip_DeleteBrush( Brush )
	
		Brush := Gdip_CreateLineBrushFromRect( 5 , 7 , fObj.W-11 , fObj.H-14 , fObj.ButtonMainColor1 , fObj.ButtonMainColor2 , 1 , 1 ) , Gdip_FillRoundedRectangle( G , Brush , 5 , 7 , fObj.W-11 , fObj.H-14 , 5 ) , Gdip_DeleteBrush( Brush )
		
		Brush := Gdip_CreateLineBrushFromRect( 0 , 2 , fObj.W , fObj.H , fObj.TextBottomColor1 , fObj.TextBottomColor2 , 1 , 1 )
		
		arr := [ { X: -1 , Y: -1 } , { X: 0 , Y: -1 } , { X: 1 , Y: -1 } , { X: -1 , Y: 0 } , { X: 1 , Y: 0 } , { X: -1 , Y: 1 } , { X: 0 , Y: 1 } , { X: 1 , Y: 1 } ]
		
		Loop, % 8
			
			Gdip_TextToGraphics( G , fObj.Text , "s" fObj.FontSize " " fObj.FontOptions " c" Brush " x" 0 + arr[A_Index].X + fObj.TextOffsetX " y" 2 + arr[A_Index].Y + fObj.TextOffsetY , fObj.Font , fObj.W + fObj.TextOffsetW , fObj.H + fObj.TextOffsetH )
	
		Brush := Gdip_CreateLineBrushFromRect( 0 , 2 , fObj.W , fObj.H , fObj.TextTopColor1 , fObj.TextTopColor2 , 1 , 1 )
		
		Gdip_TextToGraphics( G , fObj.Text , "s" fObj.FontSize " " fObj.FontOptions " c" Brush " x" 0 + fObj.TextOffsetX " y" 2 + fObj.TextOffsetY , fObj.Font , fObj.W + fObj.TextOffsetW , fObj.H + fObj.TextOffsetH )
	
		if( fObj.ButtonAddGlossy ){
		
			Brush := Gdip_BrushCreateSolid( fObj.GlossTopColor ) , Gdip_FillRectangle( G , Brush , 6 , 10 , fObj.W-13 , ( fObj.H / 2 ) - 10   ) , Gdip_DeleteBrush( Brush )
			
			Brush := Gdip_BrushCreateSolid( fObj.GlossTopAccentColor ) , Gdip_FillRectangle( G , Brush , 10 , 12 , fObj.W-21 , fObj.H / 15 ) , Gdip_DeleteBrush( Brush )
			
			Brush := Gdip_BrushCreateSolid( fObj.GlossBottomColor ) , Gdip_FillRectangle( G , Brush , 6  , 10 + ( fObj.H / 2 ) - 10 , fObj.W-13 , ( fObj.H / 2 ) - 7 ) , Gdip_DeleteBrush( Brush )
				
		}
	
		Gdip_DeleteGraphics( G )
		
		Bitmap.hBitmap := Gdip_CreateHBITMAPFromBitmap( Bitmap.pBitmap )
		
		return Bitmap
		
	}
	
	_GetMasterDefaultValues(){ ;Default State
		
		local Default := {}
		
		Default.pBitmap := "" 
		, Default.hBitmap := ""
		, Default.Font := "Arial"
		, Default.FontOptions := " Bold Center vCenter "
		, Default.FontSize := "12"
		, Default.Text := "Button"
		, Default.W := 10
		, Default.H := 10
		, Default.TextBottomColor1 := "0x0002112F"
		, Default.TextBottomColor2 := Default.TextBottomColor1
		, Default.TextTopColor1 := "0xFFFFFFFF"
		, Default.TextTopColor2 := "0xFF000000"
		, Default.TextOffsetX := 0
		, Default.TextOffsetY := 0
		, Default.TextOffsetW := 0
		, Default.TextOffsetH := 0
		, Default.BackgroundColor := "0xFF22262A"
		, Default.ButtonOuterBorderColor := "0xFF161B1F"	
		, Default.ButtonCenterBorderColor := "0xFF262B2F"	
		, Default.ButtonInnerBorderColor1 := "0xFF3F444A"
		, Default.ButtonInnerBorderColor2 := "0xFF24292D"
		, Default.ButtonMainColor1 := "0xFF272C32"
		, Default.ButtonMainColor2 := "" Default.ButtonMainColor1
		, Default.ButtonAddGlossy := 0
		, Default.GlossTopColor := "0x11FFFFFF"
		, Default.GlossTopAccentColor := "0x05FFFFFF"	
		, Default.GlossBottomColor := "0x33000000"
		
		return Default
		
	}
	
	_GetMasterHoverValues(){ ;Hover State
		
		local Default := {}
		
		Default.pBitmap := ""
		, Default.hBitmap := ""
		, Default.Font := "Arial"
		, Default.FontOptions := " Bold Center vCenter "
		, Default.FontSize := "12"
		, Default.Text := "Button"
		, Default.W := 10
		, Default.H := 10
		, Default.TextBottomColor1 := "0x0002112F"
		, Default.TextBottomColor2 := Default.TextBottomColor1
		, Default.TextTopColor1 := "0xFFFFFFFF"
		, Default.TextTopColor2 := "0xFF000000"
		, Default.TextOffsetX := 0
		, Default.TextOffsetY := 0
		, Default.TextOffsetW := 0
		, Default.TextOffsetH := 0
		, Default.BackgroundColor := "0xFF22262A"
		, Default.ButtonOuterBorderColor := "0xFF161B1F"	
		, Default.ButtonCenterBorderColor := "0xFF262B2F"	
		, Default.ButtonInnerBorderColor1 := "0xFF3F444A"
		, Default.ButtonInnerBorderColor2 := "0xFF24292D"
		, Default.ButtonMainColor1 := "0xFF373C42"
		, Default.ButtonMainColor2 := "" Default.ButtonMainColor1
		, Default.ButtonAddGlossy := 0
		, Default.GlossTopColor := "0x11FFFFFF"
		, Default.GlossTopAccentColor := "0x05FFFFFF"	
		, Default.GlossBottomColor := "0x33000000"
		
		return Default
		
	}
	
	_GetMasterPressedValues(){ ;Pressed State
		
		local Default := {}
		
		Default.pBitmap := ""
		, Default.hBitmap := ""
		, Default.Font := "Arial"
		, Default.FontOptions := " Bold Center vCenter "
		, Default.FontSize := "12"
		, Default.Text := "Button"
		, Default.W := 10
		, Default.H := 10
		, Default.TextBottomColor1 := "0x0002112F"
		, Default.TextBottomColor2 := Default.TextBottomColor1
		, Default.TextTopColor1 := "0xFFFFFFFF"
		, Default.TextTopColor2 := "0xFF000000"
		, Default.TextOffsetX := 0
		, Default.TextOffsetY := 0
		, Default.TextOffsetW := 0
		, Default.TextOffsetH := 0
		, Default.BackgroundColor := "0xFF22262A"
		, Default.ButtonOuterBorderColor := "0xFF62666a"
		, Default.ButtonCenterBorderColor := "0xFF262B2F"	
		, Default.ButtonInnerBorderColor1 := "0xFF151A20"
		, Default.ButtonInnerBorderColor2 := "0xFF151A20"
		, Default.ButtonMainColor1 := "0xFF12161a"
		, Default.ButtonMainColor2 := "0xFF33383E"
		, Default.ButtonAddGlossy := 0
		, Default.GlossTopColor := "0x11FFFFFF"
		, Default.GlossTopAccentColor := "0x05FFFFFF"	
		, Default.GlossBottomColor := "0x33000000"
	
		return Default
		
	}
	
	SetSessionDefaults( All := "" , Default := "" , Hover := "" , Pressed := "" ){ ;Set the default values based on user input
		
		This.SessionBitmapData := {} 
		, This.Preset := 1
		, This.init := 0
		
		This._LoadDefaults("SessionBitmapData")
		
		This._SetSessionData( All , Default , Hover , Pressed )
		
	}
	
	_SetSessionData( All := "" , Default := "" , Hover := "" , Pressed := "" ){
		
		local index , k , v , i , j
	
		if( IsObject( All ) ){
			
			Loop, % GuiButtonType1.List.Length()	{
				index := A_Index
				For k , v in All
					This.SessionBitmapData[ GuiButtonType1.List[ index ] ][ k ] := v
			}
		}
		
		For k , v in GuiButtonType1.List
			if( isObject( %v% ) )
				For i , j in %v%
					This.SessionBitmapData[ GuiButtonType1.List[ k ] ][ i ] := j
				
	}
	
	_LoadDefaults( input := "" ){
		
		This.CurrentBitmapData := "" , This.CurrentBitmapData := {}
			
		For k , v in This.SessionBitmapData
			This.CurrentBitmapData[k] := {}
		
		This[ input ].Default := This._GetMasterDefaultValues()
		, This[ input ].Hover := This._GetMasterHoverValues()
		, This[ input ].Pressed := This._GetMasterPressedValues()
		
	}
	
	_SetCurrentBitmapDataFromSessionData(){
		
		local k , v , i , j
			
		This.CurrentBitmapData := "" , This.CurrentBitmapData := {}
			
		For k , v in This.SessionBitmapData
		{
			This.CurrentBitmapData[k] := {}
			
			For i , j in This.SessionBitmapData[k]
				
				This.CurrentBitmapData[k][i] := j

		}
		
	}
	
	_UpdateCurrentBitmapData( All := "" , Default := "" , Hover := "" , Pressed := "" ){
		
		local k , v , i , j
		
		if( IsObject( All ) ){
			
			Loop, % GuiButtonType1.List.Length()	{
				
				index := A_Index
			
				For k , v in All
					
					This.CurrentBitmapData[ GuiButtonType1.List[ index ] ][ k ] := v
					
			}
		}
		
		For k , v in GuiButtonType1.List
			
			if( isObject( %v% ) )
				
				For i , j in %v%
					
					This.CurrentBitmapData[ GuiButtonType1.List[ k ] ][ i ] := j
				
	}
	
	_UpdateInstanceData( obj := ""){
		
		For k , v in GuiButtonType1.List	
			
			This.CurrentBitmapData[v].Text := obj.Text
			, This.CurrentBitmapData[v].W := obj.W
			, This.CurrentBitmapData[v].H := obj.H
			
	}

	CreateButtonBitmapSet( obj := "" ,  All := "" , Default := "" , Hover := "" , Pressed := ""  ){ ;Create a new button
		
		local Bitmaps := {}
		
		if( This.Preset )
				
			This._SetCurrentBitmapDataFromSessionData()
			
		else
			
			This._LoadDefaults( "CurrentBitmapData" )
			
		This._UpdateCurrentBitmapData( All , Default , Hover , Pressed )
		
		This._UpdateInstanceData( obj )
		 
		Bitmaps.Default := This._CreateDefaultBitmap()
		, Bitmaps.Hover := This._CreateHoverBitmap()
		, Bitmaps.Pressed := This._CreatePressedBitmap()
		
		return Bitmaps
		
	}
	
}
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************
;****************************************************************************************************************************************************************************************


BG 1.gif
BG 1.gif (159.21 KiB) Viewed 472 times
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

Re: GDIP+ and ActiveX HTML

10 Jan 2023, 13:43

@flyingDman
@Hellbent :superhappy:

Thanks a lot for your time. Cheers and a happy new year!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, mikeyww, yxldh and 147 guests