Что нового

Изменение размера картинки в графическом ProgressBar'e

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
410
Не получается изменить размеры, точнее картинка при изменении размера прячется за другие и мелькает, подскажите как исправить? в коде пример как должен выглядеть прогресс, всё что нужно изменить в коде я указал коментариями.

Код:
#Include <WindowsConstants.au3>
#Include <GDIPlus.au3>
#Include <Memory.au3>
#Include <WinAPIEx.au3>

Global $LeftBitmap = '0xFFD8FFE000104A46494600010101006000600000FFE1006C45786966000049492A000800000004001A010500010000003E0000001B010500010000004600000028010300010000000200000031010200150000004E000000000000000B770100E80300000B770100E80300005061696E742E4E4554203F3F3F3F3F3F20332E3500FFFFDB0043000201010101010201010102020202020403020202020504040304060506060605060606070908060709070606080B08090A0A0A0A0A06080B0C0B0A0C090A0A0AFFDB004301020202020202050303050A0706070A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0AFFC0001108001E000403012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E17F681FDA6FE2D785BE3B78CFC3963F173C536D05978A2FE2B7B6B7F105CA471462E1C2A2AAB80AA060003800515E51FB5E5978CE5FDA93E213E91E14D4EEADFF00E12FBFF2E7B7B091D1BF7ED9C328C1E723F0A2BD88C63CAB403EA2F157836D757F881E2BD4658D4B49E31D5F24FB5F4C3FA515E9DE22FD963E3E5C78AF5AD4F41D4BC27F62BFD76FAF6D7ED3A9DCA48239EE64994385B660180700E091C7534564A765603FFFD9'
Global $CenterBitmap = '0xFFD8FFE000104A46494600010101006000600000FFE1006C45786966000049492A000800000004001A010500010000003E0000001B010500010000004600000028010300010000000200000031010200150000004E000000000000000B770100E80300000B770100E80300005061696E742E4E4554203F3F3F3F3F3F20332E3500FFFFDB0043000201010101010201010102020202020403020202020504040304060506060605060606070908060709070606080B08090A0A0A0A0A06080B0C0B0A0C090A0A0AFFDB004301020202020202050303050A0706070A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0AFFC0001108001E000403012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00F18FF86BDF8D1FF45B3C63FF00852DD7FF001CA2BC43FB2FE247FD085ADFFE0AA6FF00E268AF6B921D80FB87FE15F59FF77F9515E95FF0CA3FB4A7FD04BC1BFF00837BBFFE44A2A3DB400FFFD9'
Global $RfightBitmap = '0xFFD8FFE000104A46494600010101006000600000FFE1006C45786966000049492A000800000004001A010500010000003E0000001B010500010000004600000028010300010000000200000031010200150000004E000000000000000B770100E80300000B770100E80300005061696E742E4E4554203F3F3F3F3F3F20332E3500FFFFDB0043000201010101010201010102020202020403020202020504040304060506060605060606070908060709070606080B08090A0A0A0A0A06080B0C0B0A0C090A0A0AFFDB004301020202020202050303050A0706070A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0AFFC0001108001E000403012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00F75FF827078F7C53F127E04EA3E23F15F89F52D5A71E28B88A2B9D52FA49E458D6DEDC840D21242E4B1C74CB1F5A2B07FE09170EA09FB2DDEA6AD633DB5C0F17DDF9905C4451D7F716F8CAB0C8E307F1A2BBA76527603B3FD85ACD346F87FE26D3A3002C7E3193007BD8D99FEB4574BFB35FC2DF19FC29F0A6ADA678EAE74C96F751D75AF57FB2A79248D6336D6F0804C91A1DD9849E98E47345293BBB81FFD9'
Global $BarBitmap = '0xFFD8FFE000104A46494600010101006000600000FFE1006C45786966000049492A000800000004001A010500010000003E0000001B010500010000004600000028010300010000000200000031010200150000004E000000000000000B770100E80300000B770100E80300005061696E742E4E4554203F3F3F3F3F3F20332E35009EFFDB0043000201010101010201010102020202020403020202020504040304060506060605060606070908060709070606080B08090A0A0A0A0A06080B0C0B0A0C090A0A0AFFDB004301020202020202050303050A0706070A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0AFFC0001108001A000403012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00EB7FE17A6A5FF3F03FEFBA2BC6FF00E1497C68FF00A0CE8FFF008153FF00F1AA2BF903EB39AFFCFC7F7B3E7FEB953B9F717FC3382FFCFA9FFBF668AFAC7EC567FF003E917FDFB1457ADFD9B3FF009F9F87FC127D923FFFD9'
Global $Control

