Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » AutoIT (Часть 2)

Модерирует : gyra, Maz

Widok (01-06-2010 13:08): Лимит страниц. Продолжаем здесь.  Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

sproxy



Full Member
Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору


Код:
#region: - Options
    Opt('GUIOnEventMode',       1)
    Opt('MustDeclareVars',      1)
    Opt('TrayIconDebug',        0)
    Opt('TrayIconHide',         1)
#endregion
 
#region: - Include

;Defined Functions:
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
#endregion
 
#region: - Main Win     Global

;~  Handle, Status
    Global  $hMainWin, $hMainWinFileDeletePath
 
;~  Title, Width, Height, X, Y, Style, ExStyle
    Global  $sMainWinTitle          = 'Test'
    Global  $iMainWinWidth          = 350
    Global  $iMainWinHeight         = 345
    Global  $iMainWinX              = -1
    Global  $iMainWinY              = -1
    Global  $iMainWinStyle          = $WS_OVERLAPPEDWINDOW
    Global  $iMainWinExStyle        = -1
#endregion
 
#region: - Main Win     Functions

Func _MainWin_Create()
    $hMainWin = GUICreate($sMainWinTitle, $iMainWinWidth, $iMainWinHeight, $iMainWinX, $iMainWinY, $iMainWinStyle, $iMainWinExStyle)
        GUISetOnEvent($GUI_EVENT_CLOSE, '_Pro_Exit')
 
    $hMainWinFileDeletePath = GUICtrlCreateInput('', 10, 20, 250, 20)
 
    GUICtrlCreateButton('Удалить файл (AutoIt)', 10, 50, 150, 25)
        GUICtrlSetOnEvent(-1, '_MainWin_FileDelete_AutoIt')
 
    GUICtrlCreateButton('Удалить файл (WinAPI)', 10, 50+30, 150, 25)
        GUICtrlSetOnEvent(-1, '_MainWin_FileDelete_WInAPI')
 
    GUISetState(@SW_SHOW, $hMainWin)
EndFunc
Func
_MainWin_FileDelete_AutoIt()
    Local $sFilePath = GUICtrlRead($hMainWinFileDeletePath)
    _FileDelete_AutoIt($sFilePath)
    Switch @error
        Case -1
            MsgBox(48, 'Удаление файла', 'Файл удаления: ' & $sFilePath & @CRLF & @CRLF & 'Результат: ' & @error & @CRLF & @CRLF & _
            'Удаляемый файл ненайден')
        Case 0
            MsgBox(48, 'Удаление файла', 'Файл удаления: ' & $sFilePath & @CRLF & @CRLF & 'Результат: ' & @error & @CRLF & @CRLF & _
            'Ошибка удаления: невозможно удалить файл')
        Case 1
            MsgBox(64, 'Удаление файла', 'Файл удаления: ' & $sFilePath & @CRLF & @CRLF & 'Результат: ' & @error & @CRLF & @CRLF & _
            'Файл удален')
    EndSwitch
EndFunc
Func
_MainWin_FileDelete_WInAPI()
    Local $sFilePath = GUICtrlRead($hMainWinFileDeletePath)
    Local $sMsg = _FileDelete_WinApi($sFilePath)
    Switch @error
        Case -1
            MsgBox(48, 'Удаление файла', 'Файл удаления: ' & $sFilePath & @CRLF & @CRLF & 'Результат: ' & @error & @CRLF & @CRLF & _
            'Удаляемый файл ненайден')
        Case 0
            MsgBox(48, 'Удаление файла', 'Файл удаления: ' & $sFilePath & @CRLF & @CRLF & 'Результат: ' & @error & @CRLF & @CRLF & _
            $sMsg)
        Case 1
            MsgBox(64, 'Удаление файла', 'Файл удаления: ' & $sFilePath & @CRLF & @CRLF & 'Результат: ' & @error & @CRLF & @CRLF & _
            'Файл удален')
    EndSwitch
EndFunc

#endregion
 
#region: - After creating all GUI

    _MainWin_Create()
#endregion
#region: - Sleep, Exit

While 1
    Sleep(100)
WEnd
 
Func
_Pro_Exit()
    Exit
EndFunc

#endregion
 
Func _FileDelete_AutoIt($sFilePath)
    If NOT FileExists($sFilePath) Then
        SetError(-1)
        Return SetError(-1)
    EndIf
 
    Local
$fResult = FileDelete($sFilePath)
 
    SetError($fResult)
    Return $fResult
EndFunc
 
Func
_FileDelete_WinApi($sFilePath)
    If NOT FileExists($sFilePath) Then
        SetError(-1)
        Return SetError(-1)
    EndIf
 
    Local
$aDllCall = DllCall( _
                'kernel32.dll', 'int', _
                'DeleteFile', _
                'str', $sFilePath)
 
    If $aDllCall[0] == 0 Then
        SetError(0)
        Return _GetLastErrorMessage()
    Else
        SetError(1)
        Return 1
    EndIf
EndFunc

;===============================================
;    _GetLastErrorMessage($DisplayMsgBox="")
;    Format the last windows error as a string and return it
;    if $DisplayMsgBox <> "" Then it will display a message box w/ the error
;    Return        Window's error as a string
;===============================================

Func _GetLastErrorMessage($sDisplayMsgBox = '')
    Local $aDllCall, $iLastError, $sErrorMsg
    Local $iPtr = DllStructCreate('char[4096]')
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
 
    If @error Then Return ''
 
    $aDllCall= DllCall('Kernel32.dll', 'int', 'GetLastError')
    $iLastError = $aDllCall[0]
 
    $aDllCall = DllCall('kernel32.dll', 'int', 'FormatMessage', _
            'int', $FORMAT_MESSAGE_FROM_SYSTEM, _
            'ptr', 0, _
            'int', $iLastError, _
            'int', 0, _
            'ptr', DllStructGetPtr($iPtr), _
            'int', 4096, _
            'ptr', 0)
    $sErrorMsg = DllStructGetData($iPtr, 1)
 
    If $sDisplayMsgBox <> '' Then MsgBox(0, '_GetLastErrorMessage', $sDisplayMsgBox & ':' & @CRLF & $sErrorMsg & @CRLF & 'Error code: ' & String($iLastError))
 
    Return $sErrorMsg
EndFunc;==>_GetLastErrorMessage


Всего записей: 556 | Зарегистр. 21-11-2007 | Отправлено: 22:33 07-04-2009 | Исправлено: sproxy, 00:59 08-04-2009
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » AutoIT (Часть 2)
Widok (01-06-2010 13:08): Лимит страниц. Продолжаем здесь.


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru