Jump to content

update gdi before gui_show


 Share

Recommended Posts

So i have a problem to load GDI graphic before the label has been shown.

How do i fix so it works?

Here is the code + extra files.

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <misc.au3>
#include <file.au3>



Opt('MustDeclareVars', 1)

Global $hGUI, $hWnd, $hGraphic, $hPen,$s,$lines,$s1,$x,$color,$ss
Global $s2,$file,$label,$msg,$button1

$file = "test.txt"


$hGUI = GUICreate("Test", 300, 200)
guisetbkcolor("0x181717")
$label = guictrlcreatelabel("",5,100,84,62)
guictrlsetbkcolor(-1,"0x000000")
guictrlsetstate(-1,$GUI_HIDE)
$button1 = guictrlcreatebutton("Minimap",5,170,50,21)
$hwnd = guictrlgethandle($label)
GUISetState()
_GDIPlus_Startup ()


while 1
    $msg = GUIGetMsg()
    switch $msg
        case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown ()
            Exit
        case $button1
            $s= WinGetState(GUICtrlGetHandle($label))
            if bitand($s,2) then
                GUICtrlSetState($label, $GUI_hide)
                _GDIPlus_PenDispose ($hPen)
                _GDIPlus_GraphicsDispose ($hGraphic)
            Else
                update() ; <- add this after gui_show works. But before, It doesn't.
                GUICtrlSetState($label, $GUI_show)
            EndIf
    EndSwitch
WEnd

func update()

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
    _GDIPlus_GraphicsClear($hgraphic,0x000000)
    $hpen = _GDIPlus_PenCreate(0xFF696969)
    _GDIPlus_GraphicsDrawRect ($hGraphic, 0, 0, 83,61,$hPen)
    $hpen = _GDIPlus_PenCreate(0xFF00FF00,1,2)
    $lines = _FileCountLines($file)
    $s1 = stringsplit(filereadline($file,1),chr(32))

    for $i = 2 to $lines

        $s = stringsplit(filereadline($file,$i),chr(32))
        $ss = $s[1]
        $color = iniread("colors.ini","colors",$s1[$ss],0)

        if stringinstr($color,chr(44)) then
            $s2 = stringsplit($color,chr(44))
            $s2 = "0xFF"&hex($s2[1],2)&hex($s2[2],2)&hex($s2[3],2)
            _GDIPlus_PenSetColor($hpen,$s2)
        Else
            _GDIPlus_PenSetColor($hpen,0x00000000)
        EndIf
            _GDIPlus_GraphicsDrawRect ($hGraphic, $s[2]*2, $s[3]*2, 1,1,$hPen)
    Next
EndFunc

files.zip

Link to comment
Share on other sites

Try this:

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <file.au3>

Opt('MustDeclareVars', 1)

Global $hGUI, $hWnd, $hGraphic, $hPen, $hBrush, $s, $lines, $s1, $x, $color, $ss
Global $s2, $file, $label, $msg, $button1, $button2

$file = @ScriptDir & "\test.txt"

Global $width = 300
Global $height = 200
$hGUI = GUICreate("Test", $width, $height)
GUISetBkColor("0x181717")
$button1 = GUICtrlCreateButton("Minimap", 5, 170, 50, 21)
$button2 = GUICtrlCreateButton("Load Minimap", 55, 170, 80, 21)
GUISetState()

_GDIPlus_Startup()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

#region exclude GUI controls from GDI+ graphic screen
Global Const $GW_CHILD = 5, $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $width, $height))
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)
#endregion exclude GUI controls from GDI+ graphic screen

$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hPen = _GDIPlus_PenCreate(0xFF696969)
Global Const $iWidth = 82
Global Const $iHeight = 60
Global Const $iX = 5
Global Const $iY = 100
_GDIPlus_GraphicsFillRect($hGraphic, $iX + 1, $iY + 1, $iWidth, $iHeight, $hBrush)
_GDIPlus_GraphicsDrawRect($hGraphic, $iX, $iY, $iWidth + 1, $iHeight + 1, $hPen)

Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Global $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsFillRect($hContext, 0, 0, $iWidth, $iHeight, $hBrush)

