用Delphi如何控制另一个软件(比如运行记事本,并能敲两个回车) (50分)

P

pyk1

Unregistered / Unconfirmed
GUEST, unregistred user!
用Delphi如何控制另一个软件(比如运行记事本,并能敲两个回车)。

谢谢!
 
运行另一程序用winexec函数
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1067379
 
应该很简单吧。
先WinExec或者ShellExecute打开记事本,比如:
WinExec("notepad.exe");
然后KeyEvent(i); // 其中i是你要输入字符的ASCII,回车键的ASCII自己查,我忘了。
 
使用postmessage()
 
在DEPHI中运行EXPLORE.EXE,其中有一个参数可以指明您要运行的程序。
 
postmessage(记事本窗口的句柄,wm_keydown,键盘值)
大致这样的
 
最好用createprocess()
 
WinExec、ShellExecute都可以在程序中打开其它的应用程序。
至于要敲回车,可以通过WINDOWS消息进行处理。
 
听说可以用系统钩子,'指南'书中有'sendkey'例程,很长的,可看看。
 
ShellExecute是api函数,我不做说明了,请查看帮助,下面是简单的说明
HINSTANCE ShellExecute(

HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);
作用:查找与指定文件关联在一起的程序的文件名
HINSTANCE,非零表示成功,零表示失败。会设置GetLastErrorhwnd -----------
HWND hwnd,指定一个窗口的句柄,有时候,windows程序有必要在创建自己的主窗口前显示一个消息框

lpOperation ---- String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它

lpFile --------- String,想用关联程序打印或打开一个程序名或文件名

lpParameters --- String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数

lpDirectory ---- String,想使用的完整路径

nShowCmd ------- Long,定义了如何显示启动程序的常数值。参考ShowWindow函数的nCmdShow参数

调用word程序打开默认的文档
ShellExecute(frmMain.Handle,nil,PChar('WINWORD.EXE'),nil,nil,SW_SHOWNORMAL);
 
同意stuwei
 
用shellexecute吧,我用过,很好用的
 
顶部