HANDLE hProcess;
HWND apphWnd=NULL;
int the CALLBACK EnumWindowsProc (HWND HWND, LPARAM LPARAM)
{
DWORD pID;
DWORD tpID=GetWindowThreadProcessId (HWND, & amp; PID);
If (tpID==(DWORD) lParam)
{
ApphWnd=HWND;
return false;
}
return true;
}
HANDLE StartProcess (LPCTSTR program, LPCTSTR args)
{
HANDLE hPro=NULL;
PROCESS_INFORMATION processInfo;
STARTUPINFO STARTUPINFO;
: : ZeroMemory (& amp; StartupInfo, sizeof (startupInfo));
StartupInfo. Cb=sizeof (startupInfo);
//setting process creation does not display window
//startupInfo dwFlags STARTF_USEPOSITION=/* */STARTF_USESHOWWINDOW;
StartupInfo. DwFlags=STARTF_USEPOSITION;//STARTF_USESHOWWINDOW;
StartupInfo. DwX=600;
StartupInfo. DwY=900;
StartupInfo. WShowWindow=SW_HIDE;
If (: : CreateProcess (program, LPTSTR args,
NULL,//process security
NULL,//the thread security
FALSE,//no inheritance
0,//no startup flags
NULL,//no special environment
NULL,//the default startup directory
& StartupInfo,
& ProcessInfo))
{
//delay 0.5 s, wait for the process to create success
Sleep (500);
While (true)
{
: : EnumWindows (& amp; EnumWindowsProc, processInfo. DwThreadId);//Iterate all Windows
If (NULL!=apphWnd)
break;
}
HPro=processInfo. HProcess;
}
Return hPro;
}
If (apphWnd!=NULL)
{
OnQuit ();
}
CRect rect;
GetClientRect (& amp; The rect);//get our dialog size into the rect
HProcess=StartProcess (" my tools. Exe ", "");//Start ms paint
If (apphWnd!=NULL)//check for the window handle
{
: : SetParent (apphWnd m_hWnd);//set the parent of ms paint to our dialog.
SetWindowLong (apphWnd GWL_STYLE, WS_VISIBLE);//eraze title of ms paint window.
//Positioning ms paint.
: : MoveWindow (apphWnd, the rect. Left, the rect. The top, the rect. Right, the rect. Bottom, true);
Redrawing//window, (because of creating an exe, set to SW_HIDE, led to the parent window exe window will cover part of)
Invalidate ().
: : UpdateWindow (apphWnd);
: : ShowWindow (apphWnd, SW_SHOW);
}
The else
Always find a MessageBox (" Window ");
OnQuit ()
{
The TerminateProcess (hProcess, 0);
ApphWnd=NULL;
}
Run after the first picture there is no problem already inserted in the diagram below
But after launching the program changed, wrong
Run to the bottom
How can I solve
CodePudding user response:
Waiting for someone to help solve!CodePudding user response:
BOOL CMsPaintInMyDlgDlg: : GoMsPaint (char * path, BOOL bWait)
{
Char pathexe [MAX_PATH];
Strcpy (pathexe, "mspaint. Exe");
Strcat (pathexe, path);
STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
Memset (& amp; Sinfo, 0, sizeof (STARTUPINFO));
Sinfo. Cb=sizeof (STARTUPINFO);
Sinfo. DwFlags |=STARTF_USESHOWWINDOW;
Sinfo. WShowWindow=SW_HIDE;
//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
//
If (fsuccess)
{
Sleep (500);
CRect rect;
GetClientRect (& amp; The rect);//get our dialog size into the rect
M_hPaint=: : FindWindow (" MSPaintApp ", 0);
: : SetParent (m_hPaint m_hWnd);//set the parent of ms paint to our dialog.
: : ShowWindow (m_hPaint, SW_SHOW);
: : MoveWindow (m_hPaint, 0, 0, the rect. The Width (), the rect. Height (), true);
: : SetFocus (m_hPaint);
}
Return (fsuccess);
}
CodePudding user response: