Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

My first REAL try on my own 'Notepad'


  • Please log in to reply
17 replies to this topic

#1 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 15 November 2008 - 04:29 PM

Hi!

I think the title explains enough.

AutoIt         
#include <GUIConstants.au3> #include <Misc.au3> #include <String.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <File.au3> Global $EditField $GUI = GUICreate("Notepad Example", 700, 500, -1, -1, $WS_SIZEBOX) $File = GUICtrlCreateMenu("File") $New = GUICtrlCreateMenuItem("New", $File) $Open = GUICtrlCreateMenuItem("Open...", $File) $Save = GUICtrlCreateMenuItem("Save", $File) $SaveAs = GUICtrlCreateMenuItem("Save As...", $File) GUICtrlCreateMenuItem("", $File) $Print = GUICtrlCreateMenuItem("Print...", $File) GUICtrlCreateMenuItem("", $File) $Exit = GUICtrlCreateMenuItem("Exit", $File) $Edit = GUICtrlCreateMenu("Edit") $Undo = GUICtrlCreateMenuItem("Undo", $Edit) GUICtrlCreateMenuItem("", $Edit) $Cut = GUICtrlCreateMenuItem("Cut", $Edit) $Copy = GUICtrlCreateMenuItem("Copy", $Edit) $Paste = GUICtrlCreateMenuItem("Paste", $Edit) $Delete = GUICtrlCreateMenuItem("Delete", $Edit) GUICtrlCreateMenuItem("", $Edit) $SelectAll = GUICtrlCreateMenuItem("Select All", $Edit) $Time = GUICtrlCreateMenuItem("Time/Date", $Edit) $Show = GUICtrlCreateMenu("Show") $Font = GUICtrlCreateMenuItem("Font...", $Show) $Help = GUICtrlCreateMenu("Help") $About = GUICtrlCreateMenuItem("About", $Help) $Extra = GUICtrlCreateMenu("Extra") $Count = GUICtrlCreateMenuItem("Count...", $Extra) $Reverse = GUICtrlCreateMenuItem("Reverse Text", $Extra) $Hex = GUICtrlCreateMenuItem("Hex Text", $Extra) $UnHex = GUICtrlCreateMenuItem("UnHex Text", $Extra) $Encrypt = GUICtrlCreateMenuItem("Encrypt Text...", $Extra) $EditField = GUICtrlCreateEdit("", 0, 0, 700, 460) GUISetState() While 1     $nMsg = GUIGetMsg()     Select     Case $nMsg = $GUI_EVENT_CLOSE         _Exit()     Case $nMsg = $New         _New()     Case $nMsg = $Open         _Open()     Case $nMsg = $Save         _Save()     Case $nMsg = $SaveAs         _SaveAs()     Case $nMsg = $Print         _Print()     Case $nMsg = $Exit         _Exit()     Case $nMsg = $Undo         Sleep(100)         Send("^z")     Case $nMsg = $Cut         Sleep(100)         Send("^x")     Case $nMsg = $Copy         Sleep(100)         Send("^c")     Case $nmsg = $Paste         Sleep(100)         Send("^v")     Case $nMsg = $Delete         Sleep(100)         Send("{DELETE}")     Case $nMsg = $SelectAll         Sleep(100)         Send("{TAB}")     Case $nMsg = $Time         $TimeDate = @HOUR & ":" & @MIN & " " & @MDAY & "-" & @MON & "-" & @YEAR         Sleep(100)         Send($TimeDate)     Case $nMsg = $Font         $aFont = _ChooseFont("", "", "", "", "", "", "", $GUI)         If $aFont <> -1 Then             GUICtrlSetFont($EditField, $aFont[3], $aFont[4], $aFont[1], $aFont[2])             GUICtrlSetColor($EditField, $aFont[7])         EndIf     Case $nMsg = $About         MsgBox(64, "About", "Notepad Example made by" & @CRLF & "AlmarM")     Case $nMsg = $Count         _Count()     Case $nMsg = $Reverse         _Reverse()     Case $nMsg = $Hex         _Hex()     Case $nMsg = $UnHex         _UnHex()     Case $nMsg = $Encrypt         _Encrypt(GUICtrlRead($EditField))     EndSelect WEnd Func _New()     If GUICtrlRead($EditField) <> "" Then         $MsgBox = MsgBox(51, "", "Save text first?")         If $MsgBox = 6 Then             $read_text = GUICtrlRead($EditField)             $fod_new_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)             FileWrite($fod_new_save & ".txt", $read_text)             GUICtrlSetData($EditField, "")         ElseIf $MsgBox = 7 Then             GUICtrlSetData($EditField, "")         Else         EndIf     Else         GUICtrlSetData($EditField, "")     EndIf EndFunc Func _Open()     If GUICtrlRead($EditField) <> "" Then         $MsgBox = MsgBox(51, "", "Save text first?")         If $MsgBox = 6 Then             $read_text = GUICtrlRead($EditField)             $fod_open_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)             FileWrite($fod_open_save & ".txt", $read_text)             $fod_open = FileOpenDialog("Open...", @DesktopDir, "Text Files (*.txt)", 11, "", $GUI)             $read = FileRead($fod_open)             GUICtrlSetData($EditField, $read)         ElseIf $MsgBox = 7 Then             $fod_open = FileOpenDialog("Open...", @DesktopDir, "Text Files (*.txt)", 11, "", $GUI)             $read = FileRead($fod_open)             WinSetTitle(WinGetTitle("[CLASS:AutoIt v3 GUI]"), "", $fod_save & ".txt")             GUICtrlSetData($EditField, $read)         Else         EndIf     Else         $fod_open = FileOpenDialog("Open...", @DesktopDir, "Text Files (*.txt)", 11, "", $GUI)         $read = FileRead($fod_open)         $gettitle = WinGetTitle("[CLASS:AutoIt v3 GUI]")         WinSetTitle($gettitle, "", $fod_open)         GUICtrlSetData($EditField, $read)     EndIf EndFunc Func _Save()     If WinGetTitle("[CLASS:AutoIt v3 GUI]") <> "Notepad Example" Then         $gettitle = WinGetTitle("[CLASS:AutoIt v3 GUI]")         FileWrite($gettitle, GUICtrlRead($EditField))     Else         $fod_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)         If $fod_save <> "" Then             $read = GUICtrlRead($EditField)             FileWrite($fod_save & ".txt", $read)             WinSetTitle(WinGetTitle("[CLASS:AutoIt v3 GUI]"), "", $fod_save & ".txt")         EndIf     EndIf EndFunc Func _SaveAs()     $fod_saveas = FileSaveDialog("Save As...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)     If $fod_saveas <> "" Then         $read = GUICtrlRead($EditField)         FileWrite($fod_save & ".txt", $read)     EndIf EndFunc Func _Print()     $Read = GUICtrlRead($EditField)     $Random = Random(000000, 999999, 1)     $x = FileWrite(@TempDir & "\$~" & $Random & ".txt", $Read)     $File = @TempDir & "\$~" & $Random & ".txt"     _FilePrint($File)     Sleep(1000)     FileDelete($File) EndFunc Func _Count()     $_Split = StringSplit(GUICtrlRead($EditField), Chr(10))         $ReplaceCR = StringReplace(GUICtrlRead($EditField), Chr(10), " ")     $Words = StringSplit($ReplaceCR, " ")         MsgBox(64, Default, "Total Characters   : " & StringLen(GUICtrlRead($EditField)) & @CRLF & _                         "Total Words    : " & $Words[0] & @CRLF & _                         "Total Lines    : " & $_Split[0]) EndFunc Func _Reverse()     $read = GUICtrlRead($EditField)     $rev = _StringReverse($read)     GUICtrlSetData($EditField, $rev) EndFunc Func _Hex()     $Read = GUICtrlRead($EditField)     $x = _StringToHex($Read)     GUICtrlSetData($EditField, $x) EndFunc Func _UnHex()     $Read = GUICtrlRead($EditField)     $x = _HexToString($Read)     GUICtrlSetData($EditField, $x) EndFunc Func _Encrypt($nText)     $Main = GUICreate("Encrypt", 400, 400, -1, -1)     $EditText = GUICtrlCreateEdit("", 5, 5, 390, 350)     GUICtrlSetData($EditText, $nText)     $InputPass = GUICtrlCreateInput("", 5, 367, 100, 20, BitOR($ES_PASSWORD, $ES_CENTER))     $InputLevel = GUICtrlCreateInput("1", 110, 367, 50, 20, $SM_REMOTECONTROL)     $UpDown = GUICtrlCreateUpDown($InputLevel)     GUICtrlSetLimit($UpDown, 10, 1)     $EncryptButton = GUICtrlCreateButton("Encrypt", 170, 360, 105, 35)     $DecryptButton = GUICtrlCreateButton("Decrypt", 285, 360, 105, 35)         GUISetState()     While 1         $nMsg = GUIGetMsg()         Select         Case $nMsg = $GUI_EVENT_CLOSE             GUIDelete($Main)             ExitLoop         Case $nMsg = $EncryptButton             $Read_Text = GUICtrlRead($EditText)             $Read_Level = GUICtrlRead($InputPass)             $Read_Pass = GUICtrlRead($InputPass)             GUICtrlSetData($EditText, "Encrypting...")             $x = _StringEncrypt(1, $Read_Text, $Read_Pass, $Read_Level)             GUICtrlSetData($EditText, $x)         Case $nmsg = $DecryptButton             $Read_Text = GUICtrlRead($EditText)             $Read_Level = GUICtrlRead($InputPass)             $Read_Pass = GUICtrlRead($InputPass)             GUICtrlSetData($EditText, "Decrypting...")             $x = _StringEncrypt(0, $Read_Text, $Read_Pass, $Read_Level)             GUICtrlSetData($EditText, $x)         EndSelect     WEnd EndFunc Func _Exit()     If GUICtrlRead($EditField) <> "" Then         $MsgBox = MsgBox(51, "", "Save text first?")         If $MsgBox = 6 Then             $read_text = GUICtrlRead($EditField)             $fod_new_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)             FileWrite($fod_new_save & ".txt", $read_text)             GUICtrlSetData($EditField, "")         ElseIf $MsgBox = 7 Then             Exit         Else         EndIf     Else         Exit     EndIf EndFunc


