
..::Свирепый Кодер::..
 
Профиль
Группа: Участник
Сообщений: 901
Регистрация: 17.10.2004
Где: ICQ
Репутация: 6 Всего: 11
|
Код | unit MainUnit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Dialogs, StdCtrls, Buttons, WordXP, OleServer, ComCtrls, Registry, XPMan;
var WordDoc: TWordDocument; WordApp: TWordApplication; colSpellErrors : ProofreadingErrors; colSuggestions : SpellingSuggestions;
procedure Conn; procedure Check; procedure Disconn; function IsWordInstalled: Boolean; implementation
uses CheckUnit, CallExec, Forms;
function IsWordInstalled: Boolean; var Reg: TRegistry; s: string; begin Reg := TRegistry.Create; try Reg.RootKey := HKEY_CLASSES_ROOT; Result := Reg.KeyExists('Word.Application'); finally Reg.Free; end; end;
procedure Conn; begin WordDoc:=TWordDocument.Create(nil); WordApp:=TWordApplication.Create(nil); WordDoc.ConnectKind:=ckRunningOrNew; WordApp.ConnectKind:=ckRunningOrNew;
WordApp.Connect; WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam, EmptyParam,EmptyParam));
CheckFrm:=TCheckFrm.Create(nil); end;
procedure Disconn; var varFalse : OleVariant; begin WordDoc.Disconnect; varFalse:=False; WordApp.Quit(varFalse); CHeckFrm.Free; end;
procedure Check; var hwnd: THandle; textlength: Integer; Text: PChar; i : Integer; begin Hwnd:=FindWindow('TchatFrm',nil); Hwnd:=FindWindowEx(hwnd,0,'TPageControl',nil); Hwnd:=FindWindowEx(hwnd,0,'TTabSheet',nil); Hwnd:=FindWindowEx(hwnd,0,'TMemo',nil);
if hwnd=0 then begin ShowMessage('Îêíî ÷àòà íå íàéäåíî'); exit; end;
textlength := SendMessage(HWnd, WM_GETTEXTLENGTH, 0, 0); GetMem(Text, textlength + 1); SendMessage(HWnd, WM_GETTEXT, textlength + 1, Integer(Text));
WordDoc.Range.Delete(EmptyParam,EmptyParam); WordDoc.Range.Set_Text(Text); colSpellErrors := WordDoc.SpellingErrors; if colSpellErrors.Count <> 0 then begin colSuggestions := WordApp.GetSpellingSuggestions (colSpellErrors.Item(1).Get_Text); with CheckFrm do begin RichEdit1.Text:=Text; ListBox1.Items.Clear; for i:= 1 to colSuggestions.Count do ListBox1.Items.Add(VarToStr(colSuggestions.Item(i))); ListBox1.ItemIndex := 0; ShowModal; case ModalResult of mrOK: SendMessage(HWnd, WM_SETTEXT, 0, Integer(PChar(RichEdit1.Text))); end; end; end else ShowMessage('Ïðîâåðêà ïðàâîïèñàíèÿ çàâåðøåíà'); FreeMem(Text); end;
end.
|
Код | unit CheckUnit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ComCtrls, XPMan, ExtCtrls, Menus;
type TCheckFrm = class(TForm) ListBox1: TListBox; RichEdit1: TRichEdit; Button1: TButton; Button2: TButton; XPManifest1: TXPManifest; Button4: TButton; Button3: TButton; BitBtn1: TBitBtn; PopupMenu1: TPopupMenu; About1: TMenuItem; procedure Button4Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure About1Click(Sender: TObject); private procedure NextErr; { Private declarations } public
end;
var CheckFrm: TCheckFrm; ii: integer;
implementation
uses MainUnit, CallExec, AboutUnit;
{$R *.dfm}
procedure TCheckFrm.NextErr; var i: integer; begin if colSpellErrors.Count=ii-1 then begin ListBox1.Items.Clear; RichEdit1.SelStart:=0; Button4.Enabled:=False; Button3.Enabled:=false; Button1.Enabled:=False; Button2.Enabled:=false; exit; end;
colSuggestions := WordApp.GetSpellingSuggestions (colSpellErrors.Item(ii).Get_Text); ListBox1.Items.Clear; for i:= 1 to colSuggestions.Count do ListBox1.Items.Add(VarToStr(colSuggestions.Item(i))); ListBox1.ItemIndex := 0; RichEdit1.SelStart:=Pos(colSpellErrors.Item(ii).Get_Text,RichEdit1.Text)-1; RichEdit1.SelLength:=Length(colSpellErrors.Item(ii).Get_Text); RichEdit1.SelAttributes.Color:=clRed; RichEdit1.SelAttributes.Style:=[fsBold]; end;
procedure TCheckFrm.Button4Click(Sender: TObject); begin RichEdit1.SelText:=ListBox1.Items[ListBox1.ItemIndex]; RichEdit1.SelStart:=Pos(ListBox1.Items[ListBox1.ItemIndex],RichEdit1.Text)-1; RichEdit1.SelLength:=Length(ListBox1.Items[ListBox1.ItemIndex]); RichEdit1.SelAttributes.Color:=clBlack; RichEdit1.SelAttributes.Style:=RichEdit1.Font.Style- [fsBold]; inc(ii); NextErr; end;
procedure TCheckFrm.FormShow(Sender: TObject); begin Button4.Enabled:=true; Button3.Enabled:=true; Button1.Enabled:=true; Button2.Enabled:=true; RichEdit1.SelStart:=Pos(colSpellErrors.Item(ii).Get_Text,RichEdit1.Text)-1; RichEdit1.SelLength:=Length(colSpellErrors.Item(ii).Get_Text); RichEdit1.SelAttributes.Color:=clRed; RichEdit1.SelAttributes.Style:=[fsBold]; end;
procedure TCheckFrm.FormCreate(Sender: TObject); begin ii:=1; end;
procedure TCheckFrm.Button1Click(Sender: TObject); begin RichEdit1.SelAttributes.Color:=clBlack; RichEdit1.SelAttributes.Style:=RichEdit1.Font.Style- [fsBold]; inc(ii); NextErr; end;
procedure TCheckFrm.Button2Click(Sender: TObject); begin RichEdit1.SelAttributes.Color:=clBlack; RichEdit1.SelAttributes.Style:=RichEdit1.Font.Style- [fsBold]; ii:=colSpellErrors.Count+1; NextErr; end;
procedure TCheckFrm.Button3Click(Sender: TObject); var i:integer; begin for i:=ii to colSpellErrors.Count do begin Button4Click(Sender); end; end;
procedure TCheckFrm.FormClose(Sender: TObject; var Action: TCloseAction); begin ii:=1; RichEdit1.SelStart:=0; RichEdit1.SelLength:=0; end;
end.
| Добавлено @ 17:42 на вот когда-то писал с кодом думаю сам разбирёшся если чё не понятно спрашивай =)
|