Recently I have prepared a CET-4 exam. I got a "four-level high-frequency word" Doc document from the classmate. The document has only words, and there is no phonetic and explanation. If a manual one is very translator, it is very trouble, so I used Delphi and Jinshan Word 2002, specially made a word batch translation, and can save the translation results directly as the RTF file program. The program interface is as follows: Principle Analysis: Use the translation function of "Jinshan Word 2002", the translation of the word, use Delphi to obtain the handle of the result of the result of the "Jinshan Word 2002", using the paste replication function, you can get translation Result. API function description: hWnd findwindow (LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTS LPCTSTR LPWINDOWNAME // Distraver of the title name of the form); / / Find the first sub-window to match the specified condition hWnd FindWindowEx ( HWND HWNDPARENT, / / The handle of the parent window in which the child's parent window hWND HWNDCHILDAFTER, // Start searching for LPCTSTR LPSZCLASS, // To search for the form of the form name lpctstr lpszwindow // want to search the title Name); // Find the first sub-window Bool showWindow (HWND HWnd, // Form of Handle Int Ncmdshow // Form); / / Specify the window in the specified form list; // Specify the window Visibility BOOL BRINGWINDOWTOP (HWND HWND / / Handle); // Take the specified window to the top Bool setForegroundWindow (HWND HWND / / Form handle) of the window list; / / Set the window to the system front program HWND SetFocus (HWND hWnd // handle to form a focused); // window focus VOID keybd_event (BYTE bVk, // virtual-key code BYTE bScan, // hardware scan code DWORD dwFlags, // flags specifying various function options DWORD DWEXTRAINFO // Additional Data Associated with keyStroke); // Analog buttons are generated here that provide basic API declarations, specific usage, you can other relevant information. Specific analysis: First use Spy tools, analyze "Jinshan Word 2002", the analysis results are as follows: The name of the form of Kingsoft 2002 is: Jinshan Words 2002 Jinshan Word Inba 2002 Word Input Control Class Name: Edit (subordinate subbobox) Forms) The translation results of Jinshan Word 2002: XDict_ExplainView Program Interface: A Timer Control (Timer1, It is 3 seconds of 3 seconds), an MEMO control (MLIST), two Richedit controls (RTRANS, RCONV), specific code show as below:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Clipbrd, Buttons, ExtCtrls, Menus; type TForm1 = class (TForm) MList: TMemo; RTrans: TRichEdit; button1: TButton; Timer1: TTimer; Button2: TButton; RConv: TRichEdit; Button3: TButton; od: TOpenDialog; RichEdit3: TRichEdit; MainMenu1: TMainMenu; F1: TMenuItem; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; C1: TMenuItem; N4: TMenuItem; N5: TMenuItem; RTF1: TMenuItem; Panel1: TPanel; ProgressBar1: TProgressBar; Splitter1: TSplitter; Splitter2: TSplitter; E1: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; Edit1: TEdit; label1: TLabel; Label2: TLabel; Label3: TLabel; procedure Button1Click (Sender: TObject); procedure Timer1Timer (Sender: TObject); procedure Button2Click (Sender: TObject); procedure Button3Click (Sender: TObject); procedure N3Click (Sender : TObject); procedure N6Click (Sender: TObject); procedure N8Click (Sender: TObject); private {Private declarations} public {Public declarations} end; var Form1: TForm1; i: integer = 0; // declare a global variable, Reverse IMPLEMENTATION {$ r * .dfm} // Start conversion event procedure tform1.button1click (sender: TOBJECT); begin rtrans.clear; // Clear conversion zone RCONV.CLEAR; Timer1.Iterval: = start ( Edit1.text) * 1000; // Set interval Timer1.Enabled: = true; // progressbar1.position: = 0; // Setting progress strip status i: = 0; // Initialization variable, used to count Progressbar1. Max: = mlist.lines.count; end; procedure tform1.timer1timer (sender: Tobject); var king, // 金山 词霸 2002 main window handle Combo, // Word input box parent window handle Edit, // Word input box handle Means: thandle; // Translation display window handle Begin if i <=
Mlist.Lines.count-1 Then Begin King: = FindWindow (Nil, Pchar ('Jinshan Word 2002')); Combo: = FindWindowEx (King, 0, 'ComboBox', NIL); Edit: = FINDWINDOWEX (Combo, 0 , 'Edit', nil); means: = findwindowex (king, 0, 'xdict_explainview ", nil); // information display label3.caption: =' (' INTTOSTR (i 1) ' / ' INTTOSTR Mlist.lines.count) ')' mlist.Lines [i]; // Storage Information Clipboard.astext: = mList.Lines [i]; showwindow (king, sw_shownormal); bringwindowtotop (king); setForegroundWindow (KING) Windows.Setfocus (Edit); // Simulation Ctrl V Paste KeyBD_Event (VK_Control, MapVirtualKey (vk_control, 0), 0, 0); KeyBD_Event (ORD ('V'), MapVirtualKey (ORD ('V'), 0 ), 0, 0); keybd_event (Ord ( 'V'), MapVirtualKey (Ord ( 'V'), 0), KEYEVENTF_KEYUP, 0); keybd_event (VK_CONTROL, MapVirtualKey (VK_CONTROL, 0), KEYEVENTF_KEYUP, 0); SetForegroundWindow (Means); Windows.Setfocus (Means); // Simulation Ctrl A Alllect KeyBD_Event (VK_Control, MapVirtualKey (VK_Control, 0), 0, 0); KeyBD_Event (ORD ('A'), MapVirtualKey (ORD ('A '), 0), 0, 0); KeyBD_Even t (Ord ( 'A'), MapVirtualKey (Ord ( 'A'), 0), KEYEVENTF_KEYUP, 0); keybd_event (VK_CONTROL, MapVirtualKey (VK_CONTROL, 0), KEYEVENTF_KEYUP, 0); SetForegroundWindow (means); windows.SetFocus (// simulation Ctrl C copy keybd_event (vk_control, mappvirtualkey (vk_control, 0), 0, 0); keybd_event (ORD ('c'), MapVirtualKey (ORD ('c'), 0), 0, 0); keybd_event (Ord ( 'C'), MapVirtualKey (Ord ( 'C'), 0), KEYEVENTF_KEYUP, 0); keybd_event (VK_CONTROL, MapVirtualKey (VK_CONTROL, 0), KEYEVENTF_KEYUP, 0); windows.SetFocus (RTrans .Handle);
// Simulation Ctrl V Paste KeyBD_EVENT (VK_Control, MapVirtualKey (vk_control, 0), 0, 0); KeyBD_Event (ORD ('V'), MapVirtualKey (ORD ('V'), 0), 0, 0); keybd_event (ORD ('V'), MapVirtualKey (ORD ('V'), 0), KEYEVENTF_KEYUP, 0); KeyBD_Event (VK_Control, MapVirtualKey (vk_control, 0), KeyEventf_Keyup, 0); RTRANS.LINES.ADD ('== ============================================================================================ Rtrans.lines.savetofile ('temp.txt'); end; end; // Read word list to mList Procedure TFORM1.BUTTON2CLICK (Sender: Tobject); begin if Od.execute1 mlist.lines.LoadFromFile (OD) .Filename); END; / / conversion function, because of the translation in RTRANS, the phonetic symbol does not display // must first install the Phonetic Plain font in the font directory in the golden mountain word // Implement the correct display Procedure TFORM1.BUTTON3CLICK (Sender: TOBJECT); VAR I: Integer; start, ends: integer; begin rconv.clear; for i: = 0 to rTrans.Lines.count-1 do begin richedit3.text: = rtrans.lines [i ]; Start: = POS ('[', richedit3.text); // Find a phonetic location, phonetic in [] IF start> 0 THEN BEGIN Ends: = POS ('], richedit3.text); richedit3.SelStart: = start; richedit3.SelLength: = ends-start-1; richedit3.SelAttributes.Name: = 'Kingsoft Phonetic Plain'; end; richedit3.SelectAll; richedit3.CopyToClipboard; RConv.PasteFromClipboard; application.ProcessMessages; end ; end; // program exits procedure TForm1.N3Click (Sender: TObject); begin application.Terminate; end; // replication procedure TForm1.N6Click (Sender: TObject); begin RConv.SelectAll; RConv.CopyToClipboard; end; / / Stop conversion Procedure TFORM1.N8Click (Sender: TOBJECT); begin Timer1.enabled: = false;