15,979
社区成员
发帖
与我相关
我的任务
分享
// by creating process ***********************************
BOOL GoNotePad(char *path,BOOL bWait=TRUE)
{
char pathexe[MAX_PATH];
strcpy(pathexe,"notepad.exe ");
strcat(pathexe,path);//pathname="notepad.exe ",
STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
memset (&sinfo,0,sizeof(STARTUPINFO));
sinfo.cb=sizeof(STARTUPINFO);
sinfo.dwFlags|=STARTF_USESHOWWINDOW;
sinfo.wShowWindow=SW_SHOWNORMAL;//SW_SHOW;// SW_SHOWDEFAULT;
//BOOL fsuccess=0;
BOOL fsuccess=CreateProcess(NULL,//lpApplicationName
pathexe, //lpCommanderLine
NULL, //lpProcessAttributes
NULL, //lpThreadAttributes
FALSE, //bInheritHandles
NORMAL_PRIORITY_CLASS,//dwCreationFlags
NULL, //lpEnvironment
NULL, //lpCurrentDirectory
&sinfo, //lpStartupInfo
&pinfo); //lpProcessInformation
// wait for NotePad finishes
if(fsuccess)
{
HANDLE hProcess=pinfo.hProcess;
CloseHandle(pinfo.hThread);// close thread at once
if (bWait)
{
if (WaitForSingleObject(hProcess,INFINITE)!=WAIT_FAILED)
{
DWORD dwExitCode;
GetExitCodeProcess(hProcess,&dwExitCode);
if (dwExitCode==STILL_ACTIVE) AfxMessageBox(IDS_NOTEPAD_ALIVE);
}
}
WaitForInputIdle(pinfo.hProcess,INFINITE);// let NotePad show window
CloseHandle(pinfo.hProcess);
}
return(fsuccess);
}
//
void CMdiInDlgDlg::OnAdd()
{
// TODO: Add your control notification handler code here
if(GoNotePad("",FALSE))
{//
m_hwnd=::FindWindow("NotePad","无标题 - 记事本");
if(m_hwnd)
{
LONG style=GetWindowLong(m_hwnd,GWL_STYLE);// 14CF 0000
// 1=WS_VISIBLE 4=WS_CLIPSIBLINGS C=WS_CAPTION;WS_THICKFRAME=4+WS_SYSMENU=8+WS_GROUP=2+WS_TABSTOP=1==F
style &=~WS_CAPTION;
style &=~WS_THICKFRAME;
style &=~WS_MINIMIZEBOX;
style &=~WS_MAXIMIZEBOX;
style &=~WS_SYSMENU;
style &=~WS_GROUP;
style &=~WS_TABSTOP;
// style |=WS_CHILD;// if used then no menu !!!
SetWindowLong(m_hwnd,GWL_STYLE,style);
CRect rc;
GetClientRect(rc);
rc.bottom-=50;// 底部 留 50 ,显示 文件信息 !
// afxDump << rc << "OK\n";
::SetParent(m_hwnd,this->m_hWnd);
::SetWindowPos(m_hwnd,HWND_TOP, rc.left, rc.top, rc.Width(), rc.Height(),SWP_FRAMECHANGED);
::SetFocus(m_hwnd);
SetCursorPos(10,10);// menu 'View'
}
}
}