DW1 Posted October 23, 2007 Share Posted October 23, 2007 (edited) expandcollapse popup#NoTrayIcon #include<Word.au3> #include<ANYGUI.au3> #include<array.au3> #Include <GuiEdit.au3> #include <GuiList.au3> #Include <GuiCombo.au3> #include <GuiConstants.au3> ;~ HotKeySet("!t", "_test") $ver = RegRead("HKEY_CLASSES_ROOT\Word.Application", "") If $ver <> "Microsoft Word Application" Then MsgBox(0, "Error", "You must have word installed to use spell check in notepad") Exit EndIf _WordErrorHandlerRegister() Global $oWordApp = _WordCreate("", 0, 0, 0) Global $oDoc = $oWordApp.ActiveDocument Global $oRange = $oDoc.Range Global $oSpellCollection, $oAlternateWords Global $aLangs[2][2] = [[1, ""], ["English", 1033]] ;~ Opt ("GUIOnEventMode", 1) Run("notepad.exe") WinWaitActive("") $hWnd = _GuiTarget ("Untitled - Notepad") _ArrayDisplay($hWnd) $child = _TargetaddChild ("", 0, 0, 50000, 20, $hWnd) $Button1 = GUICtrlCreateButton("Spell Check!", 0, 0, 100, 20) $Button2 = GUICtrlCreateButton("Replace Word", 400, 0, 100, 20) $ListBox1 = GUICtrlCreateList("", 100, 0, 150, 20, $LBS_NOTIFY + $WS_VSCROLL) $ListBox2 = GUICtrlCreateList("", 250, 0, 150, 20, $LBS_NOTIFY + $WS_VSCROLL) $edit = ControlGetHandle($hWnd, "", 15) ;~ MsgBox(0, "test", $edit ) ;~ GUICtrlSetOnEvent($button2, "_SpellCheck") $Combo = GUICtrlCreateCombo("", 500, 0, 80, 20) For $i = 1 To $aLangs[0][0] _GUICtrlComboAddString($Combo, $aLangs[$i][0]) Next GUICtrlSetState($Button2, $GUI_DISABLE) GUISetState(@SW_SHOW) _EndTarget () While WinExists($hWnd) $msg = GUIGetMsg() Switch $msg ;~ Case $GUI_EVENT_CLOSE, $Button3 ;~ _Exit() Case $Button1 If ControlGetText($hWnd, "", 15) <> "" Then _SpellCheck() Else MsgBox(0, "Error", "No text to check") EndIf Case $Button2 _ReplaceWord() Case $ListBox1 _SpellingSuggestions() _HighlightWord() Case $ListBox2 GUICtrlSetState($Button2, $GUI_ENABLE) Case $Combo _SetLanguage() _SpellCheck() EndSwitch $size = WinGetClientSize($hWnd) If WinExists($hWnd) Then ControlMove($hWnd, "", 15, 0, 20, $size[0], $size[1] - 20) ControlMove($hWnd, "", "button2", $size[0], 25, 20, 20) EndIf Sleep(10) WEnd ;~ While WinExists($hWnd) ;~ $size = WinGetClientSize($hWnd) ;~ If WinExists($hWnd) Then ;~ ControlMove($hWnd, "", 15, 0, 20, $size[0], $size[1] - 20) ;~ ControlMove($hWnd, "", "button2", $size[0], 25, 20, 20) ;~ EndIf ;~ Sleep(10) ;~ WEnd _WordQuit($oWordApp, 0) Func Eventer() MsgBox(0, "test", "hit") EndFunc ;==>Eventer Func _test() MsgBox(0, "ControlGetText", ControlGetText($hWnd, "", 15)) MsgBox(0, "GUICtrlRead", GUICtrlRead($edit)) EndFunc ;==>_test ; -----------------MS WORD FUNCS-----------------; ;----These funcs were written by big_daddy for his Custom Spell Checker----; Func _SpellCheck() Local $sText, $sWord ; this will allow you to have the last word corrected ControlSetText($hWnd, "", 15, ControlGetText($hWnd, "", 15) & " ") ; TRY TO FIND A WAY AROUND THIS _GUICtrlListClear($ListBox1) _GUICtrlListClear($ListBox2) GUICtrlSetState($Button2, $GUI_DISABLE) ;~ $sText = GUICtrlRead($edit) $sText = ControlGetText($hWnd, "", 15) $oRange = $oWordApp.Activedocument.Range $oRange.Delete $oRange.InsertAfter ($sText) _SetLanguage() $oSpellCollection = $oRange.SpellingErrors If $oSpellCollection.Count > 0 Then For $i = 1 To $oSpellCollection.Count $sWord = $oSpellCollection.Item ($i).Text _GUICtrlListAddItem($ListBox1, $sWord) Next Else _GUICtrlListAddItem($ListBox1, "No spelling errors found.") EndIf ControlSetText($hWnd, "", 15, $oRange.Text) ;~ GUICtrlSetData($edit, $oRange.Text) EndFunc ;==>_SpellCheck Func _SpellingSuggestions() Local $iWord, $sWord ; _GUICtrlListClear($ListBox2) GUICtrlSetState($Button2, $GUI_DISABLE) $iWord = _GUICtrlListSelectedIndex($ListBox1) + 1 $sWord = $oSpellCollection.Item ($iWord).Text $oAlternateWords = $oWordApp.GetSpellingSuggestions ($sWord) If $oAlternateWords.Count > 0 Then For $i = 1 To $oAlternateWords.Count _GUICtrlListAddItem($ListBox2, $oAlternateWords.Item ($i).Name) Next Else _GUICtrlListAddItem($ListBox2, "No suggestions.") EndIf EndFunc ;==>_SpellingSuggestions Func _HighlightWord() Local $sText, $iWord, $sWord, $iEnd, $iStart ; $iWord = _GUICtrlListSelectedIndex($ListBox1) + 1 $sWord = $oSpellCollection.Item ($iWord).Text $sText = $oRange.Text $iStart = ($oSpellCollection.Item ($iWord).Start) $iEnd = ($oSpellCollection.Item ($iWord).End) _GUICtrlEditSetSel($edit, $iStart, $iEnd) EndFunc ;==>_HighlightWord Func _ReplaceWord() Local $iWord, $iNewWord, $sWord, $sNewWord, $sText, $sNewText ; $iWord = _GUICtrlListSelectedIndex($ListBox1) + 1 $iNewWord = _GUICtrlListSelectedIndex($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($edit, $oRange.Text) ControlSetText($hWnd, "", 15, $oRange.Text) _SpellCheck() ; TRYING THIS OUT $string = ControlGetText( $hWnd, "", 15 ) While 1 If StringRight($string, 1) = " " Then $string = StringTrimRight($string, 1) Else ExitLoop EndIf WEnd ControlSetText( $hWnd, "", 15, $string) ;TESTTESTTEST GUICtrlSetState($Button2, $GUI_DISABLE) EndFunc ;==>_ReplaceWord Func _SetLanguage() $sLang = GUICtrlRead($Combo) If $sLang <> "" Then $oWordApp.CheckLanguage = False For $i = 1 To $aLangs[0][0] If $sLang = $aLangs[$i][0] Then $WdLangID = Number($aLangs[$i][1]) EndIf Next If $WdLangID Then With $oRange .LanguageID = $WdLangID .NoProofing = False EndWith EndIf Else $oWordApp.CheckLanguage = True EndIf EndFunc ;==>_SetLanguage Func _Exit() _WordQuit($oWordApp, 0) Exit EndFunc ;==>_Exit Edited November 20, 2007 by danwilli AutoIt3 Online Help Link to comment Share on other sites More sharing options...
gseller Posted October 23, 2007 Share Posted October 23, 2007 Nice use of anygui and notepad.. Link to comment Share on other sites More sharing options...
ptrex Posted October 24, 2007 Share Posted October 24, 2007 @danwilli Great stuff. AnyGui still is one of my favourites !! regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
JohnBailey Posted October 24, 2007 Share Posted October 24, 2007 very nice example A decision is a powerful thing Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted October 30, 2007 Moderators Share Posted October 30, 2007 ; -----------------MS WORD FUNCS-----------------; ;----I don't know for sure the author of these (not me), but I think it is big_daddy----;Those functions came from my Custom Spell Checker. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now