Что нового

GUICreateFromImage - Создание GUI с (можно прозрачной) картинки

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8 164
Репутация
2 329
Может будет кому то полезно:

Код:
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPISys.au3>

$ahGUI = _GUICreateFromImage('My GUI', 'GUI.png', 235, -2, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

$iButton1 = GUICtrlCreateButton('Button1', 20, $ahGUI[3] - 30, 70, 20)
$iButton2 = GUICtrlCreateButton('Button2', $ahGUI[2] - 90, $ahGUI[3] - 30, 70, 20)

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE, $iButton1, $iButton2
			Exit
	EndSwitch
WEnd

;Returns Array:
;[0] - Parent GUI
;[1] - Child GUI (where the controls are stored)
;[2] - GUI width (from image)
;[3] - GUI height (from image)
Func _GUICreateFromImage($sTitle, $sPngFile, $iOpacity = 255, $iLeft = -1, $iTop = -1, $iStyle = -1, $iExStyle = -1, $hWnd = 0)
	_GDIPlus_Startup()
	
	Local $hImage = _GDIPlus_ImageLoadFromFile($sPngFile)
	Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
	Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
	
	If $iLeft = -2 Or $iTop = -2 Then
		$iLeft = 0
		$iTop = (@DesktopHeight - WinGetPos('[CLASS:Shell_TrayWnd]')[3]) - $iHeight
	EndIf
	
	Local $hParent = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR(($iStyle = -1 ? 0 : $iStyle), $WS_POPUP), BitOR(($iExStyle = -1 ? 0 : $iExStyle), $WS_EX_LAYERED))
	_WinAPI_UpdateLayeredWindowEx($hParent, $iLeft, $iTop, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), $iOpacity, True)
	
	_GDIPlus_ImageDispose($hImage)
	_GDIPlus_Shutdown()
	
	Local $sTrnsImage = @TempDir & '\trns_img.tmp'
	Local $sBin = '0x4749463839610100010010000021F90401000003002C0000000001000100870000000000330000660000990000CC0000FF002B00002B33002B66002B99002BCC002BFF0055000055330055660055990055CC0055FF0080000080330080660080990080CC0080FF00AA0000AA3300AA6600AA9900AACC00AAFF00D50000D53300D56600D59900D5CC00D5FF00FF0000FF3300FF6600FF9900FFCC00FFFF3300003300333300663300993300CC3300FF332B00332B33332B66332B99332BCC332BFF3355003355333355663355993355CC3355FF3380003380333380663380993380CC3380FF33AA0033AA3333AA6633AA9933AACC33AAFF33D50033D53333D56633D59933D5CC33D5FF33FF0033FF3333FF6633FF9933FFCC33FFFF6600006600336600666600996600CC6600FF662B00662B33662B66662B99662BCC662BFF6655006655336655666655996655CC6655FF6680006680336680666680996680CC6680FF66AA0066AA3366AA6666AA9966AACC66AAFF66D50066D53366D56666D59966D5CC66D5FF66FF0066FF3366FF6666FF9966FFCC66FFFF9900009900339900669900999900CC9900FF992B00992B33992B66992B99992BCC992BFF9955009955339955669955999955CC9955FF9980009980339980669980999980CC9980FF99AA0099AA3399AA6699AA9999AACC99AAFF99D50099D53399D56699D59999D5CC99D5FF99FF0099FF3399FF6699FF9999FFCC99FFFFCC0000CC0033CC0066CC0099CC00CCCC00FFCC2B00CC2B33CC2B66CC2B99CC2BCCCC2BFFCC5500CC5533CC5566CC5599CC55CCCC55FFCC8000CC8033CC8066CC8099CC80CCCC80FFCCAA00CCAA33CCAA66CCAA99CCAACCCCAAFFCCD500CCD533CCD566CCD599CCD5CCCCD5FFCCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFFFF0000FF0033FF0066FF0099FF00CCFF00FFFF2B00FF2B33FF2B66FF2B99FF2BCCFF2BFFFF5500FF5533FF5566FF5599FF55CCFF55FFFF8000FF8033FF8066FF8099FF80CCFF80FFFFAA00FFAA33FFAA66FFAA99FFAACCFFAAFFFFD500FFD533FFD566FFD599FFD5CCFFD5FFFFFF00FFFF33FFFF66FFFF99FFFFCCFFFFFF000000000000000000000000080400630404003B'
	
	Local $hFile = FileOpen($sTrnsImage, 18)
	FileWrite($hFile, $sBin)
	FileClose($hFile)
	
	Local $hChild = GUICreate($sTitle, $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hParent)
	GUICtrlCreatePic($sTrnsImage, 0, 0, $iWidth, $iHeight)
	GUICtrlSetState(-1, $GUI_DISABLE)
	FileDelete($sTrnsImage)
	
	GUISetState(@SW_SHOW, $hParent)
	GUISetState(@SW_SHOW, $hChild)
	
	Local $aRet[4] = [$hParent, $hChild, $iWidth, $iHeight]
	Return $aRet
EndFunc


Картинка для данного примера:
 
Верх