update($file)
Global $button1_status = 1

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_BitmapDispose($hBitmap)
            _GDIPlus_GraphicsDispose($hContext)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_PenDispose($hPen)
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            Exit
        Case $button1
            _GDIPlus_GraphicsFillRect($hGraphic, $iX + 1, $iY + 1, $iWidth, $iHeight, $hBrush)
            If $button1_status = 1 Then _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iX + 1, $iY + 1, $iWidth, $iHeight)
            $button1_status *= -1
        Case $button2
            $file = FileOpenDialog("Select a file with pixel information", @ScriptDir, "(*.txt)")
            If Not @error Then update($file)
    EndSwitch
WEnd

Func update($file)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iWidth, $iHeight, $hBrush)
    $lines = _FileCountLines($file)
    $s1 = StringSplit(FileReadLine($file, 1), Chr(32))
    For $i = 2 To $lines
        $s = StringSplit(FileReadLine($file, $i), Chr(32))
        $ss = $s[1]
        $color = IniRead("colors.ini", "colors", $s1[$ss], 0)
        If StringInStr($color, Chr(44)) Then
            $s2 = StringSplit($color, Chr(44))
            $s2 = "0xFF" & Hex($s2[1], 2) & Hex($s2[2], 2) & Hex($s2[3], 2)
            _GDIPlus_PenSetColor($hPen, $s2)
        Else
            _GDIPlus_PenSetColor($hPen, 0x00000000)
        EndIf
        _GDIPlus_GraphicsDrawRect($hContext, $s[2] * 2, $s[3] * 2, 1, 1, $hPen)
    Next
EndFunc   ;==>update

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetClipRegion

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_RegionCreateFromRect

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionCombineRect

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionDispose

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Try this:

Hmm, it doesn't do what i want.

When i click on the minimap it should open the minimap and close when i click the 2nd time. (Also hide/show the label)

But before the opening it should generate the GDI. So it's already done. Now it's just like before.

I got it to work if i use this method, ugly but works.

Edit: Now i can't have it smaller, ooh this is so bad.

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <misc.au3>
#include <file.au3>



Opt('MustDeclareVars', 1)

Global $hGUI, $hWnd, $hGraphic, $hPen,$s,$lines,$s1,$x,$color,$ss
Global $s2,$file,$label,$msg,$button1

$file = "test.txt"


$hGUI = GUICreate("Test", 500, 200)
guisetbkcolor("0x181717")
$label = guictrlcreatelabel("",400,100,84,62)
guictrlsetbkcolor(-1,"0x000000")
$button1 = guictrlcreatebutton("Minimap",5,170,50,21)
$hwnd = guictrlgethandle($label)
GUISetState()


while 1
    $msg = GUIGetMsg()
    switch $msg
        case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown ()
            Exit
        case $button1
            $s= controlgetpos($hgui,"",$hwnd)
            if $s[0] == 5 and $s[1] == 100 then
                controlmove($hgui,"",$label,400,100,84,62)
            Else
                update()
                controlmove($hgui,"",$label,5,100,84,62)
            EndIf
    EndSwitch
WEnd

func update()
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
    _GDIPlus_GraphicsClear($hgraphic,0x000000)
    $hpen = _GDIPlus_PenCreate(0xFF696969)
    _GDIPlus_GraphicsDrawRect ($hGraphic, 0, 0, 83,61,$hPen)
    $hpen = _GDIPlus_PenCreate(0xFF00FF00,1,2)
    $lines = _FileCountLines($file)
    $s1 = stringsplit(filereadline($file,1),chr(32))

    for $i = 2 to $lines

        $s = stringsplit(filereadline($file,$i),chr(32))
        $ss = $s[1]
        $color = iniread("colors.ini","colors",$s1[$ss],0)

        if stringinstr($color,chr(44)) then
            $s2 = stringsplit($color,chr(44))
            $s2 = "0xFF"&hex($s2[1],2)&hex($s2[2],2)&hex($s2[3],2)
            _GDIPlus_PenSetColor($hpen,$s2)
        Else
            _GDIPlus_PenSetColor($hpen,0x00000000)
        EndIf
            _GDIPlus_GraphicsDrawRect ($hGraphic, $s[2]*2, $s[3]*2, 1,1,$hPen)
        Next
        _GDIPlus_PenDispose ($hPen)
        _GDIPlus_GraphicsDispose ($hGraphic)
EndFunc
Edited by greymouse
Link to comment
Share on other sites

I updated the code from post#2. Is this what you want to do?

Br,

UEZ

Yes like that, but instead of the wolf been creating when you press minimap.

