Что нового

Re: Помогите оптимизировать скрипт

Статус
Закрыто для дальнейших ответов.

MURDOC

Новичок
Сообщения
8
Репутация
0
Помогите пожалуйста оптимизировать скрипт, сделать его универсальным, нужно чтобы названия предприятий считывались с ini файла. Вот сам скрипт
Код:
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

FileInstall("C:\Documents and Settings\Администратор\Рабочий стол\Elegant\ICO\48x48\LCD.ico", @WindowsDir & "\LCD.ico") 
FileInstall("C:\Documents and Settings\Администратор\Рабочий стол\Passwords.ini", @WindowsDir & "\Passwords.ini")

$width = 1024
$height = 768

$oRDP = ObjCreate("MsTscAx.MsTscAx") 
$GUI = GUICreate("Клиент подключения к удаленному рабочему столу", $width+20, $height+20, 0, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) 
$GUIActiveX = GUICtrlCreateObj($oRDP, 10, 10, $width, $height) 
GUICtrlSetResizing ($GUIActiveX,$GUI_DOCKAUTO) 
GUISetBkColor (0x0000000)  
GUISetIcon(@WindowsDir & "\LCD.ico")
GUISetState() 
;==========================================================================================
GUICreate("listview items",500,500, 100,200,-1,$WS_EX_ACCEPTFILES) 
GUISetIcon(@WindowsDir & "\LCD.ico")
GUISetBkColor (0x0000000) 

$enterprise1 = "ДН-2"
$enterprise2 = "НА"
$enterprise3 = "НРП"
$enterprise4 = "НОР1"
$enterprise5 = "ВЧД-2"
$enterprise6 = "сл. НХ"
$enterprise7 = "НОДХ-2"
$enterprise8 = "База-40"
$enterprise9 = "Мусорка"
$enterprise10 = "сл.БМЕС"
$enterprise11 = "НГЧ-2"
$enterprise12 = "ЖБК"
$enterprise13 = "СМП-655"
$enterprise14 = "СМП-387"
$enterprise15 = "МСП-8"
$enterprise16 = "НГЧ-3"
$enterprise17 = "ДС Лозовая"
$enterprise18 = "ДС Основа"
$enterprise19 = "ДС Сортировка"
$enterprise20 = "ДС Х-Пасс"
$enterprise21 = "сл.П"
$enterprise22 = "ПЧ-4"
$enterprise23 = "ПЧ-3"
$enterprise24 = "ПЧЛ-2"
$enterprise25 = "ПЧ-10"
$enterprise26 = "ПЧ-7"
$enterprise27 = "ПЧ-14"
$enterprise28 = "КМС-131"
$enterprise29 = "КМС-39"
$enterprise30 = "КМС-213"
$enterprise31 = "сл.Т"
$enterprise32 = "ТЧ-2"
$enterprise33 = "ТЧ-9"
$enterprise34 = "ТЧ-10"
$enterprise35 = "ТЧ-Смородино"
$enterprise36 = "ТЧ-3"
$enterprise37 = "ТЧ-4 (РПЧ-1)"
$enterprise38 = "Авторем"
$enterprise39 = "ТЧ-14"
$enterprise40 = "сл.Э"
$enterprise41 = "Энергозбыт"
$enterprise42 = "ЭЧ-7"
$enterprise43 = "ЭЧ-6"
$enterprise44 = "ЭЧ-2"
$enterprise45 = "сл.В"
$enterprise46 = "ВЧД-3"
$enterprise47 = "ВЧД-6"
$enterprise48 = "сл.Ш"
$enterprise49 = "ШЧ-5"
$enterprise50 = "ШЧ-4"
$enterprise51 = "ШЧ-2"
$enterprise52 = "сл.Л (316ком.)"
$enterprise53 = "ВЧ-1"
$enterprise54 = "Вокзал Х-Пасс"
$enterprise55 = "сл.НО"
$enterprise56 = "Спецкоманда"
$enterprise57 = "ВОХР (НОР-1)"
$enterprise58 = "Автобаза"
$enterprise59 = "ДК ЖД"
$enterprise60 = "СК Локомотив"
$enterprise61 = "ДФСК"
$enterprise62 = "Техшкола"
$enterprise63 = "ИВЦ"
$enterprise64 = "НФЦ"
$enterprise65 = "НФ"

