GDI question - keep both images on the gui Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

GDI question - keep both images on the gui

16 Sep 2021, 15:04

I am trying to get the first line to stay even after the second line is drawn, does anyone know how to do this?

My sample code , you could just run it and see that when the second line is drawn the first vanishes

Code: Select all

#Include, Gdip.ahk

#SingleInstance, Force
SetBatchlines, -1
GDIP_StartUp()
Gui, 1:+AlwaysOnTop
Gui, 1:Add, Picture, xm ym w400 h400 0xE hwndPicHwnd
Gui, 1:Show,, Demo

progSizexx := 20
progSizeyy := 20
progSizex := 28
progSizey := 15
loop, 25
{
DiagonalProgressBar( PicHwnd, progSizexx, progSizeyy, progSizex, progSizey )
progSizex+=10
progSizey+=10
sleep, 15
}

progSizexx := 300
progSizeyy := 20
progSizex := 28
progSizey := 15
loop, 25
{
DiagonalProgressBar( PicHwnd, progSizexx, progSizeyy, progSizex, progSizey )
progSizex-=10
progSizey+=10
sleep, 15
}

return

DiagonalProgressBar( hwnd , sizexx := "", sizeyy := "", sizex := "", sizey := "" ){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap := Gdip_CreateBitmap( 400 , 400) , G := Gdip_GraphicsFromImage( pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
	Pen := Gdip_CreatePen( "0xFF880000" , 5 ) , Gdip_DrawLine( G , Pen , sizexx , sizeyy , sizex , sizey ) Gdip_DeletePen( Pen )
	Gdip_DeleteGraphics( G )
	hBitmap := Gdip_CreateHBITMAPFromBitmap( pBitmap )
	Gdip_DisposeImage(pBitmap)
	SetImage( hwnd , hBitmap )
	DeleteObject( hBitmap )

}
GuiClose:
esc:
ExitApp
I tried creating two picture controls and adding backgroundtrans, now they stay but its a mess of lines

Code: Select all

#Include, Gdip.ahk

#SingleInstance, Force
SetBatchlines, -1
GDIP_StartUp()
Gui, 1:+AlwaysOnTop
Gui, 1:Add, Picture, xm ym w400 h400 0xE +BackgroundTrans hwndPicHwnd
Gui, 1:Add, Picture, xm ym w400 h400 0xE +BackgroundTrans hwndPicHwnd2
Gui, 1:Show,, Demo

progSizexx := 20
progSizeyy := 20
progSizex := 28
progSizey := 15
loop, 25
{
DiagonalProgressBar( PicHwnd, progSizexx, progSizeyy, progSizex, progSizey )
progSizex+=10
progSizey+=10
sleep, 15
}

progSizexx := 300
progSizeyy := 20
progSizex := 28
progSizey := 15
loop, 25
{
DiagonalProgressBar( PicHwnd2, progSizexx, progSizeyy, progSizex, progSizey )
progSizex-=10
progSizey+=10
sleep, 15
}

return

DiagonalProgressBar( hwnd , sizexx := "", sizeyy := "", sizex := "", sizey := "" ){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap := Gdip_CreateBitmap( 400 , 400) , G := Gdip_GraphicsFromImage( pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
	Pen := Gdip_CreatePen( "0xFF880000" , 5 ) , Gdip_DrawLine( G , Pen , sizexx , sizeyy , sizex , sizey ) Gdip_DeletePen( Pen )
	Gdip_DeleteGraphics( G )
	hBitmap := Gdip_CreateHBITMAPFromBitmap( pBitmap )
	Gdip_DisposeImage(pBitmap)
	SetImage( hwnd , hBitmap )
	DeleteObject( hBitmap )

}
GuiClose:
esc:
ExitApp
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GDI question - keep both images on the gui  Topic is solved

16 Sep 2021, 18:22

I'm not quite sure what it is that your end goal is but I think that I can see a simple solution to what I see.

As it is now, each time you call the function it covers over the last thing you had drawn. A simple way around this is to use an array for your lines


So for example

Code: Select all

MyLineArray := []

MyLineArray[1] := { X1: ,Y1: ,X2: ,Y2: }


DrawingFunction( hwnd , array ){
	loop, % array.Length
	 GDIP_DrawLine(...)
}
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GDI question - keep both images on the gui

16 Sep 2021, 18:27

Another way could be to have the function return a bitmap and then use the returned bitmaps to combine together into a master bitmap. In that case it would be the Composite Image (Bitmap) that you draw on the gui.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, jollyjoe and 275 guests