大家说那么多,不如做一个<br>//ydsoftyyd,你的想法是对的,<br>//花了一下午才搞定,这个周末属于你的,咳,新来的,没开张呢,能来点分也好<br>//调试工具为Delphi的Winsignt,在win98,word97,D6下调试通过<br>implementation<br>{$R *.dfm}<br>const<br> sTitle1 = 'Microsoft Word';<br> sTitle2 = '另存为';<br><br>var<br> hDlg, hEdit, hBtn: THandle;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> FindSaveTipDlg;<br> Sleep(3000);//等会儿,后面"另存为"对话框还没出来呢<br> FindSaveFileAsDlg;<br>end;<br><br>procedure TForm1.FindSaveTipDlg;<br>begin<br> hDlg := FindWindow(PChar(WC_DIALOG), sTitle1);//找到'Microsoft Word'对话框的窗口,获得它的句柄<br> if hDlg = 0 then Exit;<br><br> hBtn := FindWindowEx(hDlg, 0, PChar('Button'), nil);//找到<是>按扭<br> SendNotifyMessage(hBtn, WM_LBUTTONDOWN, MK_LBUTTON, 0);//给<是>按扭发送一个按下鼠标左键的消息<br> SendNotifyMessage(hBtn, WM_LBUTTONDOWN, MK_LBUTTON, 0);//只发一次发现有时可以,有时不可以,再发一次,ok<br> SendNotifyMessage(hBtn, WM_LBUTTONUP, 0, 0);//再给<是>按扭发送一个弹起鼠标左键的消息<br>end;<br><br>procedure TForm1.FindSaveFileAsDlg;<br>var<br> sFileName: string;<br> i: Integer;<br>begin<br> hDlg := FindWindow(PChar('bosa_sdm_Microsoft Word 8.0'), sTitle2);//找到要"另存为"对话框的窗口,获得它的句柄<br> if hDlg = 0 then Exit;<br> hEdit := FindWindowEx(hDlg, 0, PChar('RichEdit20W'), nil);//先找到"保存位置"下拉框<br> if hEdit = 0 then Exit;<br> hEdit := FindWindowEx(hDlg, hEdit, PChar('RichEdit20W'), nil);//再找到"文件名"下拉框,<br> if hEdit = 0 then Exit;<br><br>// SendMessage(hEdit, WM_SETTEXT, 0, LPARAM(PChar(sFileName)));//模拟键盘输入文件名<br> //本来想用SendMessage(hEdit, WM_SETTEXT, 0, LPARAM(PChar(sFileName)));<br> //但输入的老是乱码,只好一个一个来,呵呵,将就用吧,大家也可讨论<br> sFileName := FormatDateTime('yyyymmddhhnnss', Now);//用时间做文件名<br> for i := 1 to Length(sFileName) do<br> begin<br> SendMessage(hEdit, WM_KeyDown, Ord(sFileName), MapVirtualKey(Ord(sFileName), 0));<br> SendMessage(hEdit, WM_Char, Ord(sFileName), MapVirtualKey(Ord(sFileName), 0));<br> SendMessage(hEdit, WM_KeyUp, Ord(sFileName), MapVirtualKey(Ord(sFileName), 0));<br> end;<br><br> SendMessage(hDlg, WM_KeyDown, $0D, 0);<br> SendMessage(hDlg, WM_KeyUp, $0D, 0);<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> Timer1.Enabled := False;<br> try<br> FindSaveTipDlg;<br> FindSaveFileAsDlg;<br> finally<br> Timer1.Enabled := True;<br> end;<br>end;<br><br>end.