Funtime60 Posted August 20, 2023 Posted August 20, 2023 When I resize my GUI the image I've loaded into the graphic blanks after it's been resized. I have no idea why though. Any help would be great. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Timers.au3> #include <Debug.au3> #include <GDIPlus.au3> GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") _GDIPlus_Startup() Global $iWidth = 512 Global $iHeight = 512 Global $tMapImg = Default #Region ### START Koda GUI section ### Global $hTestMap = GUICreate("TestMap", $iWidth, $iHeight, -1, -1, $WS_OVERLAPPEDWINDOW) Global $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($hTestMap) ;create a graphics object from a window handle Global $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics) Global $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) GUISetState(@SW_SHOW) __UpdateMapImgHelper($hTestMap, False) GUIRegisterMsg($WM_SIZE, "__ResizeUpdate") #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit EndSwitch WEnd Func __ResizeUpdate() Local $aTmp = WinGetClientSize($hTestMap) $iWidth = $aTmp[0] $iHeight = $aTmp[1] $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($hTestMap) ;create a graphics object from a window handle $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics) $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) __UpdateMapImgHelper($hTestMap, False, False) MsgBox(0,"","Why does this disappear after this line?"&"Line Number: "&@ScriptLineNumber) EndFunc Func __UpdateMapImgHelper($hWnd, $bSchedule = True, $bResetTimer = True) If $bResetTimer And $tMapImg <> Default Then _Timer_KillTimer($hWnd, $tMapImg) EndIf ;~ ConsoleWrite($iWidth&@TAB&$iHeight&@CRLF) __UpdateMapImg($hTestMap, Default, Default, Default, $bSchedule Or $bResetTimer) EndFunc Func __UpdateMapImg($hWnd, $iMsg, $iIDtimer, $iTime, $bSchedule = True) #forceref $hWnd, $iMsg, $iIDTimer,$iTime ConsoleWrite($iWidth&@TAB&$iHeight&@CRLF) Local $hHBmp = _GDIPlus_BitmapCreateFromMemory(InetRead("https://i.imgur.com/ZxOCPa3.jpg"), True) $g_hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $g_hBMP, 0, 0) ;draw bitmap to backbuffer _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iWidth, $iHeight) ;copy drawn bitmap to graphics handle (GUI) If $bSchedule Then $tMapImg = _Timer_SetTimer($hWnd, 300000, "__UpdateMapImg") EndIf EndFunc Func _Exit() ;cleanup GDI+ resources _GDIPlus_Shutdown() GUIDelete($hTestMap) Exit EndFunc ;==>_Exit
UEZ Posted August 20, 2023 Posted August 20, 2023 (edited) You have to repaint the graphic on erase. I found an old script: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> Opt("GUIOnEventMode", 1) Global $iW = 500, $iH = 500 Global Const $hGUI = GUICreate("test", $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $hGUI) _GDIPlus_Startup() Global Const $hBitmap = _GDIPlus_BitmapCreateFromMemory(InetRead("https://i.imgur.com/ZxOCPa3.jpg")) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND") WM_SIZE($hGUI, $WM_SIZE, 0, 0) _WinAPI_RedrawWindow($hGUI) While Sleep(1000) WEnd Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local Const $aWidth = WinGetClientSize($hGUI) $iW = $aWidth[0] $iH = $aWidth[1] Return "GUI_RUNDEFMSG" EndFunc ;==>WM_SIZE Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $lParam Local Const $hGfx = _GDIPlus_GraphicsCreateFromHDC($wParam) _GDIPlus_GraphicsClear($hGfx, 0xFFFFFFFF) _GDIPlus_GraphicsSetInterpolationMode($hGfx, 1) _GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap, 0, 0, $iW, $iH) _GDIPlus_GraphicsDispose($hGfx) Return True EndFunc ;==>WM_ERASEBKGND Func _Exit() GUIRegisterMsg($WM_ERASEBKGND, "") GUIRegisterMsg($WM_SIZE, "") _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc ;==>_Exit Edited August 21, 2023 by UEZ pixelsearch 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
pixelsearch Posted August 21, 2023 Posted August 21, 2023 (edited) @UEZ nice script I have a minor issue with any pic, no matter its size (lesser than 500x500 [which is the client size of the GUI] or greater) because some pixels at the bottom of the pic are always missing until the user does a 1st resize, for example : ; Global Const $hBitmap = _GDIPlus_BitmapCreateFromMemory(InetRead("https://i.imgur.com/ZxOCPa3.jpg")) Global Const $hBitmap = _GDIPlus_BitmapCreateFromFile("G:\any pic.jpg") On the left part, we see the real jpg (464x424) and the bottom part of the jpg shows clearly the last 2 lines of the pic : "Pad-" and "Pad+" On the right part, we ran the script and the pic is truncated inside the GUI, a part of the pic is missing as we don't see the last 2 lines. This is replicable on any pic (on my computer). Now when the user starts a 1st resize (by dragging with the mouse the right bottom corner of the GUI) then the whole pic appears immediately and correctly inside the GUI, that's why it's a minor problem. Nevertheless, I found a way to solve this, by forcing an automatic call to Func WM_SIZE() like this : GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND") _WinAPI_RedrawWindow($hGUI) WM_SIZE($hGUI, $WM_SIZE, 0, 0) ; force a 1st automatic WM_SIZE to have the bottom part of the pic always visible. Edit: this additional WM_SIZE() line could also be placed just before the _WinAPI_RedrawWindow($hGUI) line, with the same correct display (tested). Edited August 21, 2023 by pixelsearch UEZ 1
pixelsearch Posted August 21, 2023 Posted August 21, 2023 The issue could be related with the GUI creation line : Global Const $hGUI = GUICreate("test", $iW, $iH, -1, -1, $WS_SIZEBOX) When created like follows, everything looks fine from the start : Global Const $hGUI = GUICreate("test", $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) UEZ 1
UEZ Posted August 21, 2023 Posted August 21, 2023 @pixelsearch thanks for your feedback. You are right, the height was not set properly. Additionally the graphic context must be cleared for transparent images. I updated the script above. 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Funtime60 Posted August 23, 2023 Author Posted August 23, 2023 Thank you for all the input, I've been busy and haven't worked on this since I got stuck. I'll give it a try and come back with my results.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now