Jump to content

Recommended Posts

Posted (edited)

Hi!

I think the title explains enough.

#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

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.

Posted

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

Posted

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.

Posted

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:.

Posted (edited)

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
Posted (edited)

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

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??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Posted

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.

  • 11 months later...
Posted

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.

Posted

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.

GUICtrlSendMsg ($EditField, $EM_UNDO, 0, 0)

or if you really want to look good:

If GUICtrlSendMsg ($EditField, $EM_CANUNDO, 0, 0) Then GUICtrlSendMsg ($EditField, $EM_UNDO, 0, 0)

That'll stop it redoing when you click undo.

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

GUICtrlSendMsg ($EditField, $EM_EMPTYUNDOBUFFER, 0, 0)

Just something to think about ;)

Mat

Posted

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.

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...