Sign in to follow this  
Followers 0
Damein

GDI + How to set width/length of image?

5 posts in this topic

I have the following commands:

Func TomorrowMY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($TomorrowGUI, 0, 0, $RDW_UPDATENOW)
    $hImage   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image4.png")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($TomorrowGUI)
    GUIRegisterMsg($WM_PAINT, "TomorrowMY_WM_PAINT")
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 45, 25)
    _WinAPI_RedrawWindow($TomorrowGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

And I'm not too savvy with GDI. SO, how could I set the width/height of the image being used through my progrram?


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I also stumbled across this:

Which works.. oddly, but not on my GUI.

#include <GDIplus.au3>
#include <GuiConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $file, $msg
Do
    $file = FileOpenDialog("Select image to load", @ScriptDir, "Images (*.jpg;*.png; *.bmp;*.gif)")
    If @error Then
    $msg = MsgBox(20, "Error", "Please select an image!")
    If $msg = 7 Then
    Exit
    Else
    SetError(1)
    EndIf
    EndIf
Until Not @error
_GDIPlus_Startup()
Global $hImage = _GDIPlus_BitmapCreateFromFile($file)
Global $hwnd = GUICreate("GDI+: image resized to ",200,200)
GUISetState(@SW_SHOW)
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 300,300)
While Sleep(30)
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
WEnd

Code posted by UEZ @

Here is a snippet of my code, containing the problem area.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>
Global $ZipCode, $GUI, $hgraphic, $himage, $RightNowGui, $TodayGui, $TonightGui, $TomorrowGui
Global $h_Desktop_SysListView32
_GetDesktopHandle()
$Width = @DesktopWidth
$Height = @DesktopHeight
_RightNowGUI()
Func _RightNowGUI()
    $RightNowGUI = GUICreate("", 150, 300, $Width-151, $Height-600, BitOR($WS_POPUP,$WS_BORDER), Default, WinGetHandle(AutoItWinGetTitle()))
    GuiSetFont(13)
    GUICtrlSetDefColor(0xFFFFFF)
    GUISetBkColor(0x000000)
    WinSetTrans($RightNowGUI,"",200)
    _GDIPlus_StartUp()
$file = FileOpenDialog("Select image to load", @ScriptDir, "Images (*.jpg;*.png; *.bmp;*.gif)")
    $hImage   = _GDIPlus_ImageLoadFromFile($file)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($RightNowGUI)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 25, 300,300)
    DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32)
    GuiSetState()
EndFunc
Func _GetDesktopHandle()
    $h_Desktop_SysListView32 = 0
    Local Const $hDwmApiDll = DllOpen("dwmapi.dll")
    Local $sChkAero = DllStructCreate("int;")
    DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
    Local $aero_on = DllStructGetData($sChkAero, 1)
    If Not $aero_on Then
        $h_Desktop_SysListView32 = WinGetHandle("Program Manager")
        Return 1
    Else
        Local $hCBReg = DllCallbackRegister("_GetDesktopHandle_EnumChildWinProc", "hwnd", "hwnd;lparam")
        If $hCBReg = 0 Then Return SetError(2)
        DllCall("user32.dll", "int", "EnumChildWindows", "hwnd", _WinAPI_GetDesktopWindow(), "ptr", DllCallbackGetPtr($hCBReg), "lparam", 101)
        Local $iErr = @error
        DllCallbackFree($hCBReg)
        If $iErr Then
            Return SetError(3, $iErr, "")
        EndIf
        Return 2
    EndIf
EndFunc
While 1
    Sleep(10)
WEnd
Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

It's always best to link to where you found the code.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I have determined it is this bit:

DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32)

That is making it not work. Anyone know why?


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this:

Func _RightNowGUI()
    GuiDelete($RightNowGUI)
    GuiDelete($TodayGUI)
    GuiDelete($TonightGUI)
    GuiDelete($TomorrowGUI)
    $RightNowGUI = GUICreate("", 150, 300, $Width-151, $Height-600, BitOR($WS_POPUP,$WS_BORDER), Default, WinGetHandle(AutoItWinGetTitle()))
    GuiSetFont(13)
    GUICtrlSetDefColor(0xFFFFFF)
    GUISetBkColor(0x000000)
    WinSetTrans($RightNowGUI,"",200)
    GuiSetState()
    GuiCtrlCreateLabel($OverViewTime[1],38,10,200,50)
    GuiCtrlCreateLabel($OverViewStatus[1],55,128,200,40)
    GuiCtrlCreateLabel("Temperature",38,160,200,40)
    GuiCtrlCreateLabel($OverViewTemp[1] & "°F",64,185,200,40)
    GuiCtrlCreateLabel("Precipitation",34,220,200,40)
    GuiCtrlCreateLabel($OverViewPrecip[1],60,245,200,40)
    $ContextMenu = GuiCtrlCreateContextMenu()
    $RightNowItem = GuiCtrlCreateMenuItem($OverViewTime[1], $ContextMenu)
    GUICtrlSetOnEvent($RightNowItem, "_RightNowGUI")
    $TodayItem = GuiCtrlCreateMenuItem($OverViewTime[2], $ContextMenu)
    GUICtrlSetOnEvent($TodayItem, "_TodayGUI")
    $TonightItem = GuiCtrlCreateMenuItem($OverViewTime[3], $ContextMenu)
    GUICtrlSetOnEvent($TonightItem, "_TonightGUI")
    $TomorrowItem = GuiCtrlCreateMenuItem($OverViewTime[4], $ContextMenu)
    GUICtrlSetOnEvent($TomorrowItem, "_TomorrowGUI")
    $RefreshItem = GuiCtrlCreateMenuItem("Refresh", $ContextMenu)
    GUICtrlSetOnEvent($RefreshItem, "_Refresh")
    $ExitItem = GuiCtrlCreateMenuItem("Close", $ContextMenu)
    GUICtrlSetOnEvent($ExitItem, "_Exit")
    DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32)

    _GDIPlus_StartUp()
    $hImage   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image1.png")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($RightNowGUI)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 25, 300,300)
EndFunc

To avoid any erasing of the background pic I would suggest to use picture controls where you can load any image and send it to the pic control.

Btw, when you post only a fragment of your code we cannot test it properly because of missing variables, functions, etc.

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!
¯\_(ツ)_/¯

Share this post


Link to post
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
Sign in to follow this  
Followers 0