Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Misc.au3>
- #include <GuiEdit.au3>
- #include <GuiMenu.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- Local $sPathCur, $ifCharSet = 0
- ; Установки шрифта
- $sFontName = 'Arial'
- $iPointSize = 10
- $iColorRef = 0
- $iFontWeight = 400
- $iItalic = False
- $iUnderline = False
- $iStrikethru = False
- $hGui = GUICreate('Безымянный - Блокнот AutoIt3', 500, 400, -1, -1, BitOR($WS_POPUP, $WS_OVERLAPPEDWINDOW), $WS_EX_COMPOSITED)
- GUISetIcon('shell32.dll', 2)
- $iMenuFile = GUICtrlCreateMenu('Файл')
- $iMenuNew = GUICtrlCreateMenuItem('Новый', $iMenuFile)
- $iMenuOpen = GUICtrlCreateMenuItem('Открыть', $iMenuFile)
- $iMenuSave = GUICtrlCreateMenuItem('Сохранить', $iMenuFile)
- $iMenuSaveAs = GUICtrlCreateMenuItem('Сохранить как...', $iMenuFile)
- $iMenuExit = GUICtrlCreateMenuItem('Выход', $iMenuFile)
- $iMenuEdit = GUICtrlCreateMenu('Правка')
- $iMenuUndo = GUICtrlCreateMenuItem('Отменить', $iMenuEdit)
- $iMenuSelAll = GUICtrlCreateMenuItem('Выделить всё', $iMenuEdit)
- $iMenuFrmt = GUICtrlCreateMenu('Формат')
- $iMenuMultu = GUICtrlCreateMenuItem('Перенос по словам', $iMenuFrmt)
- GUICtrlSetState(-1, $GUI_CHECKED)
- $iMenuFont = GUICtrlCreateMenuItem('Шрифт', $iMenuFrmt)
- $iMenuView = GUICtrlCreateMenu('Вид')
- $iMenuHelp = GUICtrlCreateMenu('Справка')
- $iMenuAbout = GUICtrlCreateMenuItem('О программе', $iMenuHelp)
- $hMenuFile = _GUICtrlMenu_GetMenu($hGui)
- $aRect = _GUICtrlMenu_GetItemRect($hGui, $hMenuFile, 0)
- $iStyle = BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_NOHIDESEL, $ES_WANTRETURN)
- $iEdit = GUICtrlCreateEdit('', 0, 0, 500, 400 - ($aRect[3] - $aRect[1]), $iStyle)
- $hEdit = GUICtrlGetHandle(-1)
- GUISetState()
- While 1
- Switch GUIGetMsg()
- Case $iMenuFont
- $a_font = _ChooseFont($sFontName, $iPointSize, $iColorRef, $iFontWeight, $iItalic, $iUnderline, $iStrikethru, $hGui)
- If @error Then ContinueLoop
- If BitAND($a_font[1], 2) Then
- $iItalic = True
- Else
- $iItalic = False
- EndIf
- If BitAND($a_font[1], 4) Then
- $iUnderline = True
- Else
- $iUnderline = False
- EndIf
- If BitAND($a_font[1], 8) Then
- $iStrikethru = True
- Else
- $iStrikethru = False
- EndIf
- $sFontName = $a_font[2]
- $iPointSize = $a_font[3]
- $iFontWeight = $a_font[4]
- $iColorRef = $a_font[5]
- $iFntStl = 0
- If $iItalic Then $iFntStl = 2
- If $iUnderline Then $iFntStl += 4
- If $iStrikethru Then $iFntStl += 8
- GUICtrlSetFont($iEdit, $iPointSize, $iFontWeight, $iFntStl, $sFontName)
- GUICtrlSetColor($iEdit, $a_font[7])
- $a_font = 0
- Case $iMenuSelAll
- _GUICtrlEdit_SetSel($hEdit, 0, -1)
- Case $iMenuUndo
- _GUICtrlEdit_Undo($hEdit)
- Case $iMenuNew
- GUICtrlSetData($iEdit, '')
- $sPathCur = ''
- WinSetTitle($hGui, '', 'Безымянный - Блокнот AutoIt3')
- $ifCharSet = 0
- Case $iMenuOpen
- $sPath = FileOpenDialog('Открыть', @WorkingDir, 'Текстовые документы (*.txt)|Все (*)', 8, '', $hGui)
- If @error Then ContinueLoop
- $ifCharSet = FileGetEncoding($sPath)
- $sText = FileRead($sPath)
- GUICtrlSetData($iEdit, $sText)
- $sPathCur = $sPath
- $sText = 0
- $sPath = StringRegExpReplace($sPath, '^(?:.*\\)([^\\]+?)(\.[^.]+)?$', '\1\2')
- WinSetTitle($hGui, '', $sPath & ' - Блокнот AutoIt3')
- Case $iMenuSave
- If FileExists($sPathCur) Then
- $sText = GUICtrlRead($iEdit)
- $hFile = FileOpen($sPathCur, 2 + $ifCharSet)
- FileWrite($hFile, $sText)
- FileClose($hFile)
- $sText = 0
- Else
- ContinueCase
- EndIf
- Case $iMenuSaveAs
- $sPath = FileSaveDialog("Сохранить как", @WorkingDir, 'Текстовые документы (*.txt)|Все (*)', 16, '', $hGui)
- If @error Then ContinueLoop
- $sText = GUICtrlRead($iEdit)
- $hFile = FileOpen($sPath, 2 + $ifCharSet)
- FileWrite($hFile, $sText)
- FileClose($hFile)
- $sPathCur = $sPath
- $sText = 0
- $sPath = StringRegExpReplace($sPath, '^(?:.*\\)([^\\]+?)(\.[^.]+)?$', '\1\2')
- WinSetTitle($hGui, '', $sPath & ' - Блокнот AutoIt3')
- Case $iMenuAbout
- MsgBox(0, 'О программе', 'Программа является примером стандартного ' & @LF & 'блокнота, созданного с помощью AutoIt3.')
- Case $iMenuMultu
- If BitAND(GUICtrlRead($iMenuMultu), $GUI_CHECKED) Then
- GUICtrlSetState($iMenuMultu, $GUI_UNCHECKED)
- ; GUICtrlSetStyle($iEdit, 0)
- GUICtrlSetStyle($iEdit, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $WS_HSCROLL, $ES_AUTOHSCROLL))
- ; GUICtrlSetStyle($iEdit, $GUI_SS_DEFAULT_EDIT)
- Else
- GUICtrlSetState($iMenuMultu, $GUI_CHECKED)
- ; GUICtrlSetStyle($iEdit, 0)
- GUICtrlSetStyle($iEdit, $iStyle)
- EndIf
- Case $GUI_EVENT_CLOSE, $iMenuExit
- Exit
- EndSwitch
- WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement