Sign in to follow this  
Followers 0
BoonPek

Grouping multiple images into one control.

6 posts in this topic

Hi there!

Currently, I have a script which does this:

Do
  GUICtrlCreatePic($imgDir & "\grass.gif", $bM,  455, 128, 25)
  GUICtrlSetState(-1, $GUI_DISABLE)
  GUICtrlSetResizing(-1, 840)
  $bM += 128
Until $bM > @DesktopWidth

It works fine, but it involved the looping of an image over the GUI. Is there a way to make it so that it's one sinle control and not multiple controls?

I'd like to be able to hide that whole segment using GUICtrlSetState, and with its' current setup it doesn't seem possible.

Thanks for any input!

Extras: grass.gif is 128x25


Share this post


Link to post
Share on other sites



This is the only way that i figured out... Say thanks to the GDI genius of the forum UEZ he give me the tools to achieve this :mellow:

I am sure that there is several ways to do this, this is one of them.

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
Global Const $STM_SETIMAGE = 0x172
;~ $img = @ScriptDir & "\bot2.bmp"
;~ InetGet("http://www.mediafire.com/imgbnc.php/c83b527a400083eedd4f6958da2d9f6f1db83d5f6513f59045fae80a37df1e276g.jpg", $img)
$img = FileOpenDialog("Select an Image", @ScriptDir, "Images (*.jpg;*.bmp;*.gif)")
$GUI = GUICreate("Tile Image")
$Pic = GUICtrlCreatePic("", 0, 0, 400, 400)
_SetTiledPic($GUI, $Pic, $img)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
Do
Until GUIGetMsg() = -3
Func _SetTiledPic($hGUI, $iPic, $sImg)
Local $hPic = GUICtrlGetHandle($iPic)
Local $aSize = ControlGetPos($hGUI, "", $iPic)
Local $iPicWidth = $aSize[2]
Local $iPicHeight = $aSize[3]
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($sImg)
Local $iImageWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iImageHeight = _GDIPlus_ImageGetHeight($hImage)
Local $hBMP = _GDIPlus_BitmapCreateFromScan0($iPicWidth, $iPicHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMP)
Local $x = 0
Local $y = 0
Do
  If $x > $iPicWidth Then
   $x = 0
   $y += $iImageHeight
  EndIf
  _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $x, $y, $iImageWidth, $iImageHeight)
  $x += $iImageWidth
Until $y > $iPicHeight And $x > $iPicWidth
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP, 0x00000000)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hBMP)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc   ;==>_SetTiledPic
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, GDIPlus and GUICtrlSendMsg,

#include <GDIPlus.au3>
 
Global $ImgPath =  @ProgramFilesDir & "\AutoIt3\Examples\GUI\logo4.gif"
Local $hGui, $iPic, $hGraphic, $hBitmap, $hImage
 
$hGui = GUICreate("", @DesktopWidth, 480)
$iPic = GUICtrlCreatePic("", 0,  455, @DesktopWidth, 25)
 
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, 25, $hGraphic)
_GDIPlus_GraphicsDispose($hGraphic)
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hBitmap)
$hImage = _GDIPlus_ImageLoadFromFile ($ImgPath)
For $i = 0 To @DesktopWidth - 128 Step 128
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $i, 0, 128, 25)
Next
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
$hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hImage))
_GDIPlus_ShutDown()
 
GUISetState(@SW_SHOW, $hGui)
 
While GUIGetMsg() <> -3
WEnd

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

Doh my post was to slow..lol, nvm

Share this post


Link to post
Share on other sites

Doh my post was to slow..lol, nvm

jaja you have been a while, i saw you down there :mellow:

Share this post


Link to post
Share on other sites

This is the only way that i figured out... Say thanks to the GDI genius of the forum UEZ he give me the tools to achieve this :mellow:

I am sure that there is several ways to do this, this is one of them.

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
Global Const $STM_SETIMAGE = 0x172
;~ $img = @ScriptDir & "\bot2.bmp"
;~ InetGet("http://www.mediafire.com/imgbnc.php/c83b527a400083eedd4f6958da2d9f6f1db83d5f6513f59045fae80a37df1e276g.jpg", $img)
$img = FileOpenDialog("Select an Image", @ScriptDir, "Images (*.jpg;*.bmp;*.gif)")
$GUI = GUICreate("Tile Image")
$Pic = GUICtrlCreatePic("", 0, 0, 400, 400)
_SetTiledPic($GUI, $Pic, $img)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
Do
Until GUIGetMsg() = -3
Func _SetTiledPic($hGUI, $iPic, $sImg)
Local $hPic = GUICtrlGetHandle($iPic)
Local $aSize = ControlGetPos($hGUI, "", $iPic)
Local $iPicWidth = $aSize[2]
Local $iPicHeight = $aSize[3]
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($sImg)
Local $iImageWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iImageHeight = _GDIPlus_ImageGetHeight($hImage)
Local $hBMP = _GDIPlus_BitmapCreateFromScan0($iPicWidth, $iPicHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMP)
Local $x = 0
Local $y = 0
Do
  If $x > $iPicWidth Then
   $x = 0
   $y += $iImageHeight
  EndIf
  _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $x, $y, $iImageWidth, $iImageHeight)
  $x += $iImageWidth
Until $y > $iPicHeight And $x > $iPicWidth
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP, 0x00000000)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hBMP)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc   ;==>_SetTiledPic
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Hi, GDIPlus and GUICtrlSendMsg,

#include <GDIPlus.au3>
 
Global $ImgPath =  @ProgramFilesDir & "\AutoIt3\Examples\GUI\logo4.gif"
Local $hGui, $iPic, $hGraphic, $hBitmap, $hImage
 
$hGui = GUICreate("", @DesktopWidth, 480)
$iPic = GUICtrlCreatePic("", 0,  455, @DesktopWidth, 25)
 
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, 25, $hGraphic)
_GDIPlus_GraphicsDispose($hGraphic)
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hBitmap)
$hImage = _GDIPlus_ImageLoadFromFile ($ImgPath)
For $i = 0 To @DesktopWidth - 128 Step 128
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $i, 0, 128, 25)
Next
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
$hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hImage))
_GDIPlus_ShutDown()
 
GUISetState(@SW_SHOW, $hGui)
 
While GUIGetMsg() <> -3
WEnd

Cheers

Excellent! This works as intended, thank you! :)


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