Войти

Показать полную графическую версию : [решено] Несколько WM_NOTIFY в одном скрипте


saavaage
07-09-2010, 11:26
Собственно, вопросы:
1. можно ли в одном скрипте (форма с Tab) применить несколько WM_NOTIFY
2. частный случай - не получается совместить работу двух WM_NOTIFY в скрипте следующего типа:

#include <Constants.au3>
#include <EditConstants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <DeviceAPI.au3>

; ErrorLogs
Global $hMain_GUI, $nErrorRenew_Button, $hInput, $hInputAll, $ListViewEv, $hListViewEv, $aErrorsNew

; DriversErrors
Global $aAssoc[1][2]


Opt("GUIOnEventMode", 1)

$hMain_GUI = GUICreate("Диагностика и Настройка XP SP3", 619, 442, 189, 122)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Tab1 = GUICtrlCreateTab(8, 16, 601, 377)
;;;; EventErrors ;;;;
Dim $aToList = __ErrorLog()
$EventErrors = GUICtrlCreateTabItem("EventErrors")
$nErrorRenew_Button = GUICtrlCreateButton("Обновить", 440, 400, 85, 33)
GUICtrlSetOnEvent($nErrorRenew_Button, "ErrorRenew_Button")

GUICtrlCreateGroup("Расшифровка кода ошибки", 16, 65, 585, 63)
$hInput = GUICtrlCreateEdit('', 24, 80, 570, 39, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$ListViewEv = GUICtrlCreateListView('Список Errors логов системы', 16, 133, 585, 169, -1, $LVS_EX_GRIDLINES)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateGroup("Полное описание выделенной ошибки", 16, 305, 585, 82)
$hInputAll = GUICtrlCreateEdit('', 24, 320, 570, 59, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY_Ev')

$hListViewEv = GUICtrlGetHandle($ListViewEv)
_GUICtrlListView_SetColumnWidth($hListViewEv, 0, 2000)
If $aToList <> 0 Then
_GUICtrlListView_AddColumn($hListViewEv, '')
For $i = 1 To UBound($aToList) - 1
_GUICtrlListView_AddItem($hListViewEv, $aToList[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf


;;; DriversErrors ;;;
$DriverErrors = GUICtrlCreateTabItem("DriversErrors")
Dim $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
$hTreeView = GUICtrlCreateTreeView(14, 45, 253, 337, $iStyle, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_FOCUS)
$hListView = GUICtrlCreateListView("Key|Value", 272, 45, 332, 337)

;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_Dr")

;Assign image list to treeview
_GUICtrlTreeView_SetNormalImageList($hTreeView, _DeviceAPI_GetClassImageList())

Dim $total_devices = 0

_DeviceAPI_GetClasses()
While _DeviceAPI_EnumClasses()

;Build list of devices within current class, if class doesn't contain any devices it will be skipped
_DeviceAPI_GetClassDevices($p_currentGUID)

;Skip classes without devices
If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) = '' Then


;Add parent class to treeview
$parent = _GUICtrlTreeView_Add($hTreeView, 0, _DeviceAPI_GetClassDescription($p_currentGUID))

;Loop through all devices by index
While _DeviceAPI_EnumDevices()

$description = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC)
$friendly_name = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME)

;If a friendly name is available, use it instead of description
If $friendly_name <> "" Then
$description = $friendly_name
EndIf


;Add device to treeview below parent
$handle = _GUICtrlTreeView_AddChild($hTreeView, $parent, $description)

If $total_devices > 0 Then
ReDim $aAssoc[$total_devices+1][2]
EndIf

;Add treeview item handle to array along with device Unique Instance Id (For lookup)
$aAssoc[$total_devices][0] = $handle
$aAssoc[$total_devices][1] = _DeviceAPI_GetDeviceId()

;Update running total count of devices
$total_devices += 1
WEnd
EndIf
WEnd

;Cleanup image list
_DeviceAPI_DestroyClassImageList()

_DeviceAPI_DestroyDeviceInfoList() ;Cleanup for good measure


GUICtrlCreateTabItem("")

GUISetState()

While 1
Sleep(100)
WEnd


Func CLOSEClicked()
Exit
EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ErrorsLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func ErrorRenew_Button()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
_GUICtrlListView_DeleteAllItems($hListViewEv)
GUICtrlSetData($hInput, '')
GUICtrlSetData($hInputAll, '')
$aErrorsNew = __ErrorLog()
If $aErrorsNew <>0 Then
For $i = 1 To UBound($aErrorsNew) - 1
_GUICtrlListView_AddItem($hListViewEv, $aErrorsNew[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf
sleep(1000)
GUICtrlSetState($nErrorRenew_Button, $GUI_ENABLE)
GUICtrlSetState($ListViewEv, $GUI_FOCUS)
EndFunc

Func WM_NOTIFY_Ev($EventErrors, $iMsg, $wParam, $lParam)
Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')
Switch $hFrom
Case $hListViewEv
Switch $ID
Case $LVN_ITEMCHANGED
If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And _
(BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
_ErrorHelp($Index)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func __ErrorLog()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
Local $sLog = '', $hError, $aErrorsTemp, $i
Dim $aErrors[1]
$hError = Run('CSCRIPT.exe ' & @SystemDir & '\eventquery.vbs /v /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hError)
If @error Then ExitLoop
; Sleep(10)
WEnd
If Not $sLog Then Return 0
$aErrorsTemp = StringSplit(_Encoding_866To1251($sLog), @LF)
If Not IsArray($aErrorsTemp) Then Return 0
Dim $aErrors[$aErrorsTemp[0]]
For $i = 1 To $aErrorsTemp[0]
If StringInStr($aErrorsTemp[$i], "ошибка") Then
$aErrors[0] += 1
$aErrors[$aErrors[0]] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
EndIf
Next
If $aErrors[0] < 1 Then Return 0
ReDim $aErrors[$aErrors[0]+1]
Return $aErrors
EndFunc ;==>__ErrorLog


Func _ErrorHelp($Index)
Local $iNumberError, $hHelp, $sLog = ''
GUICtrlSetState($hListViewEv, $GUI_DISABLE)
$sItemText = _GUICtrlListView_GetItemText($hListViewEv, $Index)
$iNumberError = StringRegExpReplace($sItemText, "(?s).*?ошибка (.*?)\s+?.*", '\1')
$hHelp = Run('net helpmsg ' & $iNumberError, '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hHelp)
If @error Then ExitLoop
;Sleep(10)
WEnd
$sLog = StringStripWS(StringStripCR(_Encoding_866To1251($sLog)), 7)
GUICtrlSetData($hInput, 'Ошибка № ' & $iNumberError & ' - ' & $sLog)
GUICtrlSetData($hInputAll, $sItemText)
GUICtrlSetState($hListViewEv, $GUI_ENABLE)
EndFunc ;==>_ErrorHelp

;; End ErrorLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func WM_NOTIFY_Dr($DriverErrors, $iMsg1, $iwParam1, $ilParam1)
#forceref $DriverErrors, $iMsg1, $iwParam1
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview

$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam1)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
RefreshDeviceProperties()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

;Triggered when a device is selected in the treeview
Func RefreshDeviceProperties()
Local $hSelected = _GUICtrlTreeView_GetSelection($hTreeView)

;Don't do anything if a class name (root item) was clicked
If _GUICtrlTreeView_Level($hTreeView, $hSelected) = 0 Then Return

;Lookup treeview item handle in global array
For $X = 0 to Ubound($aAssoc)-1

If $hSelected = $aAssoc[$X][0] Then
;MsgBox(0,"", "Handle: " & $aAssoc[$X][0] & @CRLF & "Unique Instance Id: " & $aAssoc[$X][1])

;Build list of ALL device classes
_DeviceAPI_GetClassDevices()

;Loop through all devices by index
While _DeviceAPI_EnumDevices()
If $aAssoc[$X][1] = _DeviceAPI_GetDeviceId() Then

;Empty listview
_GUICtrlListView_DeleteAllItems($hListView)

GUICtrlCreateListViewItem ("Hardware ID: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID), $hListView )
GUICtrlCreateListViewItem ("Unique Instance ID: |" & _DeviceAPI_GetDeviceId(), $hListView )
GUICtrlCreateListViewItem ("Manufacturer: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_MFG), $hListView )
GUICtrlCreateListViewItem ("Driver: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER), $hListView )
GUICtrlCreateListViewItem ("Friendly Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME), $hListView )
GUICtrlCreateListViewItem ("Physical Device Object Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_PHYSICAL_DEVICE_OBJECT_NAME), $hListView )
GUICtrlCreateListViewItem ("Upper Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_UPPERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Lower Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_LOWERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Enumerator: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_ENUMERATOR_NAME), $hListView )

;Resize columns to fit text
_GUICtrlListView_SetColumnWidth($hListView, 0,$LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 1,$LVSCW_AUTOSIZE)
EndIf
WEnd
EndIf
Next
EndFunc
;; End DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Проблема - текущий вариант позволяет работать скрипту на вкладке EventErrors (при выделении в listview строки в верхнем и нижнем полях автоматически выдается полное наименование и расшифровка ошибки) и блокирует работу скрипта на вкладке DriverErrors (при "раскрытии плюса" конкретного оборудования без драйверов нельзя в правом поле просмотреть детальную информацию по этому оборудованию).
В случае, когда я убираю комментирование строки ;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_Dr") блокируется работа полей подсказок на первой вкладке (EventErrors) и начинает корректно работать скрипт на DriverErrors

PS версия autoit 3.3.6.1

Creat0R
07-09-2010, 14:56
Обычно совмещают код в одной функций, но можно и такой трюк проделать:

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) WM_NOTIFY_Ev($EventErrors, $iMsg, $wParam, $lParam)
WM_NOTIFY_Dr($EventErrors, $iMsg, $wParam, $lParam)

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tNMITEMACTIVATE = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMITEMACTIVATE, $lParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hFrom = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'hWndFrom')
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $Index = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'Index')
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $ID = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'Code')
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $hFrom
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hListViewEv
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $ID
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $LVN_ITEMCHANGED
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) (BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) _
(BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) (Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
_ErrorHelp($Index)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
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)

т.е вызывать вторую функцию сообщения из первой (регистрировать нужно только первую).

saavaage
07-09-2010, 17:59
Creat0R, Func WM_NOTIFY_Ev($EventErrors, $iMsg, $wParam, $lParam)
WM_NOTIFY_Dr($EventErrors, $iMsg, $wParam, $lParam) »
почему и в одной и в другой функциях параметр $EventErrors. Имхо, вторая разве не должна быть записана так:
WM_NOTIFY_Dr($DriverErrors, $iMsg1, $iwParam1, $ilParam1)

Creat0R
07-09-2010, 22:48
почему и в одной и в другой функциях параметр $EventErrors »
А я знал что будет такой вопрос :)

Функций «WM_NOTIFY_Dr» будет передан параметр $hWnd, что такое $EventErrors или $DriverErrors я не знаю.

вторая разве не должна быть записана так »
И что, работает? а откуда берётся переменная $DriverErrors?

Func WM_NOTIFY_Ev($hWnd, $iMsg, $wParam, $lParam)
WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)

saavaage
07-09-2010, 23:41
Creat0R, не работает, конечно.
Вопрос по Обычно совмещают код в одной функций »:совмещение происходит через case? Приблизительно так?:

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$hWndListViewEv = $hListViewEv
$hWndTreeViewDr = $hTreeViewDr
If Not IsHWnd($hTreeViewDr) Then $hWndTreeviewDr = GUICtrlGetHandle($hTreeViewDr)

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeviewDr
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
RefreshDeviceProperties()
EndSwitch

Case $hWndListViewEv
Switch $iCode
Case $LVN_ITEMCHANGED
If (BitAND(DllStructGetData($tNMHDR, 'Changed'), $LVIF_STATE)) And _
(BitAND(DllStructGetData($tNMHDR, 'NewState'), $LVIS_SELECTED)) _
And (Not BitAND(DllStructGetData($tNMHDR, 'OldState'), $LVIS_FOCUSED)) Then
_ErrorHelp($iIDFrom)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

saavaage
07-09-2010, 23:58
Creat0R, изменил скрипт в шапке в соответствии с Вашим советом, но вкладка DriverErrors по прежнему не работает :sorry: .
Вот, что у меня получилось:
#include <Constants.au3>
#include <EditConstants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <DeviceAPI.au3>

; ErrorLogs
Global $hMain_GUI, $nErrorRenew_Button, $hInput, $hInputAll, $ListViewEv, $hListViewEv, $aErrorsNew

; DriversErrors
Global $aAssoc[1][2]
;Global $hTreeView

Opt("GUIOnEventMode", 1)

$hMain_GUI = GUICreate("Диагностика и Настройка XP SP3", 619, 442, 189, 122)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Tab1 = GUICtrlCreateTab(8, 16, 601, 377)
;;;; EventErrors ;;;;
Dim $aToList = __ErrorLog()
$EventErrors = GUICtrlCreateTabItem("EventErrors")
$nErrorRenew_Button = GUICtrlCreateButton("Обновить", 440, 400, 85, 33)
GUICtrlSetOnEvent($nErrorRenew_Button, "ErrorRenew_Button")

GUICtrlCreateGroup("Расшифровка кода ошибки", 16, 65, 585, 63)
$hInput = GUICtrlCreateEdit('', 24, 80, 570, 39, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$ListViewEv = GUICtrlCreateListView('Список Errors логов системы', 16, 133, 585, 169, -1, $LVS_EX_GRIDLINES)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateGroup("Полное описание выделенной ошибки", 16, 305, 585, 82)
$hInputAll = GUICtrlCreateEdit('', 24, 320, 570, 59, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY_Ev')

$hListViewEv = GUICtrlGetHandle($ListViewEv)
_GUICtrlListView_SetColumnWidth($hListViewEv, 0, 2000)
If $aToList <> 0 Then
_GUICtrlListView_AddColumn($hListViewEv, '')
For $i = 1 To UBound($aToList) - 1
_GUICtrlListView_AddItem($hListViewEv, $aToList[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf


;;; DriversErrors ;;;
$DriverErrors = GUICtrlCreateTabItem("DriversErrors")
Dim $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
$hTreeView = GUICtrlCreateTreeView(14, 45, 253, 337, $iStyle, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_FOCUS)
$hListView = GUICtrlCreateListView("Key|Value", 272, 45, 332, 337)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_Ev")

;Assign image list to treeview
_GUICtrlTreeView_SetNormalImageList($hTreeView, _DeviceAPI_GetClassImageList())

Dim $total_devices = 0

_DeviceAPI_GetClasses()
While _DeviceAPI_EnumClasses()

;Build list of devices within current class, if class doesn't contain any devices it will be skipped
_DeviceAPI_GetClassDevices($p_currentGUID)

;Skip classes without devices
If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) = '' Then


;Add parent class to treeview
$parent = _GUICtrlTreeView_Add($hTreeView, 0, _DeviceAPI_GetClassDescription($p_currentGUID))

;Loop through all devices by index
While _DeviceAPI_EnumDevices()

$description = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC)
$friendly_name = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME)

;If a friendly name is available, use it instead of description
If $friendly_name <> "" Then
$description = $friendly_name
EndIf


;Add device to treeview below parent
$handle = _GUICtrlTreeView_AddChild($hTreeView, $parent, $description)

If $total_devices > 0 Then
ReDim $aAssoc[$total_devices+1][2]
EndIf

;Add treeview item handle to array along with device Unique Instance Id (For lookup)
$aAssoc[$total_devices][0] = $handle
$aAssoc[$total_devices][1] = _DeviceAPI_GetDeviceId()

;Update running total count of devices
$total_devices += 1
WEnd
EndIf
WEnd

;Cleanup image list
_DeviceAPI_DestroyClassImageList()

_DeviceAPI_DestroyDeviceInfoList() ;Cleanup for good measure


GUICtrlCreateTabItem("")

GUISetState()

While 1
Sleep(100)
WEnd


Func CLOSEClicked()
Exit
EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ErrorsLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func ErrorRenew_Button()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
_GUICtrlListView_DeleteAllItems($hListViewEv)
GUICtrlSetData($hInput, '')
GUICtrlSetData($hInputAll, '')
$aErrorsNew = __ErrorLog()
If $aErrorsNew <>0 Then
For $i = 1 To UBound($aErrorsNew) - 1
_GUICtrlListView_AddItem($hListViewEv, $aErrorsNew[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf
sleep(1000)
GUICtrlSetState($nErrorRenew_Button, $GUI_ENABLE)
GUICtrlSetState($ListViewEv, $GUI_FOCUS)
EndFunc

Func WM_NOTIFY_Ev($hWnd, $iMsg, $wParam, $lParam)
WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)
Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')
Switch $hFrom
Case $hListViewEv
Switch $ID
Case $LVN_ITEMCHANGED
If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And _
(BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
_ErrorHelp($Index)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc

Func __ErrorLog()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
Local $sLog = '', $hError, $aErrorsTemp, $i
Dim $aErrors[1]
$hError = Run('CSCRIPT.exe ' & @SystemDir & '\eventquery.vbs /v /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hError)
If @error Then ExitLoop
; Sleep(10)
WEnd
If Not $sLog Then Return 0
$aErrorsTemp = StringSplit(_Encoding_866To1251($sLog), @LF)
If Not IsArray($aErrorsTemp) Then Return 0
Dim $aErrors[$aErrorsTemp[0]]
For $i = 1 To $aErrorsTemp[0]
If StringInStr($aErrorsTemp[$i], "ошибка") Then
$aErrors[0] += 1
$aErrors[$aErrors[0]] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
EndIf
Next
If $aErrors[0] < 1 Then Return 0
ReDim $aErrors[$aErrors[0]+1]
Return $aErrors
EndFunc ;==>__ErrorLog


Func _ErrorHelp($Index)
Local $iNumberError, $hHelp, $sLog = ''
GUICtrlSetState($hListViewEv, $GUI_DISABLE)
$sItemText = _GUICtrlListView_GetItemText($hListViewEv, $Index)
$iNumberError = StringRegExpReplace($sItemText, "(?s).*?ошибка (.*?)\s+?.*", '\1')
$hHelp = Run('net helpmsg ' & $iNumberError, '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hHelp)
If @error Then ExitLoop
;Sleep(10)
WEnd
$sLog = StringStripWS(StringStripCR(_Encoding_866To1251($sLog)), 7)
GUICtrlSetData($hInput, 'Ошибка № ' & $iNumberError & ' - ' & $sLog)
GUICtrlSetData($hInputAll, $sItemText)
GUICtrlSetState($hListViewEv, $GUI_ENABLE)
EndFunc ;==>_ErrorHelp

;; End ErrorLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)
;#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView

$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
RefreshDeviceProperties()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

;Triggered when a device is selected in the treeview
Func RefreshDeviceProperties()
Local $hSelected = _GUICtrlTreeView_GetSelection($hTreeView)

;Don't do anything if a class name (root item) was clicked
If _GUICtrlTreeView_Level($hTreeView, $hSelected) = 0 Then Return

;Lookup treeview item handle in global array
For $X = 0 to Ubound($aAssoc)-1

If $hSelected = $aAssoc[$X][0] Then
;MsgBox(0,"", "Handle: " & $aAssoc[$X][0] & @CRLF & "Unique Instance Id: " & $aAssoc[$X][1])

;Build list of ALL device classes
_DeviceAPI_GetClassDevices()

;Loop through all devices by index
While _DeviceAPI_EnumDevices()
If $aAssoc[$X][1] = _DeviceAPI_GetDeviceId() Then

;Empty listview
_GUICtrlListView_DeleteAllItems($hListView)

GUICtrlCreateListViewItem ("Hardware ID: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID), $hListView )
GUICtrlCreateListViewItem ("Unique Instance ID: |" & _DeviceAPI_GetDeviceId(), $hListView )
GUICtrlCreateListViewItem ("Manufacturer: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_MFG), $hListView )
GUICtrlCreateListViewItem ("Driver: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER), $hListView )
GUICtrlCreateListViewItem ("Friendly Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME), $hListView )
GUICtrlCreateListViewItem ("Physical Device Object Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_PHYSICAL_DEVICE_OBJECT_NAME), $hListView )
GUICtrlCreateListViewItem ("Upper Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_UPPERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Lower Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_LOWERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Enumerator: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_ENUMERATOR_NAME), $hListView )

;Resize columns to fit text
_GUICtrlListView_SetColumnWidth($hListView, 0,$LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 1,$LVSCW_AUTOSIZE)
EndIf
WEnd
EndIf
Next
EndFunc
;; End DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Где я накосячил, сэнсей?

Creat0R
08-09-2010, 00:16
Где я накосячил »
Я не могу проверить, у меня нет «DeviceAPI.au3». ...

вкладка DriverErrors по прежнему не работает »
Что именно должно работать?

совмещение происходит через case? Приблизительно так? »
Да.

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) WM_NOTIFY_Ev($hWnd, $iMsg, $wParam, $lParam)

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tNMITEMACTIVATE = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMITEMACTIVATE, $lParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hFrom = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'hWndFrom')
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $Index = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'Index')
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $ID = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'Code')

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hWndTreeview = $hTreeView
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)($hTreeView) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $hWndTreeview = GUICtrlGetHandle (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlGetHandle.htm)($hTreeView)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tNMHDR = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMHDR, $lParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hWndFrom = HWnd (http://www.autoitscript.com/autoit3/docs/functions/HWnd.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "hWndFrom"))
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iIDFrom = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "IDFrom")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iCode = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "Code")

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $hFrom
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hListViewEv
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $ID
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $LVN_ITEMCHANGED
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) (BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) _
(BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) (Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
_ErrorHelp($Index)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hWndTreeview
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iCode
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
RefreshDeviceProperties()
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)

saavaage
08-09-2010, 00:45
Creat0R, Прошу прощение. Племяш, оказывается, переустановил дрова. Я специально удалял пару для теста. Вобщем, естественно, у меня поля вкладки DriverErrors были пусты. Столько времени убить!
Спасибо Вам за помощь. Все работает.

рабочий код (для проверки сделал вывод всего оборудования, для которого есть дрова)

через case:

#include <Constants.au3>
#include <EditConstants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <DeviceAPI.au3>

; ErrorLogs
Global $hMain_GUI, $nErrorRenew_Button, $hInput, $hInputAll, $ListViewEv, $hListViewEv, $aErrorsNew

; DriversErrors
Global $aAssoc[1][2]
Global $hTreeView

Opt("GUIOnEventMode", 1)

$hMain_GUI = GUICreate("Диагностика и Настройка XP SP3", 619, 442, 189, 122)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Tab1 = GUICtrlCreateTab(8, 16, 601, 377)
;;;; EventErrors ;;;;
Dim $aToList = __ErrorLog()
$EventErrors = GUICtrlCreateTabItem("EventErrors")
$nErrorRenew_Button = GUICtrlCreateButton("Обновить", 440, 400, 85, 33)
GUICtrlSetOnEvent($nErrorRenew_Button, "ErrorRenew_Button")

GUICtrlCreateGroup("Расшифровка кода ошибки", 16, 65, 585, 63)
$hInput = GUICtrlCreateEdit('', 24, 80, 570, 39, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$ListViewEv = GUICtrlCreateListView('Список Errors логов системы', 16, 133, 585, 169, -1, $LVS_EX_GRIDLINES)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateGroup("Полное описание выделенной ошибки", 16, 305, 585, 82)
$hInputAll = GUICtrlCreateEdit('', 24, 320, 570, 59, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY_Ev')

$hListViewEv = GUICtrlGetHandle($ListViewEv)
_GUICtrlListView_SetColumnWidth($hListViewEv, 0, 2000)
If $aToList <> 0 Then
_GUICtrlListView_AddColumn($hListViewEv, '')
For $i = 1 To UBound($aToList) - 1
_GUICtrlListView_AddItem($hListViewEv, $aToList[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf


;;; DriversErrors ;;;
$DriverErrors = GUICtrlCreateTabItem("DriversErrors")
Dim $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
$hTreeView = GUICtrlCreateTreeView(14, 45, 253, 337, $iStyle, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_FOCUS)
$hListView = GUICtrlCreateListView("Key|Value", 272, 45, 332, 337)

Dim $total_devices = 0

_DeviceAPI_GetClasses()
While _DeviceAPI_EnumClasses()

;Build list of devices within current class, if class doesn't contain any devices it will be skipped
_DeviceAPI_GetClassDevices($p_currentGUID)

;Skip classes without devices
If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) <> '' Then


;Add parent class to treeview
$parent = _GUICtrlTreeView_Add($hTreeView, 0, _DeviceAPI_GetClassDescription($p_currentGUID))

;Loop through all devices by index
While _DeviceAPI_EnumDevices()

$description = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC)
$friendly_name = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME)

;If a friendly name is available, use it instead of description
If $friendly_name <> "" Then
$description = $friendly_name
EndIf


;Add device to treeview below parent
$handle = _GUICtrlTreeView_AddChild($hTreeView, $parent, $description)

If $total_devices > 0 Then
ReDim $aAssoc[$total_devices+1][2]
EndIf

;Add treeview item handle to array along with device Unique Instance Id (For lookup)
$aAssoc[$total_devices][0] = $handle
$aAssoc[$total_devices][1] = _DeviceAPI_GetDeviceId()

;Update running total count of devices
$total_devices += 1
WEnd
EndIf
WEnd


_DeviceAPI_DestroyDeviceInfoList() ;Cleanup for good measure


GUICtrlCreateTabItem("")

GUISetState()

While 1
Sleep(100)
WEnd


Func CLOSEClicked()
Exit
EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ErrorsLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func ErrorRenew_Button()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
_GUICtrlListView_DeleteAllItems($hListViewEv)
GUICtrlSetData($hInput, '')
GUICtrlSetData($hInputAll, '')
$aErrorsNew = __ErrorLog()
If $aErrorsNew <>0 Then
For $i = 1 To UBound($aErrorsNew) - 1
_GUICtrlListView_AddItem($hListViewEv, $aErrorsNew[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf
sleep(1000)
GUICtrlSetState($nErrorRenew_Button, $GUI_ENABLE)
GUICtrlSetState($ListViewEv, $GUI_FOCUS)
EndFunc

Func WM_NOTIFY_Ev($hWnd, $iMsg, $wParam, $lParam)

Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')

Local $hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
Local $iCode = DllStructGetData($tNMHDR, "Code")

Switch $hFrom
Case $hListViewEv
Switch $ID
Case $LVN_ITEMCHANGED
If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And _
(BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
_ErrorHelp($Index)
EndIf
EndSwitch
Case $hWndTreeview
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
RefreshDeviceProperties()
EndSwitch
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc

Func __ErrorLog()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
Local $sLog = '', $hError, $aErrorsTemp, $i
Dim $aErrors[1]
$hError = Run('CSCRIPT.exe ' & @SystemDir & '\eventquery.vbs /v /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hError)
If @error Then ExitLoop
; Sleep(10)
WEnd
If Not $sLog Then Return 0
$aErrorsTemp = StringSplit(_Encoding_866To1251($sLog), @LF)
If Not IsArray($aErrorsTemp) Then Return 0
Dim $aErrors[$aErrorsTemp[0]]
For $i = 1 To $aErrorsTemp[0]
If StringInStr($aErrorsTemp[$i], "ошибка") Then
$aErrors[0] += 1
$aErrors[$aErrors[0]] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
EndIf
Next
If $aErrors[0] < 1 Then Return 0
ReDim $aErrors[$aErrors[0]+1]
Return $aErrors
EndFunc ;==>__ErrorLog


Func _ErrorHelp($Index)
Local $iNumberError, $hHelp, $sLog = ''
GUICtrlSetState($hListViewEv, $GUI_DISABLE)
$sItemText = _GUICtrlListView_GetItemText($hListViewEv, $Index)
$iNumberError = StringRegExpReplace($sItemText, "(?s).*?ошибка (.*?)\s+?.*", '\1')
$hHelp = Run('net helpmsg ' & $iNumberError, '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hHelp)
If @error Then ExitLoop
;Sleep(10)
WEnd
$sLog = StringStripWS(StringStripCR(_Encoding_866To1251($sLog)), 7)
GUICtrlSetData($hInput, 'Ошибка № ' & $iNumberError & ' - ' & $sLog)
GUICtrlSetData($hInputAll, $sItemText)
GUICtrlSetState($hListViewEv, $GUI_ENABLE)
EndFunc ;==>_ErrorHelp

;; End ErrorLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Triggered when a device is selected in the treeview
Func RefreshDeviceProperties()
Local $hSelected = _GUICtrlTreeView_GetSelection($hTreeView)

;Don't do anything if a class name (root item) was clicked
If _GUICtrlTreeView_Level($hTreeView, $hSelected) = 0 Then Return

;Lookup treeview item handle in global array
For $X = 0 to Ubound($aAssoc)-1

If $hSelected = $aAssoc[$X][0] Then
;MsgBox(0,"", "Handle: " & $aAssoc[$X][0] & @CRLF & "Unique Instance Id: " & $aAssoc[$X][1])

;Build list of ALL device classes
_DeviceAPI_GetClassDevices()

;Loop through all devices by index
While _DeviceAPI_EnumDevices()
If $aAssoc[$X][1] = _DeviceAPI_GetDeviceId() Then

;Empty listview
_GUICtrlListView_DeleteAllItems($hListView)

GUICtrlCreateListViewItem ("Hardware ID: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID), $hListView )
GUICtrlCreateListViewItem ("Unique Instance ID: |" & _DeviceAPI_GetDeviceId(), $hListView )
GUICtrlCreateListViewItem ("Manufacturer: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_MFG), $hListView )
GUICtrlCreateListViewItem ("Driver: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER), $hListView )
GUICtrlCreateListViewItem ("Friendly Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME), $hListView )
GUICtrlCreateListViewItem ("Physical Device Object Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_PHYSICAL_DEVICE_OBJECT_NAME), $hListView )
GUICtrlCreateListViewItem ("Upper Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_UPPERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Lower Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_LOWERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Enumerator: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_ENUMERATOR_NAME), $hListView )

;Resize columns to fit text
_GUICtrlListView_SetColumnWidth($hListView, 0,$LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 1,$LVSCW_AUTOSIZE)
EndIf
WEnd
EndIf
Next
EndFunc
;; End DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

через "трюк" (запуск одного WM_NOTIFY из другого WM_NOTIFY):

#include <Constants.au3>
#include <EditConstants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <DeviceAPI.au3>

; ErrorLogs
Global $hMain_GUI, $nErrorRenew_Button, $hInput, $hInputAll, $ListViewEv, $hListViewEv, $aErrorsNew

; DriversErrors
Global $aAssoc[1][2]
Global $hTreeView

Opt("GUIOnEventMode", 1)

$hMain_GUI = GUICreate("Диагностика и Настройка XP SP3", 619, 442, 189, 122)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Tab1 = GUICtrlCreateTab(8, 16, 601, 377)
;;;; EventErrors ;;;;
Dim $aToList = __ErrorLog()
$EventErrors = GUICtrlCreateTabItem("EventErrors")
$nErrorRenew_Button = GUICtrlCreateButton("Обновить", 440, 400, 85, 33)
GUICtrlSetOnEvent($nErrorRenew_Button, "ErrorRenew_Button")

GUICtrlCreateGroup("Расшифровка кода ошибки", 16, 65, 585, 63)
$hInput = GUICtrlCreateEdit('', 24, 80, 570, 39, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$ListViewEv = GUICtrlCreateListView('Список Errors логов системы', 16, 133, 585, 169, -1, $LVS_EX_GRIDLINES)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateGroup("Полное описание выделенной ошибки", 16, 305, 585, 82)
$hInputAll = GUICtrlCreateEdit('', 24, 320, 570, 59, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY_Ev')

$hListViewEv = GUICtrlGetHandle($ListViewEv)
_GUICtrlListView_SetColumnWidth($hListViewEv, 0, 2000)
If $aToList <> 0 Then
_GUICtrlListView_AddColumn($hListViewEv, '')
For $i = 1 To UBound($aToList) - 1
_GUICtrlListView_AddItem($hListViewEv, $aToList[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf


;;; DriversErrors ;;;
$DriverErrors = GUICtrlCreateTabItem("DriversErrors")
Dim $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
$hTreeView = GUICtrlCreateTreeView(14, 45, 253, 337, $iStyle, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_FOCUS)
$hListView = GUICtrlCreateListView("Key|Value", 272, 45, 332, 337)

Dim $total_devices = 0

_DeviceAPI_GetClasses()
While _DeviceAPI_EnumClasses()

;Build list of devices within current class, if class doesn't contain any devices it will be skipped
_DeviceAPI_GetClassDevices($p_currentGUID)

;Skip classes without devices
If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) <> '' Then


;Add parent class to treeview
$parent = _GUICtrlTreeView_Add($hTreeView, 0, _DeviceAPI_GetClassDescription($p_currentGUID))

;Loop through all devices by index
While _DeviceAPI_EnumDevices()

$description = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC)
$friendly_name = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME)

;If a friendly name is available, use it instead of description
If $friendly_name <> "" Then
$description = $friendly_name
EndIf


;Add device to treeview below parent
$handle = _GUICtrlTreeView_AddChild($hTreeView, $parent, $description)

If $total_devices > 0 Then
ReDim $aAssoc[$total_devices+1][2]
EndIf

;Add treeview item handle to array along with device Unique Instance Id (For lookup)
$aAssoc[$total_devices][0] = $handle
$aAssoc[$total_devices][1] = _DeviceAPI_GetDeviceId()

;Update running total count of devices
$total_devices += 1
WEnd
EndIf
WEnd

_DeviceAPI_DestroyDeviceInfoList() ;Cleanup for good measure


GUICtrlCreateTabItem("")

GUISetState()

While 1
Sleep(100)
WEnd


Func CLOSEClicked()
Exit
EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ErrorsLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func ErrorRenew_Button()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
_GUICtrlListView_DeleteAllItems($hListViewEv)
GUICtrlSetData($hInput, '')
GUICtrlSetData($hInputAll, '')
$aErrorsNew = __ErrorLog()
If $aErrorsNew <>0 Then
For $i = 1 To UBound($aErrorsNew) - 1
_GUICtrlListView_AddItem($hListViewEv, $aErrorsNew[$i])
Next
_GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf
sleep(1000)
GUICtrlSetState($nErrorRenew_Button, $GUI_ENABLE)
GUICtrlSetState($ListViewEv, $GUI_FOCUS)
EndFunc

Func WM_NOTIFY_Ev($hWnd, $iMsg, $wParam, $lParam)
WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)
Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')
Switch $hFrom
Case $hListViewEv
Switch $ID
Case $LVN_ITEMCHANGED
If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And _
(BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
_ErrorHelp($Index)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc

Func __ErrorLog()
GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
Local $sLog = '', $hError, $aErrorsTemp, $i
Dim $aErrors[1]
$hError = Run('CSCRIPT.exe ' & @SystemDir & '\eventquery.vbs /v /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hError)
If @error Then ExitLoop
; Sleep(10)
WEnd
If Not $sLog Then Return 0
$aErrorsTemp = StringSplit(_Encoding_866To1251($sLog), @LF)
If Not IsArray($aErrorsTemp) Then Return 0
Dim $aErrors[$aErrorsTemp[0]]
For $i = 1 To $aErrorsTemp[0]
If StringInStr($aErrorsTemp[$i], "ошибка") Then
$aErrors[0] += 1
$aErrors[$aErrors[0]] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
EndIf
Next
If $aErrors[0] < 1 Then Return 0
ReDim $aErrors[$aErrors[0]+1]
Return $aErrors
EndFunc ;==>__ErrorLog


Func _ErrorHelp($Index)
Local $iNumberError, $hHelp, $sLog = ''
GUICtrlSetState($hListViewEv, $GUI_DISABLE)
$sItemText = _GUICtrlListView_GetItemText($hListViewEv, $Index)
$iNumberError = StringRegExpReplace($sItemText, "(?s).*?ошибка (.*?)\s+?.*", '\1')
$hHelp = Run('net helpmsg ' & $iNumberError, '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hHelp)
If @error Then ExitLoop
;Sleep(10)
WEnd
$sLog = StringStripWS(StringStripCR(_Encoding_866To1251($sLog)), 7)
GUICtrlSetData($hInput, 'Ошибка № ' & $iNumberError & ' - ' & $sLog)
GUICtrlSetData($hInputAll, $sItemText)
GUICtrlSetState($hListViewEv, $GUI_ENABLE)
EndFunc ;==>_ErrorHelp

;; End ErrorLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)
;#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView

$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
RefreshDeviceProperties()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

;Triggered when a device is selected in the treeview
Func RefreshDeviceProperties()
Local $hSelected = _GUICtrlTreeView_GetSelection($hTreeView)

;Don't do anything if a class name (root item) was clicked
If _GUICtrlTreeView_Level($hTreeView, $hSelected) = 0 Then Return

;Lookup treeview item handle in global array
For $X = 0 to Ubound($aAssoc)-1

If $hSelected = $aAssoc[$X][0] Then
;MsgBox(0,"", "Handle: " & $aAssoc[$X][0] & @CRLF & "Unique Instance Id: " & $aAssoc[$X][1])

;Build list of ALL device classes
_DeviceAPI_GetClassDevices()

;Loop through all devices by index
While _DeviceAPI_EnumDevices()
If $aAssoc[$X][1] = _DeviceAPI_GetDeviceId() Then

;Empty listview
_GUICtrlListView_DeleteAllItems($hListView)

GUICtrlCreateListViewItem ("Hardware ID: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID), $hListView )
GUICtrlCreateListViewItem ("Unique Instance ID: |" & _DeviceAPI_GetDeviceId(), $hListView )
GUICtrlCreateListViewItem ("Manufacturer: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_MFG), $hListView )
GUICtrlCreateListViewItem ("Driver: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER), $hListView )
GUICtrlCreateListViewItem ("Friendly Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME), $hListView )
GUICtrlCreateListViewItem ("Physical Device Object Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_PHYSICAL_DEVICE_OBJECT_NAME), $hListView )
GUICtrlCreateListViewItem ("Upper Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_UPPERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Lower Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_LOWERFILTERS), $hListView )
GUICtrlCreateListViewItem ("Enumerator: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_ENUMERATOR_NAME), $hListView )

;Resize columns to fit text
_GUICtrlListView_SetColumnWidth($hListView, 0,$LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 1,$LVSCW_AUTOSIZE)
EndIf
WEnd
EndIf
Next
EndFunc
;; End DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

для вывода оборудования с отсутствующими драйверами заменить сроку
If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) <> '' Then
на
If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) = '' Then

Тема решена.




© OSzone.net 2001-2012