[19-11-2009] Update ~ Fixed some bugs and glitches.
AlmarM

Edited by AlmarM, 19 November 2009 - 08:31 PM.

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.








#2 gseller

gseller

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,057 posts

Posted 15 November 2008 - 05:58 PM

Good work.. The only trouble I see right off hand is needs error correction on the fonts, if you click on show/fonts and click cancel it errors out with
Notepad.au3 (93) : ==> Subscript used with non-Array variable.: GUICtrlSetFont($EditField, $aFont[3], $aFont[4], $aFont[1], $aFont[2]) GUICtrlSetFont($EditField, $aFont^ ERROR ->11:55:16 AutoIT3.exe ended.rc:1 >Exit code: 1    Time: 25.160


#3 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 15 November 2008 - 08:12 PM

Good work.. The only trouble I see right off hand is needs error correction on the fonts, if you click on show/fonts and click cancel it errors out with

Notepad.au3 (93) : ==> Subscript used with non-Array variable.: GUICtrlSetFont($EditField, $aFont[3], $aFont[4], $aFont[1], $aFont[2]) GUICtrlSetFont($EditField, $aFont^ ERROR ->11:55:16 AutoIT3.exe ended.rc:1 >Exit code: 1    Time: 25.160

It works for me :S
Those are the return values for '_ChooseFont'
Return Value Success: Array in the following format:     [0] - contains the number of elements     [1] - attributes = BitOr of italic:2, undeline:4, strikeout:8     [2] - fontname     [3] - font size = point size     [4] - font weight = = 0-1000     [5] - COLORREF rgbColors     [6] - Hex BGR Color     [7] - Hex RGB Color Failure: -1

Dont know why it wont work.

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.


#4 Nahuel

Nahuel

    To Err is human, to Arr is pirate.

  • Active Members
  • PipPipPipPipPipPip
  • 1,841 posts

Posted 15 November 2008 - 08:48 PM

Doesn't work if you press cancel. If you press cancel, the variable returned is not an array.

#5 Innovative

Innovative

    Super powers FTW!

  • Active Members
  • PipPipPipPipPipPip
  • 572 posts

Posted 16 November 2008 - 06:15 AM

Can try adding a IsArray check before setting the font .

#6 dbzfanatic

dbzfanatic

    functional psychopath!!

  • Active Members
  • PipPipPipPipPipPip
  • 1,090 posts

Posted 16 November 2008 - 08:52 AM

You're a little copy-cat aren't you? lol You were in my STE thread too. Just messing with you. You could also add a check to make sure it isn't null.
If $aFont[0] <> "" and IsArray($aFont[0]) Then

Or simply use one check or the other :mellow:.

#7 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 16 November 2008 - 10:53 AM

Added some Extra Functions ^^,

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.


#8 gseller

gseller

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,057 posts

Posted 16 November 2008 - 04:07 PM

Nice additions! :mellow:

#9 Achilles

Achilles

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,897 posts

Posted 16 November 2008 - 08:28 PM

Nice work on what you have... I think you add hotkeys for the functions... like Ctrl S.

#10 IKilledBambi

IKilledBambi

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 21 November 2008 - 08:22 AM

Found a bug. If you type show font, then if you cancel because you decided you didn't want to change it exits the whole script.
I had to add global before
$fod_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)
Last of all the text encrypter didn't work or I was to stupid to use it, if i was to stupid itd be nice if it said how. :mellow: Nice though its better than anything I could ever do.

*Edit - I eventually messed around and figured out how to encrypt it but it would be nice if it dropped a hint like password. And I still couldn't figure out what the numbers meant. :)

*Edit - Just figured out what the numbers are. Thats cool. :(

Edited by IKilledBambi, 21 November 2008 - 08:25 AM.


#11 cheatera

cheatera

    Seeker

  • Banned (NOT IN USE)
  • 13 posts

Posted 21 November 2008 - 09:07 AM

this isnt bad at all but it has some bugs:
when i try to "Save" or "Save as ... " u didnt put a case if user cancels. so when u click "Save" then cancel, it still saves it with a blank name ".txt", and when u click "Save as ..." and hit cancel it pop-ups error win for var not decalred. if i can help u, this is my solution:
Func _Save()     If WinGetTitle("[CLASS:AutoIt v3 GUI]") <> "Notepad Example" Then         $gettitle = WinGetTitle("[CLASS:AutoIt v3 GUI]")         FileWrite($gettitle, GUICtrlRead($EditField))     Else         $fod_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)         If $fod_save <> "" then ;detects if user inputs anything at all, if not just returning to main loop, if yes - saves                  $read = GUICtrlRead($EditField)                  FileWrite($fod_save & ".txt", $read)                  WinSetTitle(WinGetTitle("[CLASS:AutoIt v3 GUI]"), "", $fod_save)         EndIf     EndIf EndFunc


and now "Save as ...":
Func _SaveAs()     $fod_saveas = FileSaveDialog("Save As...", @DesktopDir, "Text Files (*.txt)", 18, "", $GUI)     If $fod_saveas <> "" then; same detect         $read = GUICtrlRead($EditField)                     FileWrite($fod_save & ".txt", $read)     EndIf EndFunc


and as IKilledBambi said - font has bug too. u must think of any action the user may take, and have good response on it.
when u click on "Font" and then hit cancel (again :mellow: ) it pop-ups error and exits.
    Case $nMsg = $Font         $aFont = _ChooseFont("", "", "", "", "", "", "", $GUI)     If $aFont <> -1 then; if user cancels $aFont becomes -1 so we check if its NOT -1 to continue normaly, otherwise it will return to main loop             GUICtrlSetFont($EditField, $aFont[3], $aFont[4], $aFont[1], $aFont[2])             GUICtrlSetColor($EditField, $aFont[7])     EndIf

Edited by cheatera, 21 November 2008 - 09:09 AM.

Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)