It should be created before. So it's already done. So you don't see when the pixels loads.

Link to comment
Share on other sites

Ok, another try then. Look again to post#2.

Br,

UEZ

Works really nice. It's nice from you to give the whole code too.

But to learn, what does all this do. And how does it work?

I'm not so good at Autoit and really want to learn more each day.

#region exclude GUI controls from GDI+ graphic screen
Global Const $GW_CHILD = 5, $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $width, $height))
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)
#endregion

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetClipRegion

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_RegionCreateFromRect

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionCombineRect

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionDispose

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

And one more thing. The minimap is going to be updated when everyone click on the minimap.

People drawing and it saving the colors, and the minimap need to clear the recent picture.

And one more thing. How do i remove the rectangle when i close the minimap?

I only come to this stage, then didn't i understand how i should create it.

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <misc.au3>
#include <file.au3>



Opt('MustDeclareVars', 1)

Global $hGUI, $hWnd, $hGraphic, $hPen, $hBrush, $s,$lines,$s1,$x,$color,$ss
Global $s2,$file,$label,$msg,$button1

$file = @ScriptDir & "\test.txt"

Global $width = 300
Global $height = 200
$hGUI = GUICreate("Test", $width, $height)
guisetbkcolor("0x181717")
;~ $label = guictrlcreatelabel("",5,100,84,62)
;~ guictrlsetbkcolor(-1,"0x000000")
;~ guictrlsetstate(-1,$GUI_HIDE)
$button1 = guictrlcreatebutton("Minimap",5,170,50,21)
GUISetState()

_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

#region exclude GUI controls from GDI+ graphic screen
Global Const $GW_CHILD = 5, $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $width, $height))
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)
#endregion

$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hpen = _GDIPlus_PenCreate(0xFF696969)

Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($width, $height)
Global $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsFillRect($hContext, 6, 101, 81, 59, $hBrush)

Global $button1_status = 1

while 1
    $msg = GUIGetMsg()
    switch $msg
        case $GUI_EVENT_CLOSE
            _GDIPlus_BitmapDispose($hBitmap)
            _GDIPlus_GraphicsDispose($hContext)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_PenDispose($hpen)
            _GDIPlus_GraphicsDispose($hgraphic)
            _GDIPlus_Shutdown ()
            Exit
        case $button1
            If $button1_status = 1 Then
                _GDIPlus_GraphicsFillRect($hGraphic, 6, 101, 81, 59, $hBrush)
                _GDIPlus_PenSetColor($hpen, 0xFF696969)
                _GDIPlus_GraphicsDrawRect ($hGraphic, 5, 100, 83,61,$hPen)
                update()
                _GDIPlus_GraphicsDrawImage($hgraphic, $hBitmap, 5, 100)
            Else
                _GDIPlus_GraphicsClear ($hgraphic)
            EndIf
            $button1_status *= -1
    EndSwitch
WEnd

func update()
    $lines = _FileCountLines($file)
    $s1 = stringsplit(filereadline($file,1),chr(32))

    for $i = 2 to $lines

        $s = stringsplit(filereadline($file,$i),chr(32))
        $ss = $s[1]
        $color = iniread("colors.ini","colors",$s1[$ss],0)

        if stringinstr($color,chr(44)) then
            $s2 = stringsplit($color,chr(44))
            $s2 = "0xFF"&hex($s2[1],2)&hex($s2[2],2)&hex($s2[3],2)
            _GDIPlus_PenSetColor($hpen,$s2)
        Else
            _GDIPlus_PenSetColor($hpen,0x00000000)
        EndIf
            _GDIPlus_GraphicsDrawRect ($hContext, $s[2]*2, $s[3]*2, 1,1,$hPen)
    Next
EndFunc

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetClipRegion

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_RegionCreateFromRect

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionCombineRect

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionDispose

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
Link to comment
Share on other sites

Works really nice. It's nice from you to give the whole code too.

But to learn, what does all this do. And how does it work?

I'm not so good at Autoit and really want to learn more each day.

#region exclude GUI controls from GDI+ graphic screen
Global Const $GW_CHILD = 5, $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $width, $height))
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)
#endregion

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetClipRegion

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_RegionCreateFromRect

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionCombineRect

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionDispose

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Well, as it is descriped it excludes GUI controls from GDI+ graphic screen. E.g. move the button over the picture and it will not be erased when the picture will be refreshed.

