PDA

Показать полную графическую версию : [решено] работа с _GUIImageList_Create, обработка событий


andr_mozg
15-03-2011, 11:06
Не могу обработать событие о том что выбран какой-то элемент..
то есть создаю _GUICtrlListView_Create
потом, _GUIImageList_Create

добавляю _GUICtrlListView_InsertItem

после этого мне необходимо проверять что выбран какойто элемент.



While 1
$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE
exit

Case ??????
MsgBox(0,"","ok")

EndSelect

WEnd

Creat0R
15-03-2011, 13:42
необходимо проверять что выбран какойто элемент »
Тут Case'ом не обойтись.

Нужно делать так:

#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIListView.au3>

Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $bItemChanged = False (http://www.autoitscript.com/autoit3/docs/keywords.htm#False)

$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("(Internal) ListView Get Item Text", 400, 300)

$hListView = _GUICtrlListView_Create (http://dundats.mvps.org/help/html/libfunctions/_guictrllistview_create.htm)($hGUI, "Items", 2, 2, 394, 268)

_GUICtrlListView_InsertItem (http://dundats.mvps.org/help/html/libfunctions/_guictrllistview_insertitem.htm)($hListView, "Item 1")
_GUICtrlListView_InsertItem (http://dundats.mvps.org/help/html/libfunctions/_guictrllistview_insertitem.htm)($hListView, "Item 2")
_GUICtrlListView_InsertItem (http://dundats.mvps.org/help/html/libfunctions/_guictrllistview_insertitem.htm)($hListView, "Item 3")

GUIRegisterMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm)($WM_NOTIFY, "WM_NOTIFY")
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $bItemChanged Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$bItemChanged = False (http://www.autoitscript.com/autoit3/docs/keywords.htm#False)

$iIndx = _GUICtrlListView_GetSelectedIndices (http://dundats.mvps.org/help/html/libfunctions/_guictrllistview_getselectedindices.htm)($hListView)
ConsoleWrite (http://www.autoitscript.com/autoit3/docs/functions/ConsoleWrite.htm)('Item changed: ' & _GUICtrlListView_GetItemText (http://dundats.mvps.org/help/html/libfunctions/_guictrllistview_getitemtext.htm)($hListView, Number (http://www.autoitscript.com/autoit3/docs/functions/Number.htm)($iIndx)) & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf))
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)


Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
$hWndListView = $hListView
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) IsHWnd (http://www.autoitscript.com/autoit3/docs/functions/IsHWnd.htm)($hListView) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $hWndListView = GUICtrlGetHandle (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlGetHandle.htm)($hListView)

$tNMHDR = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMHDR, $ilParam)
$hWndFrom = HWnd (http://www.autoitscript.com/autoit3/docs/functions/HWnd.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "IDFrom")
$iCode = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "Code")

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $hWndFrom
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hWndListView
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iCode
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $LVN_HOTTRACK; Sent by a list-view control when the user moves the mouse over an item

Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $LVN_ITEMCHANGED, $NM_CLICK ; An item has changed/clicked
$bItemChanged = True (http://www.autoitscript.com/autoit3/docs/keywords.htm#True)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $LVN_ITEMCHANGING; An item is changing
;Return True; prevent the change
;Return False; allow the change
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $GUI_RUNDEFMSG
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

andr_mozg
15-03-2011, 14:40
спасибо..все заработало...




© OSzone.net 2001-2012