PDA

Показать полную графическую версию : Картинки в окне, переключатель.


semiono
19-01-2011, 19:01
Нужно зделать окно 300x500 пикселей примерно, на окне разместить ComboBox() и пару квадратиков bmp, хотя лучше png.
Вообщем чтоб квадратики менять местами, левый на правый итп. через ComboBox[здесь некое название]
Я предпологаю далее зделать большее число квадратов на окне, заранее говорю чтоб было можно программу усложнить.
Ну вроде шахматных фигур нечто такое...
А конкретно это справочник гитарных аккордов будет... шесть на восемь картинок...
Мне только заготовка нужна для начала.

А вот картинки потом я надеюсь можно вкампилировать в exe? Хотелось бы одним файлом это зделать.

Из хелпа не ясно лишь как привязать "смену событий" к GUICtrlCreateCombo
Как мне через GUICtrlSetData() менять картинки (X Y)

Вот пока контрол нарисовал только...

#include <GUIConstantsEx.au3>

GUICreate('Chords',200,300)

GUICtrlCreateCombo('item1',10,10,180)
GUICtrlSetData(-1,'item2|item3','item3')

GUISetState()

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Как мне получить результат нажатия GUICtrlSetData ?

madmasles
19-01-2011, 20:08
не ясно лишь как привязать "смену событий" к GUICtrlCreateCombo »#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>

$sDefault = 'item2'
$hGui = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Chords', 200, 300)
$hCombo = GUICtrlCreateCombo (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateCombo.htm)('', 10, 30, 180)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)(-1, 'item1|item2|item3|item4|item5|item6', $sDefault)
$hLabel = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)($sDefault, 10, 5, 180)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hCombo
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($hLabel, GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($hCombo))
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
хотя лучше png »
По поводу картинок: Поддержка иконок и изображений, содержащих прозрачность (Alpha канал) (http://autoit-script.ru/index.php?topic=49.0). Смотрите пример № 6.

Чтобы картинки записать в ресурсы exe-шника: FAQ по использованию ресурсов в AutoIt (http://autoit-script.ru/index.php?topic=2849.0)

semiono
19-01-2011, 20:29
madmasles, может сразу напишешь пример, два квадрата BMP и местами (x, y) их поменять (GUICtrlSetData item1 item2)
ато я While/If/Than буду долго думать, я логически плохо умею мыслить. )

madmasles
19-01-2011, 21:22
semiono,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Icons.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <StaticConstants.au3>

Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $sRed = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\red.png'
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $sGreen = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\green.png'
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $sBlue = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\blue.png'
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $sYellow = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\yellow.png'
$sDefault = 'Красный'

$hRed = _Icons_Bitmap_Load($sRed)
$hGreen = _Icons_Bitmap_Load($sGreen)
$hBlue = _Icons_Bitmap_Load($sBlue)
$hYellow = _Icons_Bitmap_Load($sYellow)


$hGui = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Chords', 300, 340)
$hCombo = GUICtrlCreateCombo (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateCombo.htm)('', 10, 30, 280)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)(-1, 'Синий|Зеленый|Красный|Желтый', $sDefault)
$hLabel = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('По умолчанию: ' & $sDefault, 10, 5, 280, 16, $SS_CENTER)
$hPic = GUICtrlCreatePic (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreatePic.htm)('', 22, 70, 256, 256)
_SetHImage($hPic, $hRed)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hCombo
$sFromCombo = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($hCombo)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($hLabel, 'Вы выбрали: ' & $sFromCombo)
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $sFromCombo
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) 'Красный'
_SetHImage($hPic, $hRed)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) 'Зеленый'
_SetHImage($hPic, $hGreen)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) 'Синий'
_SetHImage($hPic, $hBlue)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) 'Желтый'
_SetHImage($hPic, $hYellow)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Ссылка на библиотеку Icons.au3 в моем предыдущем посту. Не забудьте про нее. Картинки в прикрепленном архиве.

semiono
19-01-2011, 21:53
Красиво! :)
---
Чтоб я вообще сам не думал, а где подправить, чтоб две картинки были одновременно рядом?

http://upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Chess_rdl44.png/26px-Chess_rdl44.pnghttp://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Chess_ndd44.png/26px-Chess_ndd44.png

или вот ещё пример:

http://b.imagehost.org/0418/Snap1.png

Впрочем попробую самостоятельно испортить Ваш код... ))

madmasles
19-01-2011, 22:47
чтоб две картинки были одновременно рядом »
Вот Вам пример с 4-мя картинками рядом:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <EditConstants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Icons.au3>

Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $aPic[10] = [@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\0.png', @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\1.png', @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\2.png', _
@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\3.png', @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\4.png', @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\5.png', _
@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\6.png', @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\7.png', @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\8.png', _
@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\9.png']
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $aPicControl[5] = [4]


$hGui = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Счетчик', 250, 250, -1, -1)
$hInput = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)('', 100, 10, 50, 18, BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($ES_NUMBER, $ES_CENTER, $ES_READONLY))
GUICtrlSetLimit (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetLimit.htm)(-1, 4)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aPicControl[0]
$aPicControl[$i] = GUICtrlCreatePic (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreatePic.htm)('', 77 + ($i - 1) * 24, 50, 24, 28)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)(-1, $GUI_DISABLE)
_SetImage($aPicControl[$i], $aPic[0])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
$hButton = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Вперед', 100, 150, 50, 22)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hButton
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)($hButton, $GUI_DISABLE)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($hInput, Random (http://www.autoitscript.com/autoit3/docs/functions/Random.htm)(1000, 9999, 1))
_Set_Number(GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($hInput))
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)($hButton, $GUI_ENABLE)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Set_Number($n)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aNumber
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 4
_SetImage($aPicControl[$i], $aPic[0])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100)
$n = StringFormat (http://www.autoitscript.com/autoit3/docs/functions/StringFormat.htm)('%04d', $n)
$aNumber = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($n, '')
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aPicControl[0]
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $j = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aNumber[$i]
_SetImage($aPicControl[$i], $aPic[$j])
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(150)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>_Set_Number

semiono
19-01-2011, 23:18
Я уже сам немного продвинулся в этом ))
$hPic1 = GUICtrlCreatePic('', 22, 70, 256, 256)
$hPic2 = GUICtrlCreatePic('', 220, 70, 256, 256)
_SetHImage($hPic1, $hRed)
_SetHImage($hPic2, $hGreen)
...
Case '1'
_SetHImage($hPic1, $hRed)
_SetHImage($hPic2, $hGreen)
Case '2'
_SetHImage($hPic1, $hGreen)
_SetHImage($hPic2, $hRed)
Case '3'
_SetHImage($hPic1, $hBlue)
_SetHImage($hPic2, $hYellow)
Case '4'
_SetHImage($hPic1, $hYellow)
_SetHImage($hPic2, $hRed)
Когда у меня будет таблица 6x8 картинок, я уже представил как там запутаться можно! )))

madmasles, однако Вы усложняете! Пример замечательный, хотя мне в нём всё менее понятно стало )))
Только казалось я был близок к пониманию.




© OSzone.net 2001-2012