$listview = GUICtrlCreateListView ("",10,10,480,450) 
_GUICtrlListView_AddColumn($listview, "Предприятие", 475) 
$button = GUICtrlCreateButton ("Подключиться",200,470,90,20) 

$item1=GUICtrlCreateListViewItem($enterprise1,$listview)
$item2=GUICtrlCreateListViewItem($enterprise2,$listview)
$item3=GUICtrlCreateListViewItem($enterprise3,$listview)
$item4=GUICtrlCreateListViewItem($enterprise4,$listview)
$item5=GUICtrlCreateListViewItem($enterprise5,$listview)
$item6=GUICtrlCreateListViewItem($enterprise6,$listview)
$item7=GUICtrlCreateListViewItem($enterprise7,$listview)
$item8=GUICtrlCreateListViewItem($enterprise8,$listview)
$item9=GUICtrlCreateListViewItem($enterprise9,$listview)
$item10=GUICtrlCreateListViewItem($enterprise10,$listview)
$item11=GUICtrlCreateListViewItem($enterprise11,$listview)
$item12=GUICtrlCreateListViewItem($enterprise12,$listview)
$item13=GUICtrlCreateListViewItem($enterprise13,$listview)
$item14=GUICtrlCreateListViewItem($enterprise14,$listview)
$item15=GUICtrlCreateListViewItem($enterprise15,$listview)
$item16=GUICtrlCreateListViewItem($enterprise16,$listview)
$item17=GUICtrlCreateListViewItem($enterprise17,$listview)
$item18=GUICtrlCreateListViewItem($enterprise18,$listview)
$item19=GUICtrlCreateListViewItem($enterprise19,$listview)
$item20=GUICtrlCreateListViewItem($enterprise20,$listview)
$item21=GUICtrlCreateListViewItem($enterprise21,$listview)
$item22=GUICtrlCreateListViewItem($enterprise22,$listview)
$item23=GUICtrlCreateListViewItem($enterprise23,$listview)
$item24=GUICtrlCreateListViewItem($enterprise24,$listview)
$item25=GUICtrlCreateListViewItem($enterprise25,$listview)
$item26=GUICtrlCreateListViewItem($enterprise26,$listview)
$item27=GUICtrlCreateListViewItem($enterprise27,$listview)
$item28=GUICtrlCreateListViewItem($enterprise28,$listview)
$item29=GUICtrlCreateListViewItem($enterprise29,$listview)
$item30=GUICtrlCreateListViewItem($enterprise30,$listview)
$item31=GUICtrlCreateListViewItem($enterprise31,$listview)
$item32=GUICtrlCreateListViewItem($enterprise32,$listview)
$item33=GUICtrlCreateListViewItem($enterprise33,$listview)
$item34=GUICtrlCreateListViewItem($enterprise34,$listview)
$item35=GUICtrlCreateListViewItem($enterprise35,$listview)
$item36=GUICtrlCreateListViewItem($enterprise36,$listview)
$item37=GUICtrlCreateListViewItem($enterprise37,$listview)
$item38=GUICtrlCreateListViewItem($enterprise38,$listview)
$item39=GUICtrlCreateListViewItem($enterprise39,$listview)
$item40=GUICtrlCreateListViewItem($enterprise40,$listview)
$item41=GUICtrlCreateListViewItem($enterprise41,$listview)
$item42=GUICtrlCreateListViewItem($enterprise42,$listview)
$item43=GUICtrlCreateListViewItem($enterprise43,$listview)
$item44=GUICtrlCreateListViewItem($enterprise44,$listview)
$item45=GUICtrlCreateListViewItem($enterprise45,$listview)
$item46=GUICtrlCreateListViewItem($enterprise46,$listview)
$item47=GUICtrlCreateListViewItem($enterprise47,$listview)
$item48=GUICtrlCreateListViewItem($enterprise48,$listview)
$item49=GUICtrlCreateListViewItem($enterprise49,$listview)
$item50=GUICtrlCreateListViewItem($enterprise50,$listview)
$item51=GUICtrlCreateListViewItem($enterprise51,$listview)
$item52=GUICtrlCreateListViewItem($enterprise52,$listview)
$item53=GUICtrlCreateListViewItem($enterprise53,$listview)
$item54=GUICtrlCreateListViewItem($enterprise54,$listview)
$item55=GUICtrlCreateListViewItem($enterprise55,$listview)
$item56=GUICtrlCreateListViewItem($enterprise56,$listview)
$item57=GUICtrlCreateListViewItem($enterprise57,$listview)
$item58=GUICtrlCreateListViewItem($enterprise58,$listview)
$item59=GUICtrlCreateListViewItem($enterprise59,$listview)
$item60=GUICtrlCreateListViewItem($enterprise60,$listview)
$item61=GUICtrlCreateListViewItem($enterprise61,$listview)
$item62=GUICtrlCreateListViewItem($enterprise62,$listview)
$item63=GUICtrlCreateListViewItem($enterprise63,$listview)
$item64=GUICtrlCreateListViewItem($enterprise64,$listview)
$item65=GUICtrlCreateListViewItem($enterprise65,$listview)

