Jump to content
Sign in to follow this  

How do I control the size of the picture

Recommended Posts

I have this code and I want to control the size of the picture that is being showing on the GUI not matter how big the source of the picture is.

To draw the picture you just add the x and y position, but I would like a end position too.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <AD.au3>

Global $sUsername = 'shortname'


Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 300, $iHeight = 300, $iBgColor = 0xFFE8FF ;$iBgColor format RRGGBB

    Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $hGUI) ;set GUI background color

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    Local $hBitmap = _GDIPlus_BitmapCreateFromMemory(_ADO_USERIMAGE($sUsername)) ;load binary saved GIF image and convert it to GDI+ bitmap format
    if Not @error Then
    Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap)
        MsgBox(0, $iW, $iH)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 15, 20) ;display image in GUI
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
EndFunc   ;==>Example

Func _ADO_USERIMAGE($sUsename)
        Local $oADO_USERIMAGE = _AD_GetObjectAttribute($sUseName, 'thumbnailPhoto')
            If @error Then Exit
    Return $oADO_USERIMAGE


Yours sincerely


Share this post

Link to post
Share on other sites

Very easy, here an example :

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>

Local $Form = GUICreate("Test Resize", 500, 500)
Local $Pic = GUICtrlCreatePic("", 100, 100, 300, 300)


$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
$hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
$hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

_SetBitmapToCtrl($Pic, $hBitmap)

;Clean up and shutdown GDIPlus.

While 1

  Switch GUIGetMsg()



; ============================================

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
  Local Const $SS_IMAGE_BITMAP = 0

  Local $hWnd = GUICtrlGetHandle($CtrlId)
  If $hWnd = 0 Then Return SetError(1, 0, 0)

  _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
  If @error Then Return SetError(4, 0, 0)
  Return 1

EndFunc   ;==>_SetBitmapToCtrl


Share this post

Link to post
Share on other sites

I get an undefined function error on : _SetBitmapToCtrl(): undefined function.

EDIT: Never mind. I should have copied all code before trying. Doh.


Edited by Valnurat

Yours sincerely


Share this post

Link to post
Share on other sites

If I use your example in my code I get:

warning: $STM_SETIMAGE: possibly used before declaration.


error: $STM_SETIMAGE: undeclared global variable

But in your example I don't get these.

Do you know why?


Yours sincerely


Share this post

Link to post
Share on other sites

$STM_SETIMAGE is a constant declared in StaticConstants.au3 which is included in Constants.au3.  Include either one of those in your script...

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.23 contains 203 functions divided into these topics:
      window, desktop and monitor mouse and GUI GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By MiKa666
      Hi all,
      I'm developing a tool for exploratively testing another software. For that I wanna cover all the GUI functionality from that software and verify everything works as intended. But now I've a problem which I couldnt solve so far.
      One thing that software I'm testing does, is to load up either a single picture or a series of pictures. Depending on how much pictures got loaded, further actions will be proceeded...
      This loaded pictures are schon within a ToolbarWindow and they're clickable. What I need to know is, how much pictures are in this ToolbarWindow...
      Can anybody provide me a tip on how to achive this?
      Would be amazing!!
    • By meety
      wingettext function can get the text content of the IE browser page, but the text content of the page cannot be obtained in the chrome browser? What should I do?
    • By DirtyJohny
      Hi everyone.Need rewrite this function how in еxample.
      #RequireAdmin #NoTrayIcon Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next MsgBox(262144,'Monitors '&$lss.Count,$sss&" "&@CR) $lss=Null $sls=Null EndFunc _a() Example:
      Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) If IsObj($ObjService) Then For $objItemMB In $ObjMB $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF I'm beginner in this sphere and need  you all speak easy and simply because i'm Russian.Thanks)
    • By Deshanur
      Am trying to automate injecting credential on the login form for all kind of Web application for IE. I know how to identify the form name by viewing the source code and using the method - _IEFormGetObjByName($ie, $form_Name).
      I would like to know how to identify or get the form object for the web app where there is no form name tag for example below, for the is I have used - _IEFormGetCollection($ie, 0) to get the form object.
      My Question is does it work for all kind of application "_IEFormGetCollection($ie, 0)" how to identify Index value? is it always 0? is there any better solution?
      The final solution am looking for is find out form object, get the username, password field and inject credential and submit the form.
      How to find out index value? for the forms which does not have form name field.
      $login_form = _IEFormGetCollection($ie, 0) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}") OR This works fine if the form has form name. $login_form = _IEFormGetObjByName($ie, $form_Name) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}")
  • Create New...