And one more thing. The minimap is going to be updated when everyone click on the minimap.

People drawing and it saving the colors, and the minimap need to clear the recent picture.

I don't understand you exactly what you want! :)

And one more thing. How do i remove the rectangle when i close the minimap?

I only come to this stage, then didn't i understand how i should create it.

Also here, I don't understand what you mean with "remove the rectangle when i close the minimap"!

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Well, as it is descriped it excludes GUI controls from GDI+ graphic screen. E.g. move the button over the picture and it will not be erased when the picture will be refreshed.

I don't understand you exactly what you want! :)

Also here, I don't understand what you mean with "remove the rectangle when i close the minimap"!

Br,

UEZ

I mean, it should close the minimap.

And then open it. Not be open forever.

^ And here is what i want it to be ^

Posted Image

With the pixels that "BitmapCreateFromScan0" saves.

Need to be cleared. Because if i load a new "text2.txt" it's will not be cleared.

^ Here is the example for that, test2.txt added as attachment. ^

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <misc.au3>
#include <file.au3>



Opt('MustDeclareVars', 1)

Global $hGUI, $hWnd, $hGraphic, $hPen, $hBrush, $s,$lines,$s1,$x,$color,$ss
Global $s2,$file,$label,$msg,$button1

$file = @ScriptDir & "\test.txt"

Global $width = 300
Global $height = 200
$hGUI = GUICreate("Test", $width, $height)
guisetbkcolor("0x181717")
;~ $label = guictrlcreatelabel("",5,100,84,62)
;~ guictrlsetbkcolor(-1,"0x000000")
;~ guictrlsetstate(-1,$GUI_HIDE)
$button1 = guictrlcreatebutton("Minimap",5,170,50,21)
GUISetState()

_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

#region exclude GUI controls from GDI+ graphic screen
Global Const $GW_CHILD = 5, $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $width, $height))
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)
#endregion

$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hpen = _GDIPlus_PenCreate(0xFF696969)

Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($width, $height)
Global $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsFillRect($hContext, 6, 101, 81, 59, $hBrush)

Global $button1_status = 1

while 1
    $msg = GUIGetMsg()
    switch $msg
        case $GUI_EVENT_CLOSE
            _GDIPlus_BitmapDispose($hBitmap)
            _GDIPlus_GraphicsDispose($hContext)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_PenDispose($hpen)
            _GDIPlus_GraphicsDispose($hgraphic)
            _GDIPlus_Shutdown ()
            Exit
        case $button1
            If $button1_status = 1 Then
                _GDIPlus_GraphicsFillRect($hGraphic, 6, 101, 81, 59, $hBrush)
                _GDIPlus_PenSetColor($hpen, 0xFF696969)
                _GDIPlus_GraphicsDrawRect ($hGraphic, 5, 100, 83,61,$hPen)
                update()
                _GDIPlus_GraphicsDrawImage($hgraphic, $hBitmap, 5, 100)
            Else
                $file = @ScriptDir & "\test2.txt" ; Just a test, this shouldn't be here
                update() ; Just a test, this shouldn't be here
                _GDIPlus_GraphicsDrawImage($hgraphic, $hBitmap, 5, 100) ; Just a test, this shouldn't be here
            EndIf
            $button1_status *= -1
    EndSwitch
WEnd

func update()
    $lines = _FileCountLines($file)
    $s1 = stringsplit(filereadline($file,1),chr(32))

    for $i = 2 to $lines

        $s = stringsplit(filereadline($file,$i),chr(32))
        $ss = $s[1]
        $color = iniread("colors.ini","colors",$s1[$ss],0)

        if stringinstr($color,chr(44)) then
            $s2 = stringsplit($color,chr(44))
            $s2 = "0xFF"&hex($s2[1],2)&hex($s2[2],2)&hex($s2[3],2)
            _GDIPlus_PenSetColor($hpen,$s2)
        Else
            _GDIPlus_PenSetColor($hpen,0x00000000)
        EndIf
            _GDIPlus_GraphicsDrawRect ($hContext, $s[2]*2, $s[3]*2, 1,1,$hPen)
    Next
EndFunc

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetClipRegion

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_RegionCreateFromRect

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionCombineRect

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionDispose

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

test2.txt

Link to comment
Share on other sites

Look to post#2 again. I hope this is what you want.

Now it is your turn to fine tune the code to fullfill your needs. :)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...