GUICtrlSetState(-1,$GUI_DROPACCEPTED) 
GUISetState() 
Do
  $msg = GUIGetMsg ()
   Select
   Case $msg = $button ; задаем параметры кнопки
		$index = Int(_GUICtrlListView_GetSelectedIndices($listview)) 
		$text = _GUICtrlListView_GetItemTextString($listview, $index) 
		$msg = $GUI_EVENT_CLOSE 
   EndSelect
Until $msg = $GUI_EVENT_CLOSE 
$login = IniRead(@WindowsDir & "\Passwords.ini", $text, "login","Нет в базе") 
$pass = IniRead(@WindowsDir & "\Passwords.ini", $text, "pass","Нет в базе")
$ip = IniRead(@WindowsDir & "\Passwords.ini", $text, "ip","Нет в базе")
;===========================================================================================

if @IPAddress1 = "10.5.106.166" Then

$oRDP.Server = $ip
$oRDP.Domain = "domain"
$oRDP.UserName = $login
$oRdp.AdvancedSettings2.ClearTextPassword = $pass
$oRDP.Connect()
;$oRdp.Fullscreen = True
$oRdp.ConnectingText = "Подключение"
$oRdp.DisconnectedText = "Сбой соединения"
Else
MsgBox(016,"Уведомление","Вы не имеете права использовать эту программу"&@CR&"на своем компьютере")	
EndIf
Opt("WinTitleMatchMode", 4 )     
Opt("WinSearchChildren", 1)     
$sATLClass = ""
$aClasses = StringSplit(WinGetClassList($GUI,""),@LF)
For $i = 1 To $aClasses[0]
    If StringLeft($aClasses[$i],4) = "ATL:" Then
        $sATLClass = $aClasses[$i]
        ExitLoop
    EndIf
Next

$hUIContainerClass = ControlGetHandle($GUI, "", "[CLASS:UIContainerClass]")
$hUIMainClass = ControlGetHandle($GUI, "", "[CLASS:UIMainClass]")
$hATL = ControlGetHandle($GUI, "", "[CLASS:"&$sATLClass&"]")
ConsoleWrite("$hUIContainerClass (should not be 0 or blank):" & $hUIContainerClass & @crlf)
ConsoleWrite("$hUIMainClass (should not be 0 or blank):" & $hUIMainClass & @crlf)
ConsoleWrite("$hATL (should not be 0 or blank):" & $hATL & @crlf)

; modify the styles of the child controls to match those set by the offical client application
; this prevents clipping problems - though, I don't know why
Const $WS_EX_NOPARENTNOTIFY = 0x4
Const $WS_EX_NOINHERITLAYOUT = 0x100000
$hUIContainerClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000
$hUIContainerClassStyleEx = BitOR($WS_EX_NOINHERITLAYOUT, $WS_EX_NOPARENTNOTIFY) ; 0x00100004
$hUIMainClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_SYSMENU, $WS_VISIBLE) ; 0x56080000
$hUIMainClassStyleEx = 0x0
$hATLStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000
$hATLStyleEx = 0x0
$guiStyle = BitOR($WS_BORDER, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_DLGFRAME, $WS_GROUP, $WS_MAXIMIZE, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_TABSTOP, $WS_THICKFRAME, $WS_VISIBLE) ; 0x17CF0100
$guiStyleEx = $WS_EX_WINDOWEDGE ; 0x00000100
_SetStyle($hUIContainerClass,$hUIContainerClassStyle,$hUIContainerClassStyleEx)
_SetStyle($hUIMainClass,$hUIMainClassStyle,$hUIMainClassStyleEx)
_SetStyle($hATL,$hATLStyle,$hATLStyleEx)
_SetStyle($gui,$guiStyle,$guiStyleEx)
Func _SetStyle($hwnd,$style,$exstyle)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -16, "long", $style)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -20, "long", $exstyle)
EndFunc