#12 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 21 November 2008 - 04:14 PM

Thx people! The newer _Save, _SaveAs, Case $nMsg = $Font helped me alot :mellow:
Updated in first post!

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.


#13 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 19 November 2009 - 08:31 PM

After a long time, I decided to fix the bugs and glitches in my notepad example. Source in the first post. :)

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.


#14 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,067 posts

Posted 20 November 2009 - 10:55 AM

Nice update...

Have you ever considered switching to OnEvent mode? Looking at that case it would only require a few more functions...

Also for the undo etc.

how about going proffessional and using GUICtrlSendMsg instead of Send ("^z")

http://msdn.microsoft.com/en-us/library/bb775458(VS.85,lightweight).aspx

thats the page you want :) Its very easy and it'll make it a whole lot more proffessional.

Spoiler


The other thing which you have to remember is what happens if they undo after saving...

Spoiler


Just something to think about ;)

Mat

#15 yashrai

yashrai

    Seeker

  • Active Members
  • 19 posts

Posted 20 November 2009 - 12:38 PM

works.fine.how.to.make.findtext.button........................or.repalce.text.button////////////

help.me

#16 Asaman83687

Asaman83687

    Seeker

  • Active Members
  • 7 posts

Posted 21 November 2009 - 09:27 AM

Just a thing.

I believe that you should open this file in OVERWRITE mode, not with the APPEND thing. FileWrite()'s fault.


:)

#17 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 22 November 2009 - 01:11 PM

Thanks for the feedback and idea's! I'll take a look at the site you gave me and i'll try to update is some. ^^,

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.


#18 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,696 posts

Posted 22 November 2009 - 01:18 PM

Just a thing.

I believe that you should open this file in OVERWRITE mode, not with the APPEND thing. FileWrite()'s fault.


:)

Also, how do I 'open' this file in overwrite mode? Take a look at my "_Save()" function. ;)

Minesweeper

A minesweeper game created in autoit, source available.

 

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

 

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users