1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
.....
startupInfo.wShowWindow = SW_HIDE;
startupInfo.dwX=0;
startupInfo.dwY=0;
startupInfo.dwXSize=Form1->Width; // on fixe la largeur de la fenêtre fille
startupInfo.dwYSize=Form1->Height; // on fixe la Hauteur de la fenêtre fille
startupInfo.dwFlags =STARTF_USESHOWWINDOW|STARTF_USESIZE|STARTF_USEPOSITION;
ProcessCreated=CreateProcess( NULL,
"C:\\Windows\\System32\\Notepad.exe",
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&startupInfo,
&procInfo);
if(ProcessCreated) Sleep(100);
HWND HWindow = FindWindow(NULL, "Sans titre- Bloc-notes"); // Caption de la fenêtre
HWND HNewParent = Form1->Handle;
if (HWindow != NULL && HNewParent != NULL)
{
::SetParent(HWindow, HNewParent);
ShowWindow(HWindow,SW_SHOW); // on affiche la fenêtre fille
}
....
// ne pas oublier de tuer le process créé auparavant, par exemple dans le destructeur de la Form
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
// procInfo est un membre privé de la classe TForm
TerminateProcess(procInfo.hProcess,0); // on termine le process
WaitForSingleObject( procInfo.hProcess, INFINITE ); // on attend sa fermeture
CloseHandle( procInfo.hProcess ); // libération des Handles créés
CloseHandle( procInfo.hThread );
} |
Partager