$hForm = GUICreate('MyGUI', 400, 300)
$hProgress = GUICtrlProgress_Create(20, 60, 200, 20)
GUISetState()

For $i = 0 To 200 Step 1
	;GUICtrlProgress_SetPos($hForm, $hProgress, $i)
    Sleep(20)
Next	

Do
Until GUIGetMsg() = -3

Func GUICtrlProgress_Create($iX, $iY, $iWeight, $iHeight)

	Local $Left = GUICtrlCreatePic("", $iX, $iY, 4, $iHeight)
	_WinAPI_CreateBinaryImage(GUICtrlGetHandle($Left), $LeftBitmap, 4, $iHeight)
	GUICtrlSetState($Left, 128)
	
	Local $Center = GUICtrlCreatePic("", $iX + 4, $iY, $iWeight - 8, $iHeight)
    _WinAPI_CreateBinaryImage(GUICtrlGetHandle($Center), $CenterBitmap, $iWeight - 8, $iHeight)
	GUICtrlSetState($Center, 128)
	
	Local $Right = GUICtrlCreatePic("", ($iX + 4) + ($iWeight - 8), $iY, 4, $iHeight)
	_WinAPI_CreateBinaryImage(GUICtrlGetHandle($Right), $RfightBitmap, 4, $iHeight)
	GUICtrlSetState($Right, 128)
	
    Local $Bar = GUICtrlCreatePic("", $iX + 2, $iY + 2, 100, $iHeight - 4) ; стираем 100 и ставим 0
    _WinAPI_CreateBinaryImage(GUICtrlGetHandle($Bar), $BarBitmap, 100, $iHeight - 4) ; полностью стираем
	
	GUIRegisterMsg($WM_USER + 1, "ProgressPos") ; Зарегистрировали сообщение
	$Control = $Bar
	Return $Bar
EndFunc 

Func GUICtrlProgress_SetPos($hWnd, $iCtrl, $iPos)
	If $iPos >= 100 Then $iPos = 100 
	DllCall("user32.dll", "lresult", "SendMessageA", "hwnd", $hWnd, "uint", $WM_USER + 1, "wParam", $iPos, "lParam", 0) ; Получаем значение $iPos и отправляем в окно
EndFunc

Func ProgressPos($hWnd, $iMsg, $wParam, $lParam) ; Обработка сообщений
	Local $Size = ControlGetPos($hWnd, "", $Control)
	GUICtrlSetPos($Control, $Size[0], $Size[1], Number($wParam), $Size[3])
	_WinAPI_CreateBinaryImage($Control, $BarBitmap, Number($wParam), $Size[3]) ; Отсылает картинку на $Bar с нужными размерами
EndFunc	

Func _WinAPI_CreateBinaryImage($iCtrl, $hBinary, $hWeight, $hHeight)
	Local $nSize = BinaryLen($hBinary)
	Local $pStruct = DllStructCreate("byte[" & $nSize & "]")
	DllStructSetData($pStruct, 1, $hBinary)
	$Pointer = DllStructGetPtr($pStruct)
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer, $pData, $nSize)
	$pStruct = ""
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
	$Image = _WinAPI_ResizeBitmap($hBitmap, $hWeight, $hHeight)
    _WinAPI_PostMessage($iCtrl, 0x0172, 0, $Image)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc
 
Верх