AdlibEnable ( "checkconn", 1000)

Func checkconn()
    If $oRDP.Connected = 0 Then
        Exit
    EndIf
EndFunc


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

GUIDelete()

Exit
 

`p r o x y

«Улыбайтесь, господа!»
Команда форума
Глобальный модератор
Сообщения
596
Репутация
157
1) 1 тема - 1 вопрос

2) Необходимо подробно описать вопрос.
Т.к. человек читающий мысли временно вне планеты Земля.
Какие именно операции необходимо универсализировать?
Функция чтения данных из INI: IniRead.

3) Необходимо придумать название темы соответсвующее вопросу.
"Помогите", "не получается" и т.д. подобное - недостаточно.
В вашей задаче, например: "Чтение данных из INI и вставка в ....".
 

AZJIO

Меценат
Меценат
Сообщения
2,879
Репутация
1,194
MURDOC
не тестировал, но сделал пример использования массива
Код:
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

FileInstall("C:\Documents and Settings\Администратор\Рабочий стол\Elegant\ICO\48x48\LCD.ico", @WindowsDir & "\LCD.ico")
FileInstall("C:\Documents and Settings\Администратор\Рабочий стол\Passwords.ini", @WindowsDir & "\Passwords.ini")

$width = 1024
$height = 768

$oRDP = ObjCreate("MsTscAx.MsTscAx")
$GUI = GUICreate("Клиент подключения к удаленному рабочему столу", $width+20, $height+20, 0, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oRDP, 10, 10, $width, $height)
GUICtrlSetResizing ($GUIActiveX,$GUI_DOCKAUTO)
GUISetBkColor (0x0000000)  
GUISetIcon(@WindowsDir & "\LCD.ico")
GUISetState()
;==========================================================================================
GUICreate("listview items",500,500, 100,200,-1,$WS_EX_ACCEPTFILES)
GUISetIcon(@WindowsDir & "\LCD.ico")
GUISetBkColor (0x0000000)

;!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i
;вставка первая
$file = FileOpen(@ScriptDir&'\1.ini', 0)
$basetext = FileRead($file)
FileClose($file)

;=====================
;кусок кода из UDF File.au3 для разделения образца построчно в массив
If StringInStr($basetext, @LF) Then
	$aFiletext = StringSplit(StringStripCR($basetext), @LF)
ElseIf StringInStr($basetext, @CR) Then
	$aFiletext = StringSplit($basetext, @CR)
Else ;; unable to split the file
	If StringLen($basetext) Then
		Dim $aFiletext[2] = [1, $basetext]
	Else
		MsgBox(0, "Сообщение", "нет данных")
		ContinueLoop
	EndIf
EndIf
;=====================
;!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i


$listview = GUICtrlCreateListView ("",10,10,480,450)
_GUICtrlListView_AddColumn($listview, "Предприятие", 475)
$button = GUICtrlCreateButton ("Подключиться",200,470,90,20)


;!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i
;вставка вторая
Global $aItem[$aFiletext[0]+1]
For $i = 1 to $aFiletext[0]
	$aItem[$i]=GUICtrlCreateListViewItem($aFiletext[$i],$listview)
Next
;!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i

GUICtrlSetState(-1,$GUI_DROPACCEPTED)
GUISetState()
Do
  $msg = GUIGetMsg ()
   Select
   Case $msg = $button ; задаем параметры кнопки
        $index = Int(_GUICtrlListView_GetSelectedIndices($listview))
        $text = _GUICtrlListView_GetItemTextString($listview, $index)
        $msg = $GUI_EVENT_CLOSE
   EndSelect
Until $msg = $GUI_EVENT_CLOSE
$login = IniRead(@WindowsDir & "\Passwords.ini", $text, "login","Нет в базе")
$pass = IniRead(@WindowsDir & "\Passwords.ini", $text, "pass","Нет в базе")
$ip = IniRead(@WindowsDir & "\Passwords.ini", $text, "ip","Нет в базе")
;===========================================================================================

if @IPAddress1 = "10.5.106.166" Then

$oRDP.Server = $ip
$oRDP.Domain = "domain"
$oRDP.UserName = $login
$oRdp.AdvancedSettings2.ClearTextPassword = $pass
$oRDP.Connect()
;$oRdp.Fullscreen = True
$oRdp.ConnectingText = "Подключение"
$oRdp.DisconnectedText = "Сбой соединения"
Else
MsgBox(016,"Уведомление","Вы не имеете права использовать эту программу"&@CR&"на своем компьютере") 
EndIf
Opt("WinTitleMatchMode", 4 )    
Opt("WinSearchChildren", 1)    
$sATLClass = ""
$aClasses = StringSplit(WinGetClassList($GUI,""),@LF)
For $i = 1 To $aClasses[0]
    If StringLeft($aClasses[$i],4) = "ATL:" Then
        $sATLClass = $aClasses[$i]
        ExitLoop
    EndIf
Next

$hUIContainerClass = ControlGetHandle($GUI, "", "[CLASS:UIContainerClass]")
$hUIMainClass = ControlGetHandle($GUI, "", "[CLASS:UIMainClass]")
$hATL = ControlGetHandle($GUI, "", "[CLASS:"&$sATLClass&"]")
ConsoleWrite("$hUIContainerClass (should not be 0 or blank):" & $hUIContainerClass & @crlf)
ConsoleWrite("$hUIMainClass (should not be 0 or blank):" & $hUIMainClass & @crlf)
ConsoleWrite("$hATL (should not be 0 or blank):" & $hATL & @crlf)

; modify the styles of the child controls to match those set by the offical client application
; this prevents clipping problems - though, I don't know why
Const $WS_EX_NOPARENTNOTIFY = 0x4
Const $WS_EX_NOINHERITLAYOUT = 0x100000
$hUIContainerClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000
$hUIContainerClassStyleEx = BitOR($WS_EX_NOINHERITLAYOUT, $WS_EX_NOPARENTNOTIFY) ; 0x00100004
$hUIMainClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_SYSMENU, $WS_VISIBLE) ; 0x56080000
$hUIMainClassStyleEx = 0x0
$hATLStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000
$hATLStyleEx = 0x0
$guiStyle = BitOR($WS_BORDER, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_DLGFRAME, $WS_GROUP, $WS_MAXIMIZE, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_TABSTOP, $WS_THICKFRAME, $WS_VISIBLE) ; 0x17CF0100
$guiStyleEx = $WS_EX_WINDOWEDGE ; 0x00000100
_SetStyle($hUIContainerClass,$hUIContainerClassStyle,$hUIContainerClassStyleEx)
_SetStyle($hUIMainClass,$hUIMainClassStyle,$hUIMainClassStyleEx)
_SetStyle($hATL,$hATLStyle,$hATLStyleEx)
_SetStyle($gui,$guiStyle,$guiStyleEx)
Func _SetStyle($hwnd,$style,$exstyle)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -16, "long", $style)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -20, "long", $exstyle)
EndFunc

AdlibEnable ( "checkconn", 1000)

Func checkconn()
    If $oRDP.Connected = 0 Then
        Exit
    EndIf
EndFunc


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

GUIDelete()

Exit


файл 1.ini

ДН-2
НА
НРП
НОР1
ВЧД-2
сл. НХ
НОДХ-2
База-40
Мусорка
сл.БМЕС
НГЧ-2
ЖБК
СМП-655
СМП-387
МСП-8
НГЧ-3
ДС Лозовая
ДС Основа
ДС Сортировка
ДС Х-Пасс
сл.П
ПЧ-4
ПЧ-3
ПЧЛ-2
ПЧ-10
ПЧ-7
ПЧ-14
КМС-131
КМС-39
КМС-213
сл.Т
ТЧ-2
ТЧ-9
ТЧ-10
ТЧ-Смородино
ТЧ-3
ТЧ-4 (РПЧ-1)
Авторем
ТЧ-14
сл.Э
Энергозбыт
ЭЧ-7
ЭЧ-6
ЭЧ-2
сл.В
ВЧД-3
ВЧД-6
сл.Ш
ШЧ-5
ШЧ-4
ШЧ-2
сл.Л (316ком.)
ВЧ-1
Вокзал Х-Пасс
сл.НО
Спецкоманда
ВОХР (НОР-1)
Автобаза
ДК ЖД
СК Локомотив
ДФСК
Техшкола
ИВЦ
НФЦ
НФ
 
Статус
Закрыто для дальнейших ответов.
Верх