我在家宝的程序中看到这么一段///////////////////////////////////////////////////////////////
//帮助函数定义// Function name : OpenNewWebPage
// Description : 按URL打开新的单独的浏览器窗口
// 由CSDN xtky_limi(亲爱的,别急,我写完这个接口就来陪你!) 编写
// Return type : BOOL
// Argument : LPCTSTR lpstUrl 指定的URL
BOOL OpenNewWebPage(LPCTSTR lpstUrl)
{
/*
BOOL bSuccess = FALSE;
CString sFile = lpstUrl;
SHELLEXECUTEINFO sei;
ZeroMemory(&sei,sizeof(sei));
sei.cbSize = sizeof(sei);
sei.hwnd = AfxGetMainWnd()->GetSafeHwnd();
sei.nShow = SW_SHOW;
sei.lpFile = sFile.GetBuffer(sFile.GetLength());
sei.fMask = SEE_MASK_INVOKEIDLIST;
bSuccess = ::ShellExecuteEx(&sei);
sFile.ReleaseBuffer();
return TRUE;
*/
//得到windows目录
char buf[256];
CString s;
if ( ::GetWindowsDirectory( buf, 255 ) != 0 )
{
s = buf;
if ( s.Right( 1 )!="\\" )
s += "\\";
} //得到资源管理器的可执行文件路径名
CString sExplorerFile( "Explorer.exe" );//直接指定了,很可能兼容性太差
sExplorerFile = s + sExplorerFile; ::ShellExecute( NULL, "open", sExplorerFile, lpstUrl, NULL, SW_MAXIMIZE ); return TRUE;//不管结果
}
//帮助函数定义// Function name : OpenNewWebPage
// Description : 按URL打开新的单独的浏览器窗口
// 由CSDN xtky_limi(亲爱的,别急,我写完这个接口就来陪你!) 编写
// Return type : BOOL
// Argument : LPCTSTR lpstUrl 指定的URL
BOOL OpenNewWebPage(LPCTSTR lpstUrl)
{
/*
BOOL bSuccess = FALSE;
CString sFile = lpstUrl;
SHELLEXECUTEINFO sei;
ZeroMemory(&sei,sizeof(sei));
sei.cbSize = sizeof(sei);
sei.hwnd = AfxGetMainWnd()->GetSafeHwnd();
sei.nShow = SW_SHOW;
sei.lpFile = sFile.GetBuffer(sFile.GetLength());
sei.fMask = SEE_MASK_INVOKEIDLIST;
bSuccess = ::ShellExecuteEx(&sei);
sFile.ReleaseBuffer();
return TRUE;
*/
//得到windows目录
char buf[256];
CString s;
if ( ::GetWindowsDirectory( buf, 255 ) != 0 )
{
s = buf;
if ( s.Right( 1 )!="\\" )
s += "\\";
} //得到资源管理器的可执行文件路径名
CString sExplorerFile( "Explorer.exe" );//直接指定了,很可能兼容性太差
sExplorerFile = s + sExplorerFile; ::ShellExecute( NULL, "open", sExplorerFile, lpstUrl, NULL, SW_MAXIMIZE ); return TRUE;//不管结果
}
extern "C" BOOL PostMessageWithProcessId(DWORD ProcessId, UINT Msg, WPARAM wParam, LPARAM lParam);
再把这加到类定义的
protected: // create from serialization only
STARTUPINFO stinfo; //要启动的窗体大小信息
PROCESS_INFORMATION procinfo; //进程信息启动另一进程把这段函数加载在.cpp文件的定义后
extern "C" BOOL PostMessageWithProcessId(DWORD ProcessId, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HWND H_ProcessWindows[255];
::ZeroMemory( H_ProcessWindows, sizeof(HWND) * 255 ) ;
DWORD dwNrProcessWindows = 0; // Get Upmost Window
HWND H_Top = ::GetTopWindow( NULL );
_ASSERT(H_Top != NULL); HWND H_Window = ::GetWindow (
H_Top, // handle of original window
GW_HWNDFIRST // relationship flag
); // Get all windows associated with the process
DWORD dwProcessId = 0;
while (H_Window != NULL)
{
::GetWindowThreadProcessId ( H_Window, &dwProcessId );
if (dwProcessId == ProcessId)
{
H_ProcessWindows[ dwNrProcessWindows ] = H_Window;
dwNrProcessWindows++;
if ( dwNrProcessWindows >= 255 )
{
_ASSERT(NULL);
break;
}
}
H_Window = ::GetWindow (
H_Window, // handle of original window
GW_HWNDNEXT // relationship flag
);
} // Send to all windows associated with the process
BOOL bMessageSent = FALSE;
for (unsigned int nrWindows = 0; nrWindows < dwNrProcessWindows; nrWindows++)
{
if ( ::IsWindow( H_ProcessWindows[ nrWindows ] ) )
{
BOOL result = ::PostMessage ( H_ProcessWindows[ nrWindows ], Msg, wParam, lParam );
if (result != TRUE)
{
DWORD dwError = GetLastError();
_ASSERT(NULL);
}
else
{
// was sent at least once
bMessageSent = TRUE;
}
}
}
return bMessageSent;
}
把这段代码加到程序中可以启动另一程序,但应把要启动的程序放在当前目录
//****************************************
GetStartupInfo(&stinfo);
stinfo.lpReserved=NULL;
stinfo.lpDesktop=NULL;
stinfo.lpTitle=NULL;
stinfo.dwX=0;
stinfo.dwY=0;
stinfo.dwXSize=200;
stinfo.dwYSize=300;
stinfo.dwXCountChars=500;
stinfo.dwYCountChars=500;
stinfo.dwFlags=STARTF_USESHOWWINDOW;
stinfo.wShowWindow=SW_HIDE;
// ˵ Ã÷ ½ø ³Ì ½« ÒÔ Òþ ²Ø µÄ ·½ ʽ ÔÚ ºó ̨ Ö´ ÐÐ
stinfo.cbReserved2=0;
stinfo.lpReserved2=NULL;
stinfo.hStdInput=stdin;
stinfo.hStdOutput=stdout;
stinfo.hStdError=stderr;
CString exefile = _T(""Explorer.exe" ");
// CString Path = " " + GetFilePath()+GetFileName();
BOOL aaa = FALSE;
aaa = CreateProcess(NULL,LPTSTR(LPCSTR(exefile)),NULL,NULL,FALSE, REALTIME_PRIORITY_CLASS,NULL,NULL, &stinfo,&procinfo);
gInput = 0;
m_SocketInfo.bAbort = FALSE;
m_SocketInfo.bListening = TRUE;
m_SocketInfo.nPort = 1966;
//**********************************
不懂在联系我。
int PAtHLEN=GetWindowsDirectory(WINPATH,MAX_PATH+1 );
strcat(WINPATH,"\\EXPLORER.EXE ");
::WinExec(WINPATH,1);
就可以