pixelsearch Posted August 27, 2019 Share Posted August 27, 2019 (edited) Hi everybody I would like to thank UEZ for the great help he brought us concerning what follows : When I right click a row in the following ListView, the corresponding image should be displayed in a Splash Window and disappear as soon as the mouse moves. But as you can see below, nothing happens when the image is .png type (as stated in the help file, topics SplashImageOn and GUICtrlCreatePic) Now see how it works fine with jpg, gif or bmp : Gladly UEZ indicated not 1, but 2 different ways to solve this, allowing us to display png files using GDI+ Let's start with way #1, simulating a Splash Window : #include <GDIPlus.au3> #include <WindowsConstants.au3> $sFileName = @ScriptDir & "\Torus.png" If Not FileExists($sFileName) Then _ Exit MsgBox($MB_TOPMOST, "Error", $sFileName & " not found") _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hGUI = GUICreate("", $iX, $iY, -1, -1, _ $WS_BORDER + $WS_POPUP, $WS_EX_TOPMOST) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY) $aPos_Old = MouseGetPos() Do $aPos_New = MouseGetPos() Sleep(100) Until $aPos_Old[0] <> $aPos_New[0] Or $aPos_Old[1] <> $aPos_New[1] GUIDelete($hGUI) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Now the 2nd way, displaying the png image in a GUI picture control : #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> $sFileName = @ScriptDir & "\Torus.png" If Not FileExists($sFileName) Then _ Exit MsgBox($MB_TOPMOST, "Error", $sFileName & " not found") _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hGUI = GUICreate("Display PNG Image in picture control", $iX, $iY, -1, -1, _ -1, $WS_EX_TOPMOST) $idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY) GUICtrlSendMsg($idPic, 0x0172, 0, $hBitmap) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) _WinAPI_DeleteObject($hBitmap) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Exit Case $idPic MsgBox($MB_TOPMOST, "Information", "PNG image was clicked") EndSwitch WEnd The "Torus.png" image can be downloaded just below in case you want to try the scripts. Just rename it "Torus.png" and place it in the same folder than the scripts. @UEZ : and let's hope this will be useful for those who encountered the same issue. @Mods : I didn't know where to post this comment. If you think it should be placed in another part of the Forum, please be kind enough to move it there, thanks. Torus.png Edited August 27, 2019 by pixelsearch Decibel 1 Link to comment Share on other sites More sharing options...
Werty Posted August 27, 2019 Share Posted August 27, 2019 Quote I didn't know where to post this comment. I The "Snippets" thread perhaps ? Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Shark007 Posted March 1, 2022 Share Posted March 1, 2022 (edited) deleted because once I put on some glasses I saw a dot where a comma should be. Edited March 1, 2022 by Shark007 Link to comment Share on other sites More sharing options...
Shark007 Posted March 18, 2022 Share Posted March 18, 2022 (edited) 1st things 1st, @UEZ, Thank you for sharing your knowledge. To follow up on @pixelsearch information, I present a simple GUI that uses #AutoIt3Wrapper_Res_HiDpi=Y. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_Res_HiDpi=Y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> _GDIPlus_Startup() Global $iScale = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", _GDIPlus_GraphicsCreateFromHWND(0), "float*", 0)[2] / 96 ; The above line retrieves the current Windows Scaling Factor - If Windows is set to 150% scaling it will return 1.5 GUICreate('Test', 500 * $iScale, 300 * $iScale, 200 * $iScale, 400 * $iScale) ;Create a GUI GUICtrlCreateButton("DPI testing", 350 * $iScale, 50 * $iScale, 120 * $iScale, 20 * $iScale) ; Create s button Global $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Torus.png") ;The PNG image that you want to display Global $B_Scaled = _GDIPlus_ImageScale($hImage, $iScale, $iScale) ;Torus.png is distributed with AutoIt and is found here - C:\Program Files (x86)\AutoIt3\Examples\GUI Global $idPic = GUICtrlCreatePic("", 150 * $iScale, 75 * $iScale, _GDIPlus_ImageGetWidth($B_Scaled), _GDIPlus_ImageGetHeight($B_Scaled)) ;The above line 1st sets the left/Top coordinates to place the png and then gets scaled image dimensioms for W/H GUICtrlSendMsg($idPic, 0x0172, 0, _GDIPlus_BitmapCreateHBITMAPFromBitmap($B_Scaled)) ; Send the image to the Pic Control _WinAPI_DeleteObject($hImage) ;some clean up _GDIPlus_ImageDispose($B_Scaled) _GDIPlus_Shutdown() GUISetState(@SW_SHOW, 0) While 1 Sleep(50) Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd Using the above scaling for your GUI will present the same GUI no matter if the Windows scaling is set to 100% or 350% The absolute real bonus of using HiDpi=Y is the quality of the text within your GUI when it is scaled properly. The text scaling is provided by Windows when the user selects to use HiDpi through the AutoIt3Wrapper. Edited March 20, 2022 by Shark007 Link to comment Share on other sites More sharing options...
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