Jump to content

(solved) Help Big_Daddy's Spell Check


Recommended Posts

ok.  So I am trying to wrap my head around this spell check function posted by big_daddy.  I am trying to utilize it in a script I am writing, but it is not working as expected, and I expect that it is not working as expected because I am not understanding (certain pieces of) the code and unfamiliar in working with Word Com objects in general.  So the example is pretty easy to follow when you there is only one (edit) control for which you wish to spell check the contents, but say I have a script for which I want to spell check the contents of an edit control and an input control?  I have tried some different methods, like creating a second word com object that mirrors the behavior of the original word com object, but uses entirely separate variables so there is no potential for data to be overwritten.  The code below is what i have so far:

Func _SpellCheck()
    Local $sText, $sText2, $sWord, $sWord2

    $sText = _GUICtrlEdit_GetText ( $Edit1 )
    $oRange = $oWordApp.ActiveDocument.Range
    $oRange.Delete
    $oRange.InsertAfter($sText)
    _SetLanguage()
    $sText2 = GUICtrlRead ( $Input3 )
    $oRange2 = $oWordApp2.ActiveDocument.Range
    $oRange2.Delete
    $oRange2.InsertAfter($sText2)
    _SetLanguage2()

    $oSpellCollection = $oRange.SpellingErrors
    $oSpellCollection2 = $oRange2.SpellingErrors
    If $oSpellCollection.Count > 0 Or $oSpellCollection2.Count > 0 Then
        If BitAND ( WinGetState ( $handle ), 2 ) Then
            If $trans = True Then
                stylish ()
            EndIf
            GUISetState ( @SW_DISABLE, $Form2 )
            GUISetState ( @SW_HIDE, $Form2 )
            GUISwitch ( $Form1 )
            GUISetState ( @SW_SHOW, $Form1 )
            GUISetState ( @SW_ENABLE, $Form1 )
        EndIf

        If $oSpellCollection.Count > 0 Then
        _GUICtrlListBox_ResetContent($ListBox1)
        _GUICtrlListBox_ResetContent($ListBox2)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection.Count
                $sWord = $oSpellCollection.Item($i).Text
                _GUICtrlListBox_AddString($ListBox1, $sWord)
            Next
        GUICtrlSetData($Edit1, $oRange.Text)
        EndIf
    If $oSpellCollection2.Count > 0 Then
        _GUICtrlListBox_ResetContent($ListBox3)
        _GUICtrlListBox_ResetContent($ListBox4)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection2.Count
                $sWord2 = $oSpellCollection2.Item($i).Text
                _GUICtrlListBox_AddString($ListBox3, $sWord2)
            Next
        GUICtrlSetData($Input3, $oRange2.Text)
    EndIf
    Else
        SendMessage ()
    Endif
EndFunc   ;==>_SpellCheck

First, I would like to understand what the purpose of the following line which takes place after populating $listbox1 with the spelling errors:

$guictrlsetdata ( $edit1, $oRange.Text)

