Ветеран
Сообщения: 903
Благодарности: 161
|
Профиль
|
Отправить PM
| Цитировать
Вот, что, собственно, у меня вышло:
читать дальше »
Код:
#include <Constants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GUIListview.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Form1, $Button1, $hInput, $hInputAll, $hListView, $aErrorsNew
Dim $aToList = __ErrorLog()
$Form1 = GUICreate("Form1", 620, 445, -1, -1)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
$Button1 = GUICtrlCreateButton("Обновить", 16, 120, 65, 57)
GUICtrlSetState(-1, $GUI_FOCUS)
$hInput = GUICtrlCreateEdit('', 95, 10, 400, 34, BitOR($ES_READONLY, $ES_MULTILINE))
$hInputAll = GUICtrlCreateEdit('', 95, 370, 400, 64, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$hListView = GUICtrlCreateListView('Список событий с ошибками', 95, 60, 400, 300, -1, $LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth($hListView, 0, 2500)
GUICtrlSetTip(-1, "Выделите левой или правой кнопкой мышки" & @CRLF & "строку, чтобы получить подсказку.")
If $aToList <> 0 Then
_GUICtrlListView_AddColumn($hListView, $aToList[0], 2500)
For $i = 1 To UBound($aToList) - 1
GUICtrlCreateListViewItem($aToList[$i], $hListView)
Next
EndIf
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($hInput, '')
_GUICtrlListView_DeleteAllItems($hListView)
$aErrorsNew = __ErrorLog()
If $aErrorsNew <> 0 Then
_GUICtrlListView_BeginUpdate($hListView)
For $i = 1 To UBound($aErrorsNew) - 1
GUICtrlCreateListViewItem($aErrorsNew[$i], $hListView)
Next
_GUICtrlListView_EndUpdate($hListView)
EndIf
GUICtrlSetState($Button1, $GUI_ENABLE)
EndSwitch
WEnd
Func __ErrorLog()
GUICtrlSetState($Button1, $GUI_DISABLE)
Local $sLog = '', $j = 0, $hError, $aErrorsTemp, $i = 0
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(100)
WEnd
If Not $sLog Then Return 0
$aErrorsTemp = StringSplit(_Encoding_866To1251($sLog), @LF)
If Not IsArray($aErrorsTemp) Then Return 0
For $i = 1 To $aErrorsTemp[0]
If StringInStr($aErrorsTemp[$i], "ошибка") Then
ReDim $aErrors[UBound($aErrors) + 1]
$j += 1
$aErrors[$j] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
EndIf
Next
If UBound($aErrors) < 2 Then Return 0
Return $aErrors
EndFunc ;==>__ErrorLog
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $iIndex, $sLog = '', $hHelp
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
If $iIndex < 0 Then Return $GUI_RUNDEFMSG
$hFullString =_GUICtrlListView_GetItemText($hListView, $iIndex)
$iNumberError = StringRegExpReplace(_GUICtrlListView_GetItemText($hListView, $iIndex), "(?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, $hFullString)
Case $NM_RCLICK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
If $iIndex <> -1 Then
GUICtrlSetData($hInput, _GUICtrlListView_GetItemText($hListView, $iIndex))
$iIndex_Item = $iIndex
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Аналогично с кодом в шапке:
читать дальше »
Код:
#include <Constants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GUIListview.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $hForm1, $hButton1, $hInput, $ListView, $hListView, $aErrorsNew, $nMsg, $hInputAll
Dim $aToList = __ErrorLog()
$hForm1 = GUICreate("Form1", 620, 445, -1, -1)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
$hButton1 = GUICtrlCreateButton("Обновить", 16, 120, 65, 57)
$hInput = GUICtrlCreateEdit('', 95, 10, 500, 34, BitOR($ES_READONLY, $ES_MULTILINE))
$hInputAll = GUICtrlCreateEdit('', 95, 370, 500, 64, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$ListView = GUICtrlCreateListView('Список событий с ошибками', 95, 60, 500, 300, -1, $LVS_EX_GRIDLINES)
GUICtrlSetState(-1, $GUI_FOCUS)
$hListView = GUICtrlGetHandle($ListView)
_GUICtrlListView_SetColumnWidth($hListView, 0, 2000)
GUICtrlSetTip(-1, "Выделите мышкой строку," & @CRLF & "чтобы получить подсказку.")
If $aToList <> 0 Then
_GUICtrlListView_AddColumn($hListView, '')
For $i = 1 To UBound($aToList) - 1
_GUICtrlListView_AddItem($hListView, $aToList[$i])
Next
_GUICtrlListView_SetItemSelected($hListView, 0)
EndIf
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hButton1
GUICtrlSetData($hInput, '')
GUICtrlSetData($hInputAll, '')
$aErrorsNew = __ErrorLog()
If $aErrorsNew <> 0 Then
_GUICtrlListView_DeleteAllItems($hListView)
For $i = 1 To UBound($aErrorsNew) - 1
_GUICtrlListView_AddItem($hListView, $aErrorsNew[$i])
Next
_GUICtrlListView_SetItemSelected($hListView, 0)
EndIf
GUICtrlSetState($hButton1, $GUI_ENABLE)
GUICtrlSetState($ListView, $GUI_FOCUS)
EndSwitch
WEnd
Func __ErrorLog()
GUICtrlSetState($hButton1, $GUI_DISABLE)
Local $sLog = '', $j = 0, $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
For $i = 1 To $aErrorsTemp[0]
If StringInStr($aErrorsTemp[$i], "ошибка") Then
ReDim $aErrors[UBound($aErrors) + 1]
$j += 1
$aErrors[$j] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
EndIf
Next
$aErrors[0] = UBound($aErrors) - 1
If UBound($aErrors) < 2 Then Return 0
Return $aErrors
EndFunc ;==>__ErrorLog
Func WM_NOTIFY($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 $hListView
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 _ErrorHelp($Index)
Local $iNumberError, $hHelp, $sLog = '', $hFullString
GUICtrlSetState($hButton1, $GUI_DISABLE)
GUICtrlSetState($hListView, $GUI_DISABLE)
$hFullString =_GUICtrlListView_GetItemText($hListView, $Index)
$iNumberError = StringRegExpReplace(_GUICtrlListView_GetItemText($hListView, $Index), "(?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, $hFullString)
GUICtrlSetState($hButton1, $GUI_ENABLE)
GUICtrlSetState($hListView, $GUI_ENABLE)
EndFunc ;==>_ErrorHelp
Кстати, есть вопрос по последнему коду: почему-то, при клике на строке в окне GUICtrlCreateListView, происходит ее выделение, а при попытке кликнуть по другой строке не происходит выделение последней. Система кликов-выделений срабатывает через клик.
|