用CreateProcess()调用第二个程序,然后再 ShowWIndow(HWND,SW_HIDE);
BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);
BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);
h_Wnd,
"open",
lpFile, <==你要运行的程序
nil,
nil,
SW_HIDE
);
另外上面说的不错:
在一程序中调用另一程序的函数有3种:
1,ShellExecute(
h_Wnd,
"open",
lpFile, <==你要运行的程序
nil,
nil,
SW_HIDE
);
2,ShellExecuteEx();
3,BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);
具体可以查MSDN
--------
如果HWND 不是当前PROCESS的,不能用的.通过调节CREATEPROCESS
的参数可以做到隐藏主窗口.STARTUPINFO startup;
memset(&startup,0x00,sizeof(startup));
startup.cbsize =sizeof(startup);
startup.dwFlags=STARTF_USESHOWWINDOW;
startup.wShowWindow =sw_hide;BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
&startup, // **************
LPPROCESS_INFORMATION lpProcessInformation // process information
);----------------
谢谢joy8223(复杂) , kugle(kugle)提供了路子,我想再调用第二个程序窗体上xxx按钮的按下的函数,并且要传一些值到第二个程序的某些变量去(我已经把它们申明为全局),好办吗?----最好把两个程序所公共的函数,变量写在一个DLL里.这种做法简直是胡说八道. 在95以后全局VAR
也是PROCESS 级别的.可以使用共享内寸. createfilemapping, openfilemapping. 如果喜欢消息机制, 如果小于4BYTES的数据交换可以使用postthreadmessage
数据多更多的时候,可以使用WM_COPYDATA(少数的几个可以在APP间通讯的MESSAGE)
也可以使用把一部分变量声明到共享区的形式.(通过编译OPTION)
#pragma data_sega("sharedata")
type data=; //what you want to share in os level,must init it.
#pragma data_sega()in link option, add -SECTION:sharedata,RWS
想发送一条消息到某个窗体里的按钮,可以这样:
先用VC资源方式打开那个程序,找到那个按钮的ID
然后
...
handle=::FindWindow(NULL,"程序窗口标题");
PostMessage(handle,WM_COMMAND,ID,0);
...
你可以把数据存在文件里,然后再读出来