Advertisement
AZJIO

Notepad

Jun 23rd, 2013
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.81 KB | None | 0 0
  1. #include <Misc.au3>
  2. #include <GuiEdit.au3>
  3. #include <GuiMenu.au3>
  4. #include <GUIConstantsEx.au3>
  5. #include <WindowsConstants.au3>
  6.  
  7. Local $sPathCur, $ifCharSet = 0
  8.  
  9. ; Установки шрифта
  10. $sFontName = 'Arial'
  11. $iPointSize = 10
  12. $iColorRef = 0
  13. $iFontWeight = 400
  14. $iItalic = False
  15. $iUnderline = False
  16. $iStrikethru = False
  17.  
  18. $hGui = GUICreate('Безымянный - Блокнот AutoIt3', 500, 400, -1, -1, BitOR($WS_POPUP, $WS_OVERLAPPEDWINDOW), $WS_EX_COMPOSITED)
  19. GUISetIcon('shell32.dll', 2)
  20.  
  21. $iMenuFile = GUICtrlCreateMenu('Файл')
  22. $iMenuNew = GUICtrlCreateMenuItem('Новый', $iMenuFile)
  23. $iMenuOpen = GUICtrlCreateMenuItem('Открыть', $iMenuFile)
  24. $iMenuSave = GUICtrlCreateMenuItem('Сохранить', $iMenuFile)
  25. $iMenuSaveAs = GUICtrlCreateMenuItem('Сохранить как...', $iMenuFile)
  26. $iMenuExit = GUICtrlCreateMenuItem('Выход', $iMenuFile)
  27.  
  28. $iMenuEdit = GUICtrlCreateMenu('Правка')
  29. $iMenuUndo = GUICtrlCreateMenuItem('Отменить', $iMenuEdit)
  30. $iMenuSelAll = GUICtrlCreateMenuItem('Выделить всё', $iMenuEdit)
  31. $iMenuFrmt = GUICtrlCreateMenu('Формат')
  32. $iMenuMultu = GUICtrlCreateMenuItem('Перенос по словам', $iMenuFrmt)
  33. GUICtrlSetState(-1, $GUI_CHECKED)
  34. $iMenuFont = GUICtrlCreateMenuItem('Шрифт', $iMenuFrmt)
  35. $iMenuView = GUICtrlCreateMenu('Вид')
  36. $iMenuHelp = GUICtrlCreateMenu('Справка')
  37. $iMenuAbout = GUICtrlCreateMenuItem('О программе', $iMenuHelp)
  38.  
  39. $hMenuFile = _GUICtrlMenu_GetMenu($hGui)
  40. $aRect = _GUICtrlMenu_GetItemRect($hGui, $hMenuFile, 0)
  41. $iStyle = BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_NOHIDESEL, $ES_WANTRETURN)
  42. $iEdit = GUICtrlCreateEdit('', 0, 0, 500, 400 - ($aRect[3] - $aRect[1]), $iStyle)
  43. $hEdit = GUICtrlGetHandle(-1)
  44.  
  45. GUISetState()
  46. While 1
  47.     Switch GUIGetMsg()
  48.         Case $iMenuFont
  49.             $a_font = _ChooseFont($sFontName, $iPointSize, $iColorRef, $iFontWeight, $iItalic, $iUnderline, $iStrikethru, $hGui)
  50.             If @error Then ContinueLoop
  51.             If BitAND($a_font[1], 2) Then
  52.                 $iItalic = True
  53.             Else
  54.                 $iItalic = False
  55.             EndIf
  56.             If BitAND($a_font[1], 4) Then
  57.                 $iUnderline = True
  58.             Else
  59.                 $iUnderline = False
  60.             EndIf
  61.             If BitAND($a_font[1], 8) Then
  62.                 $iStrikethru = True
  63.             Else
  64.                 $iStrikethru = False
  65.             EndIf
  66.             $sFontName = $a_font[2]
  67.             $iPointSize = $a_font[3]
  68.             $iFontWeight = $a_font[4]
  69.             $iColorRef = $a_font[5]
  70.             $iFntStl = 0
  71.             If $iItalic Then $iFntStl = 2
  72.             If $iUnderline Then $iFntStl += 4
  73.             If $iStrikethru Then $iFntStl += 8
  74.             GUICtrlSetFont($iEdit, $iPointSize, $iFontWeight, $iFntStl, $sFontName)
  75.             GUICtrlSetColor($iEdit, $a_font[7])
  76.             $a_font = 0
  77.            
  78.         Case $iMenuSelAll
  79.             _GUICtrlEdit_SetSel($hEdit, 0, -1)
  80.         Case $iMenuUndo
  81.             _GUICtrlEdit_Undo($hEdit)
  82.         Case $iMenuNew
  83.             GUICtrlSetData($iEdit, '')
  84.             $sPathCur = ''
  85.             WinSetTitle($hGui, '', 'Безымянный - Блокнот AutoIt3')
  86.             $ifCharSet = 0
  87.         Case $iMenuOpen
  88.             $sPath = FileOpenDialog('Открыть', @WorkingDir, 'Текстовые документы (*.txt)|Все (*)', 8, '', $hGui)
  89.             If @error Then ContinueLoop
  90.             $ifCharSet = FileGetEncoding($sPath)
  91.             $sText = FileRead($sPath)
  92.             GUICtrlSetData($iEdit, $sText)
  93.             $sPathCur = $sPath
  94.             $sText = 0
  95.             $sPath = StringRegExpReplace($sPath, '^(?:.*\\)([^\\]+?)(\.[^.]+)?$', '\1\2')
  96.             WinSetTitle($hGui, '', $sPath & ' - Блокнот AutoIt3')
  97.         Case $iMenuSave
  98.             If FileExists($sPathCur) Then
  99.                 $sText = GUICtrlRead($iEdit)
  100.                 $hFile = FileOpen($sPathCur, 2 + $ifCharSet)
  101.                 FileWrite($hFile, $sText)
  102.                 FileClose($hFile)
  103.                 $sText = 0
  104.             Else
  105.                 ContinueCase
  106.             EndIf
  107.         Case $iMenuSaveAs
  108.             $sPath = FileSaveDialog("Сохранить как", @WorkingDir, 'Текстовые документы (*.txt)|Все (*)', 16, '', $hGui)
  109.             If @error Then ContinueLoop
  110.             $sText = GUICtrlRead($iEdit)
  111.             $hFile = FileOpen($sPath, 2 + $ifCharSet)
  112.             FileWrite($hFile, $sText)
  113.             FileClose($hFile)
  114.             $sPathCur = $sPath
  115.             $sText = 0
  116.             $sPath = StringRegExpReplace($sPath, '^(?:.*\\)([^\\]+?)(\.[^.]+)?$', '\1\2')
  117.             WinSetTitle($hGui, '', $sPath & ' - Блокнот AutoIt3')
  118.         Case $iMenuAbout
  119.             MsgBox(0, 'О программе', 'Программа является примером стандартного ' & @LF & 'блокнота, созданного с помощью AutoIt3.')
  120.         Case $iMenuMultu
  121.             If BitAND(GUICtrlRead($iMenuMultu), $GUI_CHECKED) Then
  122.                 GUICtrlSetState($iMenuMultu, $GUI_UNCHECKED)
  123.                 ; GUICtrlSetStyle($iEdit, 0)
  124.                 GUICtrlSetStyle($iEdit, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $WS_HSCROLL, $ES_AUTOHSCROLL))
  125.                 ; GUICtrlSetStyle($iEdit, $GUI_SS_DEFAULT_EDIT)
  126.             Else
  127.                 GUICtrlSetState($iMenuMultu, $GUI_CHECKED)
  128.                 ; GUICtrlSetStyle($iEdit, 0)
  129.                 GUICtrlSetStyle($iEdit, $iStyle)
  130.             EndIf
  131.         Case $GUI_EVENT_CLOSE, $iMenuExit
  132.             Exit
  133.     EndSwitch
  134. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement