1. 程式人生 > >C++建立程序

C++建立程序

#include <iostream>
#include <windows.h>
using namespace std;

int main(int argc, char* argv[])
{
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;

	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = TRUE;
	TCHAR cmdline[] =TEXT(" http://www.baidu.com/"); // 注意前面有空格,否則開啟的是主頁。
	BOOL bRet = ::CreateProcess (
		TEXT("c://program files//internet explorer//iexplore.exe"),
		cmdline,
		NULL,
		NULL,
		FALSE,
		CREATE_NEW_CONSOLE,
		NULL,
		NULL,
		&si,
		&pi);
	int nError = GetLastError();
	if(bRet)
	{
		cout<<"程序的程序ID號:"<<pi.dwProcessId<<endl;
		cout<<"程序的主執行緒ID號:"<<pi.dwThreadId<<endl;
		::CloseHandle (pi.hThread);
		::CloseHandle (pi.hProcess);
 }else{cout<<"建立程序失敗:"<nError<<endl;
}return 0;}