Jump to content

Recommended Posts

Posted

@UEZ hello :)


I would like to expose an issue I got when a pic control is resided with GUICtrlSetResizing($idPic, $GUI_DOCKAUTO) , maybe you could be so kind to indicate if something is doable or not. Though the images below don't show it, all what follows has also been tested right now on Windows 11, but the issue (if it's an issue) is still there.

1) Grid.png (3KB, downloadable at the end of this post)
This is a png image 600x600 pixels, white background, with a grid composed of squares of 20x20 pixels :

image.png.c63fe2dbd604870ee4455eca58db1ae1.png

2) I create a pic control with this png, in a script having a gui which client size is also 600x600 pixels
The gui is resizable and contains controls (all movable and resizable) as shown in the pic below. The grid helps a lot to align the controls :

image.png.db98fc6c7348c0ab61b0a15919e1614a.png

3) When the yellow checkbox control is checked, then the pic control (containing grid.png) is hidden, the gui grey background reappears and all other controls react correctly (by design) as shown in the pic below :

image.png.487244fdf8861d21d62bd1bd0a2aeb6e.png

When the script ends, all coords are saved, so all controls will be correctly placed when the script is run again, so far so good

4) Now please have a look at this simpler script that will indicate the issue :

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Example()

Func Example()
    Local $sImagePath = @ScriptDir & "\Grid.png"

    _GDIPlus_Startup()
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImagePath)
    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    Local $iX = _GDIPlus_ImageGetWidth($hImage)
    Local $iY = _GDIPlus_ImageGetHeight($hImage)

    Local $hGUI = GUICreate("Grid Test", $iX, $iY, -1, -1, $WS_OVERLAPPEDWINDOW)
    GUISetBkColor(0x808080) ; grey

    Local $idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY)
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
    GUICtrlSetResizing($idPic, $GUI_DOCKAUTO)
    GUICtrlSetState($idPic, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

5) When you run the script in 4) the pic 600x600 showing the grid is displayed in the gui. Now if you resize the gui horizontally (dragging its right border to the left) then the gui client width becomes < 600 pixels . In this case, the vertical lines only becomes messy, as shown in the pic below :

image.png.295b4743284ad6063cbfe0a4537ee884.png

6) When you run the script in 4) the pic 600x600 showing the grid is displayed in the gui. Now if you resize the gui vertically (dragging its bottom border to the top) then the gui client height becomes < 600 pixels . In this case, the horizontal lines only becomes messy, as shown in the pic below :

image.png.626ec2f6729e1baa88fe926e1724f430.png

7) If you resize both width and height (both being < 600 pixels) then all lines are messy : this is 5) + 6) as shown in the pic below :

image.png.7a890165b7967e4ca98df7e105bf21dd.png

8 ) Applied to 2) you will end up with this bad display, after you resize the gui to width & height < 600 pixels :

image.png.b7db248ed8b113cc10f97541a66275f6.png

Please note that width and height > 600 pixels behave correctly, the problem occurs only when < 600 pixels.
For the record, I tried also a jpg image (instead of a png) with the same bad display.

I thought that GUICtrlSetResizing() was enough to fix this, but apparently not. Do you think there is an easy solution to avoid this, or should I update the pic control constantly during the resize phase, with a resized or scaled image, or maybe another solution ?

Thanks for reading

Grid.png

 

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)

Is the grid just for demonstration purposes, or is that really the background you want to use?

Should the grid resize when the GUI is resized?

 

Here the version without resizing the grid on GUI resize (modified one of my old scripts):

;Coded by UEZ build 2026-05-31

#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global Const $STM_SETIMAGE = 0x0172
Global $sImage = "Grid.png"

_GDIPlus_Startup()
Global $hBmp = _GDIPlus_BitmapCreateFromFile($sImage), $hTexture = _GDIPlus_TextureCreate($hBmp, 0)
Global $iW = _GDIPlus_ImageGetWidth($hBmp), $iH = _GDIPlus_ImageGetHeight($hBmp)

Global $hGUI = GUICreate("Test", $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), $WS_EX_COMPOSITED)
Global $idPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
Global $hB = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
If $hB Then _WinAPI_DeleteObject($hB)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_SIZE, "")
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_BrushDispose($hTexture)
            _GDIPlus_BitmapDispose($hBmp)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
WEnd

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    Local $aSize = ControlGetPos($hWnd, "", $idPic)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($aSize[2], $aSize[3])
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetInterpolationMode($hContext, 0)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $aSize[2], $aSize[3], $hTexture)
    _GDIPlus_GraphicsDispose($hContext)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    Local $hB = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return "GUI_RUNDEFMSG"
EndFunc

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Thanks for your script, very informative.

52 minutes ago, UEZ said:

Is the grid just for demonstration purposes, or is that really the background you want to use?

Yes it is the background I want to use.
 

52 minutes ago, UEZ said:

Should the grid resize when the GUI is resized?

 

Definitely, the grid should resize when the GUI is resized, as you can see in my preceding post, when comparing image in 2) with image in 8 )

By the way, bravo for your super comment in trac ticket 4098, it explains nicely why graphics context disappear and how to fix that. I wish your code to fix the disappearing of graphics context was found in all help file examples related to that !
You did well adding the fixing lines preceded with a Tab so it was easy to detect them :thumbsup:

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted
7 minutes ago, pixelsearch said:

Definitely, the grid should resize when the GUI is resized, as you can see in my preceding post, when comparing image in 2) with image in 8 )

With resize I mean really resize of the grid. My example above fills only the grid but doesn't resize it. You can also resize the grid when GUI resizes. That means the grid becomes smaller / bigger on GUI resize.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
;Coded by UEZ build 2026-05-31

#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global Const $STM_SETIMAGE = 0x0172
Global $sImage = "image.png"

_GDIPlus_Startup()
Global $hBmp = _GDIPlus_BitmapCreateFromFile($sImage), $hTexture = _GDIPlus_TextureCreate($hBmp, 0)
Global $iW = _GDIPlus_ImageGetWidth($hBmp), $iH = _GDIPlus_ImageGetHeight($hBmp)

Global $g_hWnd, $hGUI = GUICreate("Test", $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), $WS_EX_COMPOSITED)
Global $idPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
Global $hB = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
If $hB Then _WinAPI_DeleteObject($hB)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_SIZE, "")
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_BrushDispose($hTexture)
            _GDIPlus_BitmapDispose($hBmp)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
WEnd

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    $g_hWnd = $hWnd
    doit()
    AdlibRegister(doit, 100)
    Return "GUI_RUNDEFMSG"
EndFunc

Func doit()
    AdlibUnRegister(doit)
    Local $aSize = ControlGetPos($g_hWnd, "", $idPic)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($aSize[2], $aSize[3])
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetInterpolationMode($hContext, 0)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $aSize[2], $aSize[3], $hTexture)
    _GDIPlus_GraphicsDispose($hContext)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    Local $hB = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
EndFunc

..to give it a last pass. Looks better on mouse release :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting  image.gif.922e3a93535f431de08b31ee669cc446.gif
autoit_scripter_blue_userbar.png

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
×
×
  • Create New...