CodingCody37 Posted August 19, 2014 Share Posted August 19, 2014 (edited) Hi, I'm in need for some help because I came across an issue that I can't seem to resolve. What I want to achieve is having a part of my application containing thumbnails pictures horizontally and being able to scroll them. What I managed to get to is creating a child GUI inside my main, and to use Melba23's GUIScrollbars_Ex.au3. Now for the pictures inside, first I've drawn them with GDI+ but as soon as I move the slider and some images go out of the display area, they disappear when you move it back... so they need to be redrawn. Quite tedious, the answer I found lurking this forum is that I had to use a Pic Control, like this : $hImage = _GDIPlus_ImageLoadFromFile("myPicture.jpg") $idPic = GUICtrlCreatePic("", 0, 0, _GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage)) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) yes, here there's only one picture because it's a first step, if I manage to make it work for one I can for 10 or 20.. Ok, so this code is working and nothing needs to be redrawn, as I move my slider, even if my Picture gets out of focus (like what happens to the top of this page if u move the right slider down), when I move it back, my picture is still displayed! Now for my question then, that picture is full sized...and that is very wrong. I need it to be resized. So how to do it ? You'll say using such code with _GDIPlus_GraphicsDrawImageRect : $hBmp1 = _WinAPI_CreateBitmap(500, 500, 1, 32) $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap) _WinAPI_DeleteObject($hBmp1) $hImage = _GDIPlus_ImageLoadFromFile('myPicture.jpg') _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 80, 120) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) my issue is that this doesn't display anything, no idea why (whereas I can of course use this function in a simple script to resize a picture). Here's a shortened script to demonstrate the full working setup I would like, except I need resized pictures (you need a sample picture that I called MyPicture.jpg and Melba23's GUIScrollbars_Ex UDF of course (awesome btw)) expandcollapse popup#include <GuiConstants.au3> #include <GUIConstantsEx.au3> #include "GUIScrollbars_Ex.au3" #include <GDIPlus.au3> ;~ Global Const $IMAGE_BITMAP = 0 Global Const $STM_SETIMAGE = 0x0172 $sFile = 'myPicture.jpg' _GDIPlus_Startup() $Main_GUI = GUICreate("Main", 500, 250) GUISetBkColor(0x220a33, $Main_GUI) GUISetState(@SW_SHOW, $Main_GUI) $hDummyLabel = GUICtrlCreateLabel("", 0, 0, 0, 0) $Child_GUI = GUICreate("Child", 400, 200, 50, 5, $WS_POPUP, -1, $Main_GUI) GUISetState(@SW_SHOW, $Child_GUI) DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child_GUI), "hwnd", WinGetHandle($Main_GUI)) _GUIScrollbars_Generate($Child_GUI, 2000, 0, 0, 0, Default, 7) $hImage = _GDIPlus_ImageLoadFromFile($sFile) $idPic = GUICtrlCreatePic("", 0, 0, _GDIPlus_ImageGetWidth($hImage) / 4, _GDIPlus_ImageGetHeight($hImage) / 4) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $Main_GUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop EndSwitch EndSwitch WEnd _WinAPI_DeleteObject($hHBitmap) _GDIPlus_Shutdown() If anyone has clues about how to solve this I'd be glad to read. Thanks! note : the dummy label is there because if you remove it, no way to close the main gui (which would be empty except having the inner child gui inside) ... no idea way but this is the workaround I found Edited August 19, 2014 by CodingCody37 Link to comment Share on other sites More sharing options...
CodingCody37 Posted August 19, 2014 Author Share Posted August 19, 2014 (edited) here is a little script demonstrating how it fails regarding what I'd like to do : #include <GDIPlus.au3> #include "GUIScrollbars_Ex.au3" _GDIPlus_Startup() $Main_GUI = GUICreate("HScroll Nested GUI", 490, 300) GUISetBkColor(0x220a33, $Main_GUI) GUISetState(@SW_SHOW, $Main_GUI) $hDummyLabel = GUICtrlCreateLabel("", 0, 0, 0, 0) $Child_GUI = GUICreate("Child", 400, 200, 50, 5, $WS_POPUP, -1, $Main_GUI) GUISetState(@SW_SHOW, $Child_GUI) DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child_GUI), "hwnd", WinGetHandle($Main_GUI)) _GUIScrollbars_Generate($Child_GUI, 2000, 0, 0, 0, Default, 7) $sFile = 'MyPicture.jpg' $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($Child_GUI) $hImage = _GDIPlus_ImageLoadFromFile($sFile) _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $hImage, 0, 0, 200, 130) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Exit EndSwitch WEnd Edited August 19, 2014 by CodingCody37 Link to comment Share on other sites More sharing options...
Solution CodingCody37 Posted August 19, 2014 Author Solution Share Posted August 19, 2014 found it, I just replaced $hImage = _GDIPlus_ImageLoadFromFile($sFile) with $hImage = _GDIPlus_ImageResize( _GDIPlus_ImageLoadFromFile($sFile), 200, 130) ... 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