As this is present in the original version of big_daddy's spell check script, but I can't figure out for the life of me why it is there...  The second issue is, desptie the fact that I have created and use separate variables to hold the values for the two different controls for which I want to check the spelling of the input text, the $oSpellcollection If statement which processes last (in the above example, $oSpellCollection2) seems to overwrite, negate, or otherwise not process the earlier $oSpellcollection if statement.  For example, if there are spelling errors in the edit (which would be assigned to $oSpellcollection), but no spell errors in the input ($oSpellcollection2), the form which is set to appear if spelling errors were detected in either the edit or the input briefly appears (which tells me that the if statement is being executed, but the spelling errors that are present in the edit do not populate in the form, and since there are no spelling errors in the input, automatically tries to proceed with the rest of the script.  If there were spelling errors in the input, however, only those errors would appear in the form.  Any explanation into this madness would be appreciated.

Edited by MattHiggs
Link to comment
Share on other sites

Full script is posted below.  Seriously?!  Nobody else is able to decipher Big_Daddy's Spell checker?!  I'm shocked

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <ListBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:        William Higgs

 Script Function:
    Provides a graphical user interface for the command line utility "Cmail", which lets one send emails via command line.  I wrote this
    specificially to reduced the ammount of time needed to send messages to potential employers.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <Constants.au3>
#include <Word.au3>
#include <Hunspell.au3>
#include <Array.au3>
OnAutoItExitRegister ( "_Exit" )
Global $trans = False
;_WordErrorHandlerRegister()
If Not FileExists ( @MyDocumentsDir & "\settings.ini" ) Then
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Name","What is the name wou want the recipients of your messages to see in regards to the sender? (Should be your name)",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Name", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Email address","What is your email address or the email address of the account sending the mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("SMTP server","What is the address of the SMTP server for your outgoing mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Port","What is the port used by smtp server?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Port", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Username","What is the username used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "User name", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Password","What is the password used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Password", $sInputBoxAnswer )
EndIf
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_SYSTEMMODAL,"Proxy server?","Does your network utilize a proxy server?")
If $iMsgBoxAnswer = $IDYES  Then
    $sInputBoxAnswer = InputBox("Proxy server","What is the proxy server address?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", $sInputBoxAnswer )
EndIf
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", "False" )
EndIf
EndIf

Global $oWordApp = _Word_Create(False)
Global $oDoc = _Word_DocAdd ( $oWordApp )
Global $oRange = $oDoc.Range
Global $oSpellCollection, $oAlternateWords, $oSpellCollection2, $oAlternateWords2
Global $oWordApp2 = _Word_Create(False)
Global $oDoc2 = _Word_DocAdd ( $oWordApp2 )
Global $oRange2 = $oDoc2.Range
HotKeySet ( "^d", "stylish" )
Global $attach = ""
Global $array
_Spell_Startup ( "C:\hunspell-en_US" )
$sphand = _Spell_HunspellInit ( "C:\hunspell-en_US\en_US.aff", "C:\hunspell-en_US\en_US.dic" )
$Form2 = GUICreate("Form2", 406, 514, 320, 200, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$handle = WinGetHandle ( $Form2 )
$MenuItem1 = GUICtrlCreateMenu("configure")
$MenuItem2 = GUICtrlCreateMenuItem("Attachments", $MenuItem1)
$Label1 = GUICtrlCreateLabel("Email Address", 128, 0, 130, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 70, 32, 273, 21)
$Label2 = GUICtrlCreateLabel("Attachments (Can drag and drop below)", 27, 64, 351, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 32, 104, 337, 21)
GUICtrlSetState ( -1, $GUI_DROPACCEPTED )
$Button9 = GUICtrlCreateButton("Add/Browse", 158, 136, 89, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Label4 = GUICtrlCreateLabel("Subject", 160, 184, 157, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("", 32, 216, 337, 21)
$Label3 = GUICtrlCreateLabel("Message", 160, 240, 172, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Edit1 = GUICtrlCreateEdit("", 32, 272, 345, 153, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$Button1 = GUICtrlCreateButton("Send", 30, 440, 113, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("Save As Template", 160, 440, 105, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button6 = GUICtrlCreateButton ( "Use Template", 282, 440, 113, 33, $BS_NOTIFY )
GUICtrlSetCursor (-1, 0)
$Form1 = GUICreate("Spell Check", 396, 360, 694, 220)
Global $handle2 = WinGetHandle ( $Form1 )
$Label7 = GUICtrlCreateLabel("Subject", 162, 8, 70, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Listbox3 = GUICtrlCreateList("", 24, 40, 137, 97)
$Listbox4 = GUICtrlCreateList("", 232, 40, 137, 97)
$Label8 = GUICtrlCreateLabel("Body", 173, 136, 49, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Listbox1 = GUICtrlCreateList("", 24, 168, 137, 97)
$Listbox2 = GUICtrlCreateList("", 232, 168, 137, 97)
$Label9 = GUICtrlCreateLabel("Errors", 64, 272, 53, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("Corrections", 256, 272, 96, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("Send", 32, 313, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button5 = GUICtrlCreateButton("Correct Spelling", 152, 313, 83, 25, $BS_NOTIFY)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 0)
$Button4 = GUICtrlCreateButton("Cancel", 280, 313, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Form3 = GUICreate("Form3", 286, 283, 192, 124)
$Label5 = GUICtrlCreateLabel("Attachments", 86, 8, 113, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$List1 = GUICtrlCreateList("", 16, 40, 249, 188, BitOR($GUI_SS_DEFAULT_LIST,$LBS_HASSTRINGS))
$Button7 = GUICtrlCreateButton("Delete", 40, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button8 = GUICtrlCreateButton("Back", 160, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Form4 = GUICreate("Form4", 242, 95, 216, 123)
$Combo1 = GUICtrlCreateCombo("", 40, 56, 169, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label6 = GUICtrlCreateLabel("Templates", 72, 8, 96, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_DISABLE, $Form4)
GUISetState( @SW_DISABLE, $Form3 )
GUISetState( @SW_DISABLE, $Form1 )
GUISetState( @SW_SHOW, $Form2 )
$aRect = _GUICtrlEdit_GetRECT($Edit1)
$aRect[0] += 10
$aRect[1] += 10
$aRect[2] -= 10
$aRect[3] -= 10
_GUICtrlEdit_SetRECT($Edit1, $aRect)

While 1
    Global $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $Form2
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
                Case $GUI_EVENT_DROPPED
                    Sleep ( 200 )
                    $mult = StringSplit ( GUICtrlRead ( $Input2 ), "|" )
                    If @error Then
                        WinActivate ( $Form2 )
                        WinWaitActive ( $Form2 )
                        GUICtrlSetState ( $Input2, $GUI_FOCUS )
                        Send ( "{ENTER}", 0 )
                    Else
                        For $v = 1 To $mult[0] Step 1
                            $attach = $attach & $mult[$v] & ";"
                        Next
                        GUICtrlSetData ( $Input2, "" )
                            $sToolTipAnswer = ToolTip("The attachments were added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    EndIf

                Case $MenuItem2
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form3 )
                    GUISetState ( @SW_SHOW, $Form3 )
                    If $attach <> "" Then
                        $array = StringSplit ( StringTrimRight ( $attach, 1 ), ";" )
                        If @error Then
                            SetError ( 0 )
                            _GUICtrlListBox_AddString ( $List1, _GetFilename ( StringTrimRight ( $attach, 1 ) ) & "." & _GetFilenameExt ( StringTrimRight ( $attach, 1 ) ) )
                        Else
                            For $l = 1 To $array[0] Step 1
                                _GUICtrlListBox_AddString ( $List1, _GetFilename ( $array[$l] ) & "." & _GetFilenameExt ( $array[$l] ) )
                            Next
                        EndIf
                    Else
                        _GUICtrlListBox_AddString ( $List1, "You currently do not have any attachments." )
                    EndIf
                Case $Input2
                    $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                    GUICtrlSetData ( $Input2, "" )
                    $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                    Sleep ( 3000 )
                    ToolTip ("")

                Case $Button9
                    If GUICtrlRead ( $Input2 ) <> "" Then
                        $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                        GUICtrlSetData ( $Input2, "" )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    Else
                        $file = FileOpenDialog ( "Choose the file you want to attach.", "", "All (*.*)", 7, "", $Form2 )
                        $files = StringSplit ( $file, "|" )
                        If @error Then
                            SetError ( 0 )
                            $attach = $attach & $file & ";"
                            GUICtrlSetData ( $Input2, $file )
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                            GUICtrlSetData ( $Input2, "" )
                        Else
                            For $p = 2 To $files[0] Step 1
                                $attach = $attach & $files[1] & "\" & $files[$p] & ";"
                            Next
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                        EndIf
                    EndIf
                Case $Button1
                    _GUICtrlEdit_SetSel ( $Edit1, 0, -1 )
                    _SpellCheck ()
                Case $Button2;save as template
                    If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
                    $sInputBoxAnswer = InputBox("Template Name","What do you want to name this template?",""," ")
                    If @Error = 1 Then

                    Else
                        $name = $sInputBoxAnswer
                        $num = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                        $num += 1
                        $bodcap = _GUICtrlEdit_GetText ( $Edit1 )
                        $subcap = GUICtrlRead ( $Input3 )
                        $attcap = $attach
                        Local $holdarr[5][2] = [[3, ""], ["Name", $name], ["Body", $bodcap], ["Subject", $subcap], ["Attachments", $attcap]]
                        IniWriteSection ( @MyDocumentsDir & "\settings.ini", "Template " & $num, $holdarr )
                        IniWrite ( @MyDocumentsDir & "\settings.ini", "Number", "Template", $num )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 2000 )
                        ToolTip ( "" )
                    EndIf

                Case $Button6
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form4 )
                    GUISetState ( @SW_SHOW, $Form4 )
                    $numag = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag = 0 Then
                        MsgBox($MB_OK + $MB_ICONHAND,"No templates","You have not configured any templates.")
                    Else
                        For $h = 1 To $numag Step 1
                            GUICtrlSetData ( $Combo1, IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ) )
                        Next
                    EndIf

            EndSwitch
        Case $Form1
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $ListBox1
                    ;_SpellingSuggestions()
                Case $ListBox2
                    GUICtrlSetState($Button5, $GUI_ENABLE)
                Case $Button3
                    SendMessage ()
                Case $Button4
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Button5
                    ;_ReplaceWord()
            EndSwitch
        Case $Form3
            ToolTip ("")
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE, $Button8
                    ToolTip ("")
                    GUISetState ( @SW_HIDE, $Form3 )
                    GUISetState ( @SW_DISABLE, $Form3 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                    If UBound ( $array ) = 1 Then
                            $attach = ""
                        Else
                            $attach = ""
                            For $ff = 1 To UBound ( $array ) - 1 Step 1
                                $attach = $attach & $array[$ff] & ";"
                            Next
                        EndIf
                        _GUICtrlListBox_ResetContent ( $List1 )
                Case $List1
                    ToolTip ("")
                Case $Button7
                    If _GUICtrlListBox_GetSelCount = -1 Then
                        $sToolTipAnswer = ToolTip("Select something to delete first numbnuts.",Default,Default,"Idiot")
                    Else
                        ToolTip ("")
                        $seltext = _GUICtrlListBox_GetText ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                        For $ff = 1 To $array[0] Step 1
                            If StringInStr ( $array[$ff], $seltext ) > 0 Then
                                _ArrayDelete ( $array, $ff )
                                _GUICtrlListBox_DeleteString ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                                ExitLoop
                            EndIf
                        Next
                    EndIf
            EndSwitch
        Case $Form4
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form4 )
                    GUISetState ( @SW_DISABLE, $Form4 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Combo1
                    $sec = ""
                    $numag2 = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag2 = 0 Then

                    Else
                        $use = GUICtrlRead ( $Combo1 )
                        For $h = 1 To $numag2 Step 1
                            If StringCompare ( IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ), $use ) = 0 Then
                                $sec = "Template " & $h
                                ExitLoop
                            Else
                                ContinueLoop
                            EndIf
                        Next
                        GUISetState ( @SW_HIDE, $Form4 )
                        GUISetState ( @SW_DISABLE, $Form4 )
                        GUISwitch ( $Form2 )
                        GUISetState ( @SW_ENABLE, $Form2 )
                        GUISetState ( @SW_SHOW, $Form2 )
                        $attach = IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Attachments", "NA" )
                        GUICtrlSetData ( $Input3, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Subject", "NA" ) )
                        _GUICtrlEdit_SetText ( $Edit1, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Body", "NA" ) )
                    EndIf
            EndSwitch
    EndSwitch
WEnd
Func stylish ()
    $thestyle = GUIGetStyle ( $handle )
    If $trans = False Then
        GUISetStyle ( -1, $thestyle[1] + 32, $handle )
        WinSetTrans ( $handle, "", 170 )
        $trans = True
    Else
        GUISetStyle ( -1, $thestyle[1] - 32, $handle )
        WinSetTrans ( $handle, "", 255 )
        $trans = False
    EndIf
EndFunc
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If IsArray($iRet) Then Return HWnd($iRet[0])
    Return SetError(1, 0, 0)
EndFunc
Func _SpellCheck()
    Local $sText, $sText2, $sWord, $sWord2

    $sText = _GUICtrlEdit_GetText ( $Edit1 )
    $oRange = $oWordApp.ActiveDocument.Range
    $oRange.Delete
    $oRange.InsertAfter($sText)
    _SetLanguage()
    $sText2 = GUICtrlRead ( $Input3 )
    $oRange2 = $oWordApp2.ActiveDocument.Range
    $oRange2.Delete
    $oRange2.InsertAfter($sText2)
    _SetLanguage2()

    $oSpellCollection = $oRange.SpellingErrors
    $oSpellCollection2 = $oRange2.SpellingErrors
    If $oSpellCollection.Count > 0 Or $oSpellCollection2.Count > 0 Then
        If BitAND ( WinGetState ( $handle ), 2 ) Then
            If $trans = True Then
                stylish ()
            EndIf
            GUISetState ( @SW_DISABLE, $Form2 )
            GUISetState ( @SW_HIDE, $Form2 )
            GUISwitch ( $Form1 )
            GUISetState ( @SW_SHOW, $Form1 )
            GUISetState ( @SW_ENABLE, $Form1 )
        EndIf

        If $oSpellCollection.Count > 0 Then
        _GUICtrlListBox_ResetContent($ListBox1)
        _GUICtrlListBox_ResetContent($ListBox2)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection.Count
                $sWord = $oSpellCollection.Item($i).Text
                _GUICtrlListBox_AddString($ListBox1, $sWord)
            Next
        GUICtrlSetData($Edit1, $oRange.Text)
        EndIf
    If $oSpellCollection2.Count > 0 Then
        _GUICtrlListBox_ResetContent($ListBox3)
        _GUICtrlListBox_ResetContent($ListBox4)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection2.Count
                $sWord2 = $oSpellCollection2.Item($i).Text
                _GUICtrlListBox_AddString($ListBox3, $sWord2)
            Next
        GUICtrlSetData($Input3, $oRange2.Text)
    EndIf
    EndIf

        SendMessage ()
EndFunc   ;==>_SpellCheck

Func _SpellingSuggestions()
    Local $iWord, $sWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    If $iWord <= $oSpellCollection.Count Then
        $sWord = $oSpellCollection.Item($iWord).Text
        $oAlternateWords = $oWordApp.GetSpellingSuggestions($sWord)
    Else
        $sWord = $oSpellCollection2.Item($iWord - $oSpellCollection.Count).Text
        $oAlternateWords = $oWordApp2.GetSpellingSuggestions($sWord)
    EndIf



    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _HighlightWord()
    Local $sText, $iWord, $sWord, $iEnd, $iStart
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $sWord = $oSpellCollection.Item($iWord).Text
    $sText = $oRange.Text

    $iStart = ($oSpellCollection.Item($iWord).Start)
    $iEnd = ($oSpellCollection.Item($iWord).End)
    _GUICtrlEdit_SetSel($Edit1, $iStart, $iEnd)
EndFunc   ;==>_HighlightWord

Func _ReplaceWord()
    Local $iWord, $iNewWord, $sWord, $sNewWord, $sText, $sNewText
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $iNewWord = _GUICtrlListBox_GetCurSel($ListBox2) + 1
    If $iWord == $LB_ERR Or $iNewWord == $LB_ERR Then
        MsgBox(48, "Error", "You must first select a word to replace, then a replacement word.")
        Return
    EndIf
    $oSpellCollection.Item($iWord).Text = $oAlternateWords.Item($iNewWord).Name

    GUICtrlSetData($Edit1, $oRange.Text)

    _SpellCheck()

    GUICtrlSetState($Button5, $GUI_DISABLE)
EndFunc   ;==>_ReplaceWord

Func _SetLanguage()
    $sLang = "English"
        $oWordApp.CheckLanguage = False
        $WdLangID = Number(1033)

        If $WdLangID Then
            With $oRange
                .LanguageID = $WdLangID
                .NoProofing = False
            EndWith

        EndIf
EndFunc   ;==>_SetLanguage
Func _SetLanguage2()
    $sLang = "English"
    $oWordApp2.CheckLanguage = False
    $WdLangID = Number(1033)
    If $WdLangID Then
        With $oRange2
                .LanguageID = $WdLangID
                .NoProofing = False
        EndWith
    EndIf
EndFunc
Func SendMessage ()
    If BitAND ( WinGetState ( $handle2 ), 2 ) Then
        GUISetState ( @SW_HIDE, $Form1 )
        GUISetState ( @SW_DISABLE, $Form1 )
        GUISwitch ( $Form2 )
        GUISetState ( @SW_ENABLE, $Form2 )
        GUISetState ( @SW_SHOW, $Form2 )
    EndIf
    $change = StringStripWS ( GUICtrlRead ( $Input1 ), 3 )
    GUICtrlSetData ( $Input1, $change )
    $body = GUICtrlRead ( $Edit1 )
    _GUICtrlEdit_SetText ( $Edit1, "" )
    ;$attach = StringStripCR ( $attach )
    $subject = GUICtrlRead ( $Input3 )
    If $attach <> "" Then
        $split = StringSplit ( StringTrimRight ( $attach, 1 ), ';' )
        If @error Then
            SetError ( 0 )
            $finattach = '-a:"' & $attach & '" '
        Else
            $finattach = Null
            For $i = 1 To $split[0] Step 1
                $finattach = $finattach & '-a:"' & $split[$i] & '" '
            Next
        EndIf
    EndIf
    $body = StringReplace ( $body, @CRLF, "\n" )
    #cs
    $split = StringSplit ( $body, "", $STR_NOCOUNT )
    For $i = 0 To UBound ( $split ) - 1 Step 1
        If $split[$i] = Chr ( 10 ) Then
            $split[$i] = "\n"
        ElseIf $split[$i] = Chr ( 13 ) Then
            $split[$i] = Null
        Else
            ContinueLoop
        EndIf
    Next
    $body = _ArrayToString ( $split, "" )
    ConsoleWrite ( $body )
    #ce
    If StringRegExp ( GUICtrlRead ( $Input1 ), "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" ) = 1 Then
        If $attach = "" Then
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" -host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
        Else
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
            ClipPut ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d' )
    ProcessWaitClose ( $proc )
    $text = StdoutRead ( $proc )
    ClipPut ( $text )
    MsgBox($MB_OK + $MB_SYSTEMMODAL,"Sent!","Message Sent!!")
        EndIf
    Else
MsgBox(16,"Not a valid email","Enter a correct email address please")
    EndIf
EndFunc

Func _GetFilename($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.FileName
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilename

Func _GetFilenameExt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Extension
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameExt

Func _GetFilenameInt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Name
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameInt

Func _GetFilenameDrive($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return StringUpper($oObjectFile.Drive)
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameDrive

Func _GetFilenamePath($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Path
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenamePath

Func _Exit()
    _Word_Quit ( $oWordApp )
    _Word_Quit ( $oWordApp2 )
    Exit
EndFunc   ;==>_Exit

 

Link to comment
Share on other sites

I couldn't figure out the file structure.  I visited the "Custom Spell Check" and the hunspell.  I also created the WdLanguageID.  I tried twice but I don't have a lot of time and don't know how to set it up.

Can you create a zip with all the necessary files and post it?  I'll have a look at it tomorrow after work.

Edited by Xandy
Link to comment
Share on other sites

Here is my spell check function:

#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Word.au3>

Local $hGui = GUICreate("Spell Checker", 461, 212)
Local $idString = GUICtrlCreateEdit('“To be, or not to be…that is the  question” This  wellknown utterance has been the source of both mystery and wonderment for students around the world since the turn of the 16th century—arguably the zenith of Shakespeare’s creative output. However, the mere ubiquity of this phrase fails to answer some basic questions about it’s rather context. Where did it come  from what does it mean? The first of these questions (where does it come from?) can be answered fairly easily: from Shakespeare’s famous play Hamlet.', 7, 23, 330, 81, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL))
Local $idSpellCheck = GUICtrlCreateButton("Check Spelling", 346, 23, 107, 22)
Local $idUpdate = GUICtrlCreateEdit('', 7, 123, 330, 81, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL))
Local $idCloseGui = GUICtrlCreateButton("Close", 346, 183, 107, 22)
ControlFocus($hGui, "", $idSpellCheck)
GUISetState()

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idCloseGui
            Exit
        Case $idSpellCheck
            GUICtrlSetData($idUpdate, _SpellCheck(GUICtrlRead($idString)))
    EndSwitch
WEnd

Func _SpellCheck($sStringCheck)
    Local Const $wdDialogToolsSpellingAndGrammar = 828 ;~ Word Spelling and Grammar Dialog Window
    Local $oWord, $oDoc, $sSpellCheck = $sStringCheck
    $oWord = _Word_Create(False)
    With $oWord
        ;.Visible = False
        $oDoc = .Documents.Add
        .Selection.Text = $sSpellCheck
        .Dialogs($wdDialogToolsSpellingAndGrammar).Show
        $sSpellCheck = .Selection.Text
        $oDoc.Close($wdDonotSaveChanges)
        .Quit($wdDonotSaveChanges)
    EndWith
    Return $sSpellCheck = "" ? $sStringCheck : $sSpellCheck
EndFunc

 

Link to comment
Share on other sites

It does, however so does the code Matt posted from Big Daddy, although the code was strange to me, basically it opens two Word docs, but only uses one of the docs to post the data from the gui, it then uses Word spell checker and returns the spell checker information to a second AutoIt Gui (which is hidden).  Unfortunately I couldn't get the code working correctly, so thought I'd just write a simpler version utilizing the Word spell checker and dictionary.

Link to comment
Share on other sites

7 hours ago, Subz said:

It does, however so does the code Matt posted from Big Daddy, although the code was strange to me, basically it opens two Word docs, but only uses one of the docs to post the data from the gui, it then uses Word spell checker and returns the spell checker information to a second AutoIt Gui (which is hidden).  Unfortunately I couldn't get the code working correctly, so thought I'd just write a simpler version utilizing the Word spell checker and dictionary.

So when you say you couldn't get the code to work, do mean you couldn't get it to compile correctly or you had issues getting it to behave like I was having issues?

Link to comment
Share on other sites

7 hours ago, Subz said:

It does, however so does the code Matt posted from Big Daddy, although the code was strange to me, basically it opens two Word docs, but only uses one of the docs to post the data from the gui, it then uses Word spell checker and returns the spell checker information to a second AutoIt Gui (which is hidden).  Unfortunately I couldn't get the code working correctly, so thought I'd just write a simpler version utilizing the Word spell checker and dictionary.

@Subz.  So this description is correct for the most part.  However, there is one point which is (supposed to be) incorrect.  I open two word documents with the intention of using both word documents in the script, which is probably where I am going wrong.  My intention was to have one of the word documents hold the contents for the text pulled from the input box and the other word document hold the text pulled from the edit control to make it easier to more easily keep track of which control the text originated from.  I basically just copied the lines of code relevant to spell checking and pasted them a line below the copy, then changed the name of the variables holding the values as to create a second, duplicate word and document object.  Since this is apparently not what I did, would you mind showing me how I can accomplish this?

Link to comment
Share on other sites

@MattHiggs Actually was able to get it working today, previously the second form would only display briefly then disappear, so had to place a MsgBox just to see the Spell Check form.  Anyway in the _SpellCheck function remove or comment out the following as these have already been defined at the beginning of your script and this should utilize both documents, basically the commands below are both just saying get the ActiveDocument in Word as a Range, this meant it was always the last document that was being used.  Hope that made sense.

$oRange = $oWordApp.ActiveDocument.Range
...
$oRange2 = $oWordApp2.ActiveDocument.Range

 

Link to comment
Share on other sites

34 minutes ago, Subz said:

@MattHiggs Actually was able to get it working today, previously the second form would only display briefly then disappear, so had to place a MsgBox just to see the Spell Check form.  Anyway in the _SpellCheck function remove or comment out the following as these have already been defined at the beginning of your script and this should utilize both documents, basically the commands below are both just saying get the ActiveDocument in Word as a Range, this meant it was always the last document that was being used.  Hope that made sense.

$oRange = $oWordApp.ActiveDocument.Range
...
$oRange2 = $oWordApp2.ActiveDocument.Range

 

@Subz Thank you for the good advice.  I was actually able to figure this out as well, but have run into an even more confusing issue that makes no sense to me.  Now it appears the "SpellingSuggestions" (both 1 & 2 in modified script that will post below) is not working, as whenever I click on a misspelled word, it is giving the spelling for a different word.  But here is the strangest thing, in terms of the order in which these spelling errors take place in the actual text, the spelling suggestions are displaying the correct word, and it would the _Spellcheck function is not placing the words in the listbox in the correct order, causing the issue.  The below picture is what is seen when the Input contains the text "the chese is bron" and the edit contains "Sir, the cheese yuo gav me is not freh":

I12kJH6.png

Here is the script that I have as of now:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <ListBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:        William Higgs

 Script Function:
    Provides a graphical user interface for the command line utility "Cmail", which lets one send emails via command line.  I wrote this
    specificially to reduced the ammount of time needed to send messages to potential employers.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <Constants.au3>
#include <Word.au3>
#include <Array.au3>
OnAutoItExitRegister ( "_Exit" )
Global $trans = False
;_WordErrorHandlerRegister()
If Not FileExists ( @MyDocumentsDir & "\settings.ini" ) Then
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Name","What is the name wou want the recipients of your messages to see in regards to the sender? (Should be your name)",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Name", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Email address","What is your email address or the email address of the account sending the mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("SMTP server","What is the address of the SMTP server for your outgoing mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Port","What is the port used by smtp server?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Port", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Username","What is the username used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "User name", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Password","What is the password used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Password", $sInputBoxAnswer )
EndIf
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_SYSTEMMODAL,"Proxy server?","Does your network utilize a proxy server?")
If $iMsgBoxAnswer = $IDYES  Then
    $sInputBoxAnswer = InputBox("Proxy server","What is the proxy server address?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", $sInputBoxAnswer )
EndIf
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", "False" )
EndIf
EndIf

Global $oWordApp = _Word_Create(False)
Global $oDoc = _Word_DocAdd ( $oWordApp )
Global $oRange = $oDoc.Range
Global $oWordApp2 = _Word_Create(False)
Global $oDoc2 = _Word_DocAdd ( $oWordApp2 )
Global $oRange2 = $oDoc2.Range
Global $oSpellCollection, $oAlternateWords, $oSpellCollection2, $oAlternateWords2
HotKeySet ( "^d", "stylish" )
Global $attach = ""
Global $array
;$sphand = _Spell_HunspellInit ( "C:\hunspell-en_US\en_US.aff", "C:\hunspell-en_US\en_US.dic" )
$Form2 = GUICreate("Form2", 406, 514, 320, 200, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$handle = WinGetHandle ( $Form2 )
$MenuItem1 = GUICtrlCreateMenu("configure")
$MenuItem2 = GUICtrlCreateMenuItem("Attachments", $MenuItem1)
$Label1 = GUICtrlCreateLabel("Email Address", 128, 0, 130, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 70, 32, 273, 21)
$Label2 = GUICtrlCreateLabel("Attachments (Can drag and drop below)", 27, 64, 351, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 32, 104, 337, 21)
GUICtrlSetState ( -1, $GUI_DROPACCEPTED )
$Button9 = GUICtrlCreateButton("Add/Browse", 158, 136, 89, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Label4 = GUICtrlCreateLabel("Subject", 160, 184, 157, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("", 32, 216, 337, 21)
$Label3 = GUICtrlCreateLabel("Message", 160, 240, 172, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Edit1 = GUICtrlCreateEdit("", 32, 272, 345, 153, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$Button1 = GUICtrlCreateButton("Send", 30, 440, 113, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("Save As Template", 160, 440, 105, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button6 = GUICtrlCreateButton ( "Use Template", 282, 440, 113, 33, $BS_NOTIFY )
GUICtrlSetCursor (-1, 0)
$Form1 = GUICreate("Spell Check", 396, 360, 694, 220)
Global $handle2 = WinGetHandle ( $Form1 )
$Label7 = GUICtrlCreateLabel("Subject", 162, 8, 70, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Listbox3 = GUICtrlCreateList("", 24, 40, 137, 97)
$Listbox4 = GUICtrlCreateList("", 232, 40, 137, 97)
$Label8 = GUICtrlCreateLabel("Body", 173, 136, 49, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Listbox1 = GUICtrlCreateList("", 24, 168, 137, 97)
$Listbox2 = GUICtrlCreateList("", 232, 168, 137, 97)
$Label9 = GUICtrlCreateLabel("Errors", 64, 272, 53, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("Corrections", 256, 272, 96, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("Send", 32, 313, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button5 = GUICtrlCreateButton("Correct Spelling", 152, 313, 83, 25, $BS_NOTIFY)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 0)
$Button4 = GUICtrlCreateButton("Cancel", 280, 313, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Form3 = GUICreate("Form3", 286, 283, 192, 124)
$Label5 = GUICtrlCreateLabel("Attachments", 86, 8, 113, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$List1 = GUICtrlCreateList("", 16, 40, 249, 188, BitOR($GUI_SS_DEFAULT_LIST,$LBS_HASSTRINGS))
$Button7 = GUICtrlCreateButton("Delete", 40, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button8 = GUICtrlCreateButton("Back", 160, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Form4 = GUICreate("Form4", 242, 95, 216, 123)
$Combo1 = GUICtrlCreateCombo("", 40, 56, 169, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label6 = GUICtrlCreateLabel("Templates", 72, 8, 96, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_DISABLE, $Form4)
GUISetState( @SW_DISABLE, $Form3 )
GUISetState( @SW_DISABLE, $Form1 )
GUISetState( @SW_SHOW, $Form2 )
$aRect = _GUICtrlEdit_GetRECT($Edit1)
$aRect[0] += 10
$aRect[1] += 10
$aRect[2] -= 10
$aRect[3] -= 10
_GUICtrlEdit_SetRECT($Edit1, $aRect)

While 1
    Global $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $Form2
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
                Case $GUI_EVENT_DROPPED
                    Sleep ( 200 )
                    $mult = StringSplit ( GUICtrlRead ( $Input2 ), "|" )
                    If @error Then
                        WinActivate ( $Form2 )
                        WinWaitActive ( $Form2 )
                        GUICtrlSetState ( $Input2, $GUI_FOCUS )
                        Send ( "{ENTER}", 0 )
                    Else
                        For $v = 1 To $mult[0] Step 1
                            $attach = $attach & $mult[$v] & ";"
                        Next
                        GUICtrlSetData ( $Input2, "" )
                            $sToolTipAnswer = ToolTip("The attachments were added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    EndIf

                Case $MenuItem2
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form3 )
                    GUISetState ( @SW_SHOW, $Form3 )
                    If $attach <> "" Then
                        $array = StringSplit ( StringTrimRight ( $attach, 1 ), ";" )
                        If @error Then
                            SetError ( 0 )
                            _GUICtrlListBox_AddString ( $List1, _GetFilename ( StringTrimRight ( $attach, 1 ) ) & "." & _GetFilenameExt ( StringTrimRight ( $attach, 1 ) ) )
                        Else
                            For $l = 1 To $array[0] Step 1
                                _GUICtrlListBox_AddString ( $List1, _GetFilename ( $array[$l] ) & "." & _GetFilenameExt ( $array[$l] ) )
                            Next
                        EndIf
                    Else
                        _GUICtrlListBox_AddString ( $List1, "You currently do not have any attachments." )
                    EndIf
                Case $Input2
                    $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                    GUICtrlSetData ( $Input2, "" )
                    $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                    Sleep ( 3000 )
                    ToolTip ("")

                Case $Button9
                    If GUICtrlRead ( $Input2 ) <> "" Then
                        $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                        GUICtrlSetData ( $Input2, "" )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    Else
                        $file = FileOpenDialog ( "Choose the file you want to attach.", "", "All (*.*)", 7, "", $Form2 )
                        $files = StringSplit ( $file, "|" )
                        If @error Then
                            SetError ( 0 )
                            $attach = $attach & $file & ";"
                            GUICtrlSetData ( $Input2, $file )
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                            GUICtrlSetData ( $Input2, "" )
                        Else
                            For $p = 2 To $files[0] Step 1
                                $attach = $attach & $files[1] & "\" & $files[$p] & ";"
                            Next
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                        EndIf
                    EndIf
                Case $Button1
                    _GUICtrlEdit_SetSel ( $Edit1, 0, -1 )
                    _SpellCheck ()
                Case $Button2;save as template
                    If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
                    $sInputBoxAnswer = InputBox("Template Name","What do you want to name this template?",""," ")
                    If @Error = 1 Then

                    Else
                        $name = $sInputBoxAnswer
                        $num = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                        $num += 1
                        $bodcap = _GUICtrlEdit_GetText ( $Edit1 )
                        $subcap = GUICtrlRead ( $Input3 )
                        $attcap = $attach
                        Local $holdarr[5][2] = [[3, ""], ["Name", $name], ["Body", $bodcap], ["Subject", $subcap], ["Attachments", $attcap]]
                        IniWriteSection ( @MyDocumentsDir & "\settings.ini", "Template " & $num, $holdarr )
                        IniWrite ( @MyDocumentsDir & "\settings.ini", "Number", "Template", $num )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 2000 )
                        ToolTip ( "" )
                    EndIf

                Case $Button6
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form4 )
                    GUISetState ( @SW_SHOW, $Form4 )
                    $numag = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag = 0 Then
                        MsgBox($MB_OK + $MB_ICONHAND,"No templates","You have not configured any templates.")
                    Else
                        For $h = 1 To $numag Step 1
                            GUICtrlSetData ( $Combo1, IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ) )
                        Next
                    EndIf

            EndSwitch
        Case $Form1
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $ListBox1
                    _SpellingSuggestions()
                Case $ListBox2
                    GUICtrlSetState($Button5, $GUI_ENABLE)
                Case $ListBox3
                    _SpellingSuggestions2()
                Case $ListBox4

                Case $Button3
                    SendMessage ()
                Case $Button4
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Button5
                    ;_ReplaceWord()
            EndSwitch
        Case $Form3
            ToolTip ("")
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE, $Button8
                    ToolTip ("")
                    GUISetState ( @SW_HIDE, $Form3 )
                    GUISetState ( @SW_DISABLE, $Form3 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                    If UBound ( $array ) = 1 Then
                            $attach = ""
                        Else
                            $attach = ""
                            For $ff = 1 To UBound ( $array ) - 1 Step 1
                                $attach = $attach & $array[$ff] & ";"
                            Next
                        EndIf
                        _GUICtrlListBox_ResetContent ( $List1 )
                Case $List1
                    ToolTip ("")
                Case $Button7
                    If _GUICtrlListBox_GetSelCount = -1 Then
                        $sToolTipAnswer = ToolTip("Select something to delete first numbnuts.",Default,Default,"Idiot")
                    Else
                        ToolTip ("")
                        $seltext = _GUICtrlListBox_GetText ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                        For $ff = 1 To $array[0] Step 1
                            If StringInStr ( $array[$ff], $seltext ) > 0 Then
                                _ArrayDelete ( $array, $ff )
                                _GUICtrlListBox_DeleteString ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                                ExitLoop
                            EndIf
                        Next
                    EndIf
            EndSwitch
        Case $Form4
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form4 )
                    GUISetState ( @SW_DISABLE, $Form4 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Combo1
                    $sec = ""
                    $numag2 = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag2 = 0 Then

                    Else
                        $use = GUICtrlRead ( $Combo1 )
                        For $h = 1 To $numag2 Step 1
                            If StringCompare ( IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ), $use ) = 0 Then
                                $sec = "Template " & $h
                                ExitLoop
                            Else
                                ContinueLoop
                            EndIf
                        Next
                        GUISetState ( @SW_HIDE, $Form4 )
                        GUISetState ( @SW_DISABLE, $Form4 )
                        GUISwitch ( $Form2 )
                        GUISetState ( @SW_ENABLE, $Form2 )
                        GUISetState ( @SW_SHOW, $Form2 )
                        $attach = IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Attachments", "NA" )
                        GUICtrlSetData ( $Input3, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Subject", "NA" ) )
                        _GUICtrlEdit_SetText ( $Edit1, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Body", "NA" ) )
                    EndIf
            EndSwitch
    EndSwitch
WEnd
Func stylish ()
    $thestyle = GUIGetStyle ( $handle )
    If $trans = False Then
        GUISetStyle ( -1, $thestyle[1] + 32, $handle )
        WinSetTrans ( $handle, "", 170 )
        $trans = True
    Else
        GUISetStyle ( -1, $thestyle[1] - 32, $handle )
        WinSetTrans ( $handle, "", 255 )
        $trans = False
    EndIf
EndFunc
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If IsArray($iRet) Then Return HWnd($iRet[0])
    Return SetError(1, 0, 0)
EndFunc
#cs
Func _Spellcheck ()
    $sText = _GUICtrlEdit_GetText ( $Edit1 )
    $split = StringSplit ( $sText, " " )
    For $i = 1 To $split[0] Step 1
        $boolsp = _Spell_HunspellSpell ( $sphand, $split[$i] )
        If $boolsp = 0 Then
            _GUICtrlListBox_AddString ( $Listbox1, $split[$i] )
        Else
            ContinueLoop
        EndIf
    Next
    GUISetState ( @SW_DISABLE, $Form2 )
            GUISetState ( @SW_HIDE, $Form2 )
            GUISwitch ( $Form1 )
            GUISetState ( @SW_SHOW, $Form1 )
            GUISetState ( @SW_ENABLE, $Form1 )
EndFunc

#ce
Func _SpellCheck()
    Local $sText, $sText2, $sWord, $sWord2

    $pText = _GUICtrlEdit_GetText ( $Edit1 )
    $oRange.Delete
    $oRange.InsertAfter($pText)
    _SetLanguage()
    $pText2 = GUICtrlRead ( $Input3 )
    $oRange2.Delete
    $oRange2.InsertAfter($pText2)
    _SetLanguage2()

    $oSpellCollection = $oRange.SpellingErrors
    $oSpellCollection2 = $oRange2.SpellingErrors
    If $oSpellCollection.Count > 0 Or $oSpellCollection2.Count > 0 Then
        If BitAND ( WinGetState ( $handle ), 2 ) Then
            If $trans = True Then
                stylish ()
            EndIf
            GUISetState ( @SW_DISABLE, $Form2 )
            GUISetState ( @SW_HIDE, $Form2 )
            GUISwitch ( $Form1 )
            GUISetState ( @SW_SHOW, $Form1 )
            GUISetState ( @SW_ENABLE, $Form1 )
        EndIf

        If $oSpellCollection.Count > 0 Then
        _GUICtrlListBox_ResetContent($ListBox1)
        _GUICtrlListBox_ResetContent($ListBox2)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection.Count
                $rWord = $oSpellCollection.Item($i).Text
                _GUICtrlListBox_AddString($ListBox1, $rWord)
            Next
        GUICtrlSetData($Edit1, $oRange.Text)
        EndIf
    If $oSpellCollection2.Count > 0 Then
        _GUICtrlListBox_ResetContent($ListBox3)
        _GUICtrlListBox_ResetContent($ListBox4)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection2.Count
                $rWord2 = $oSpellCollection2.Item($i).Text
                _GUICtrlListBox_AddString($ListBox3, $rWord2)
            Next
        GUICtrlSetData($Input3, $oRange2.Text)
    EndIf
    Else
        SendMessage ()
    EndIf

EndFunc   ;==>_SpellCheck

Func _SpellingSuggestions()
    Local $iWord, $ssWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
        $ssWord = $oSpellCollection.Item($iWord).Text
        $oAlternateWords = $oWordApp.GetSpellingSuggestions($ssWord)



    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _SpellingSuggestions2()
    Local $iWord2, $ssWord2
    ;
    _GUICtrlListBox_ResetContent($ListBox4)
    GUICtrlSetState($Button5, $GUI_DISABLE)

    $iWord2 = _GUICtrlListBox_GetCurSel($ListBox3) + 1
        $ssWord2 = $oSpellCollection2.Item($iWord2).Text
        $oAlternateWords2 = $oWordApp.GetSpellingSuggestions($ssWord2)



    If $oAlternateWords2.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox4, $oAlternateWords2.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox4, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _HighlightWord()
    Local $sText, $iWord, $sWord, $iEnd, $iStart
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $sWord = $oSpellCollection.Item($iWord).Text
    $sText = $oRange.Text

    $iStart = ($oSpellCollection.Item($iWord).Start)
    $iEnd = ($oSpellCollection.Item($iWord).End)
    _GUICtrlEdit_SetSel($Edit1, $iStart, $iEnd)
EndFunc   ;==>_HighlightWord

Func _ReplaceWord()
    Local $iWord, $iNewWord, $sWord, $sNewWord, $sText, $sNewText
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $iNewWord = _GUICtrlListBox_GetCurSel($ListBox2) + 1
    If $iWord == $LB_ERR Or $iNewWord == $LB_ERR Then
        MsgBox(48, "Error", "You must first select a word to replace, then a replacement word.")
        Return
    EndIf
    $oSpellCollection.Item($iWord).Text = $oAlternateWords.Item($iNewWord).Name

    GUICtrlSetData($Edit1, $oRange.Text)

    _SpellCheck()

    GUICtrlSetState($Button5, $GUI_DISABLE)
EndFunc   ;==>_ReplaceWord

Func _SetLanguage()
    $sLang = "English"
        $oWordApp.CheckLanguage = False
        $WdLangID = Number(1033)

        If $WdLangID Then
            With $oRange
                .LanguageID = $WdLangID
                .NoProofing = False
            EndWith

        EndIf
EndFunc   ;==>_SetLanguage
Func _SetLanguage2()
    $sLang = "English"
    $oWordApp2.CheckLanguage = False
    $WdLangID = Number(1033)
    If $WdLangID Then
        With $oRange2
                .LanguageID = $WdLangID
                .NoProofing = False
        EndWith
    EndIf
EndFunc

Func SendMessage ()
    If BitAND ( WinGetState ( $handle2 ), 2 ) Then
        GUISetState ( @SW_HIDE, $Form1 )
        GUISetState ( @SW_DISABLE, $Form1 )
        GUISwitch ( $Form2 )
        GUISetState ( @SW_ENABLE, $Form2 )
        GUISetState ( @SW_SHOW, $Form2 )
    EndIf
    $change = StringStripWS ( GUICtrlRead ( $Input1 ), 3 )
    GUICtrlSetData ( $Input1, $change )
    $body = GUICtrlRead ( $Edit1 )
    _GUICtrlEdit_SetText ( $Edit1, "" )
    ;$attach = StringStripCR ( $attach )
    $subject = GUICtrlRead ( $Input3 )
    If $attach <> "" Then
        $split = StringSplit ( StringTrimRight ( $attach, 1 ), ';' )
        If @error Then
            SetError ( 0 )
            $finattach = '-a:"' & $attach & '" '
        Else
            $finattach = Null
            For $i = 1 To $split[0] Step 1
                $finattach = $finattach & '-a:"' & $split[$i] & '" '
            Next
        EndIf
    EndIf
    $body = StringReplace ( $body, @CRLF, "\n" )
    #cs
    $split = StringSplit ( $body, "", $STR_NOCOUNT )
    For $i = 0 To UBound ( $split ) - 1 Step 1
        If $split[$i] = Chr ( 10 ) Then
            $split[$i] = "\n"
        ElseIf $split[$i] = Chr ( 13 ) Then
            $split[$i] = Null
        Else
            ContinueLoop
        EndIf
    Next
    $body = _ArrayToString ( $split, "" )
    ConsoleWrite ( $body )
    #ce
    If StringRegExp ( GUICtrlRead ( $Input1 ), "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" ) = 1 Then
        If $attach = "" Then
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" -host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
        Else
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
            ClipPut ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d' )
    ProcessWaitClose ( $proc )
    $text = StdoutRead ( $proc )
    ClipPut ( $text )
    MsgBox($MB_OK + $MB_SYSTEMMODAL,"Sent!","Message Sent!!")
        EndIf
    Else
MsgBox(16,"Not a valid email","Enter a correct email address please")
    EndIf
EndFunc

Func _GetFilename($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.FileName
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilename

Func _GetFilenameExt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Extension
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameExt

Func _GetFilenameInt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Name
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameInt

Func _GetFilenameDrive($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return StringUpper($oObjectFile.Drive)
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameDrive

Func _GetFilenamePath($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Path
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenamePath

Func _Exit()
    _Word_Quit ( $oWordApp )
    _Word_Quit ( $oWordApp2 )
    Exit
EndFunc   ;==>_Exit

 

Edited by MattHiggs
Link to comment
Share on other sites

Noticed an error in _SpellingSuggestions2 where you used $oAlternateWords.Count rather than $oAlternateWords2.Count.  Not really sure what the intention of $ssWord = $oSpellCollection.Item($iWord).Text was so just changed it to get the text directly from the listbox which works for me.

Func _SpellingSuggestions()
    Local $iWord, $ssWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

        $ssWord = _GUICtrlListBox_GetText($ListBox1, _GUICtrlListBox_GetCurSel($ListBox1))
        $oAlternateWords = $oWordApp.GetSpellingSuggestions($ssWord)



    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _SpellingSuggestions2()
    Local $iWord2, $ssWord2
    ;
    _GUICtrlListBox_ResetContent($ListBox4)
    GUICtrlSetState($Button5, $GUI_DISABLE)

        $ssWord2 = _GUICtrlListBox_GetText($ListBox3, _GUICtrlListBox_GetCurSel($ListBox3))
        $oAlternateWords2 = $oWordApp.GetSpellingSuggestions($ssWord2)



    If $oAlternateWords2.Count > 0 Then
        For $i = 1 To $oAlternateWords2.Count
            _GUICtrlListBox_AddString($ListBox4, $oAlternateWords2.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox4, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

 

Link to comment
Share on other sites

6 minutes ago, Subz said:

Noticed an error in _SpellingSuggestions2 where you used $oAlternateWords.Count rather than $oAlternateWords2.Count.  Not really sure what the intention of $ssWord = $oSpellCollection.Item($iWord).Text was so just changed it to get the text directly from the listbox which works for me.

Func _SpellingSuggestions()
    Local $iWord, $ssWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

        $ssWord = _GUICtrlListBox_GetText($ListBox1, _GUICtrlListBox_GetCurSel($ListBox1))
        $oAlternateWords = $oWordApp.GetSpellingSuggestions($ssWord)



    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _SpellingSuggestions2()
    Local $iWord2, $ssWord2
    ;
    _GUICtrlListBox_ResetContent($ListBox4)
    GUICtrlSetState($Button5, $GUI_DISABLE)

        $ssWord2 = _GUICtrlListBox_GetText($ListBox3, _GUICtrlListBox_GetCurSel($ListBox3))
        $oAlternateWords2 = $oWordApp.GetSpellingSuggestions($ssWord2)



    If $oAlternateWords2.Count > 0 Then
        For $i = 1 To $oAlternateWords2.Count
            _GUICtrlListBox_AddString($ListBox4, $oAlternateWords2.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox4, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

 

@Subz.  Thank you for your continued help with this.  So the purpose of $ssWord = $oSpellCollection.Item($iWord).Text is (as far as I know, since I have not found any really good documentation for this yet, just going off the logic of the script) to pull the "iWord"th item from the multiple objects stored in $oSpellcollection (which can be easily thought of as a 1-based array) where iWord = the index of the currently selected word in the listbox + 1.  Then the text property for the pulled "Item" is assigned to $ssWord.  It is pretty roundabout, but I would like to get it to work this way if possible, because when it was strictly just one Word document, it worked perfectly.

Link to comment
Share on other sites

16 minutes ago, Subz said:

Noticed an error in _SpellingSuggestions2 where you used $oAlternateWords.Count rather than $oAlternateWords2.Count.  Not really sure what the intention of $ssWord = $oSpellCollection.Item($iWord).Text was so just changed it to get the text directly from the listbox which works for me.

Func _SpellingSuggestions()
    Local $iWord, $ssWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

        $ssWord = _GUICtrlListBox_GetText($ListBox1, _GUICtrlListBox_GetCurSel($ListBox1))
        $oAlternateWords = $oWordApp.GetSpellingSuggestions($ssWord)



    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _SpellingSuggestions2()
    Local $iWord2, $ssWord2
    ;
    _GUICtrlListBox_ResetContent($ListBox4)
    GUICtrlSetState($Button5, $GUI_DISABLE)

        $ssWord2 = _GUICtrlListBox_GetText($ListBox3, _GUICtrlListBox_GetCurSel($ListBox3))
        $oAlternateWords2 = $oWordApp.GetSpellingSuggestions($ssWord2)



    If $oAlternateWords2.Count > 0 Then
        For $i = 1 To $oAlternateWords2.Count
            _GUICtrlListBox_AddString($ListBox4, $oAlternateWords2.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox4, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

 

Oh, and thanks for finding the error, but it doesn't seem to have helped the issue:

U14YMCA.png

Link to comment
Share on other sites

Not sure if you tried my code above, but that way will always work correctly since it's getting the text that you selected from the listbox, otherwise you're using the index returned from the listbox to determine the word in the $oSpellCollection object based upon that index, which means it could always return the wrong text.

Link to comment
Share on other sites

1 minute ago, Subz said:

Not sure if you tried my code above, but that way will always work correctly since it's getting the text that you selected from the listbox, otherwise you're using the index returned from the listbox to determine the word in the $oSpellCollection object based upon that index, which means it could always return the wrong text.

@Subz.  I have not yet for one important reason.  If I grab the word that way, sure the spelling suggestions will appear for the correct word, but i don't know if changing the script to detect the spelling that way will break the other aspects of the process (the highlight and replace portions).  I will try your method if the original method will not work no matter what I try.  Beside, I am someone who seeks to understand these kinds of things.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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