Click here to Skip to main content
15,901,283 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Draw on the none-client area Pin
Naveen9-Sep-07 22:32
Naveen9-Sep-07 22:32 
GeneralRe: Draw on the none-client area Pin
kcynic9-Sep-07 22:50
kcynic9-Sep-07 22:50 
GeneralRe: Draw on the none-client area Pin
Naveen9-Sep-07 23:15
Naveen9-Sep-07 23:15 
GeneralRe: Draw on the none-client area Pin
kcynic10-Sep-07 16:31
kcynic10-Sep-07 16:31 
QuestionChild-process without parents Pin
baerten9-Sep-07 21:31
baerten9-Sep-07 21:31 
AnswerRe: Child-process without parents [modified] Pin
Stephen Hewitt9-Sep-07 22:26
Stephen Hewitt9-Sep-07 22:26 
GeneralRe: Child-process without parents Pin
baerten9-Sep-07 22:50
baerten9-Sep-07 22:50 
GeneralRe: Child-process without parents Pin
Stephen Hewitt10-Sep-07 14:37
Stephen Hewitt10-Sep-07 14:37 
The procedure I outlined will do exactly what you want. Here's an example:
-----------------------------------------------

// ParentChild.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <conio.h>
#include <string>
#include <sstream>
#include <algorithm>
#include <memory>
#include <assert.h>

using namespace std;

HANDLE GetInheritableProcessHandle()
{
HANDLE hProcess;

BOOL bOK = DuplicateHandle(
GetCurrentProcess(), // HANDLE hSourceProcessHandle
GetCurrentProcess(), // HANDLE hSourceHandle
GetCurrentProcess(), // HANDLE hTargetProcessHandle
&hProcess, // LPHANDLE lpTargetHandle
SYNCHRONIZE, // DWORD dwDesiredAccess
TRUE, // BOOL bInheritHandle
0 // DWORD dwOptions
);

if (!bOK)
{
return NULL;
}

return hProcess;
}

void SpawnChild()
{
// Get our path.
char Us[MAX_PATH];
GetModuleFileName(NULL, Us, sizeof(Us));

// Get an inheritable process handle for this process.
HANDLE hUs = GetInheritableProcessHandle();
assert(hUs!=NULL);

// Build the command line.
ostringstream oss;
oss << "\"" << Us << "\" " << reinterpret_cast<DWORD>(hUs);
string CommandLine = oss.str();

// Build a mutable version of the command line string.
char *pMutable = new char[CommandLine.length()+1];
const char *pStr = CommandLine.c_str();
memcpy(pMutable, pStr, CommandLine.length()+1);

// Launch the child process.
STARTUPINFO si = {0};
si.cb = sizeof(si);
si.lpTitle = "I am the child!";
PROCESS_INFORMATION pi;
BOOL bOK = CreateProcess(
NULL, // LPCTSTR lpApplicationName
pMutable, // LPTSTR lpCommandLine
NULL, // LPSECURITY_ATTRIBUTES lpProcessAttributes
NULL, // LPSECURITY_ATTRIBUTES lpThreadAttributes
TRUE, // BOOL bInheritHandles
CREATE_NEW_CONSOLE, // DWORD dwCreationFlags
NULL, // LPVOID lpEnvironment
NULL, // LPCTSTR lpCurrentDirectory
&si, // LPSTARTUPINFO lpStartupInfo
&pi // LPPROCESS_INFORMATION lpProcessInformation
);

delete [] pMutable; // Free the memory.
CloseHandle(hUs);

if (!bOK)
{
return;
}

// As always, close handles you don't need or are finished with!
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}

int main(int argc, char* argv[])
{
if (argc==1)
{
cout << "I am the parent." << endl;
SpawnChild();
cout << "Press any key to exit." << endl;
_getch();
}
else
{
cout << "I am the child." << endl;

// Get the handle to the parent from the command line.
DWORD HandleValue;
istringstream iss(argv[1]);
iss >> HandleValue;
HANDLE hParent = reinterpret_cast<HANDLE>(HandleValue);

// Wait for the parent to exit or be killed.
WaitForSingleObject(hParent, INFINITE);

// Close handles you're finished with.
CloseHandle(hParent);
}

return 0;
}

Steve
GeneralRe: Child-process without parents Pin
baerten10-Sep-07 21:52
baerten10-Sep-07 21:52 
GeneralRe: Child-process without parents Pin
Stephen Hewitt10-Sep-07 22:05
Stephen Hewitt10-Sep-07 22:05 
GeneralRe: Child-process without parents Pin
baerten10-Sep-07 22:27
baerten10-Sep-07 22:27 
GeneralRe: Child-process without parents Pin
Stephen Hewitt11-Sep-07 19:26
Stephen Hewitt11-Sep-07 19:26 
AnswerRe: Child-process without parents Pin
vipin_nvk9-Sep-07 22:27
vipin_nvk9-Sep-07 22:27 
GeneralRe: Child-process without parents Pin
baerten9-Sep-07 23:49
baerten9-Sep-07 23:49 
GeneralRe: Child-process without parents Pin
Stephen Hewitt10-Sep-07 15:57
Stephen Hewitt10-Sep-07 15:57 
Questionfocus in edit control Pin
bhogavalli suresh9-Sep-07 20:03
bhogavalli suresh9-Sep-07 20:03 
AnswerRe: focus in edit control Pin
Nishad S9-Sep-07 20:08
Nishad S9-Sep-07 20:08 
GeneralRe: focus in edit control Pin
bhogavalli suresh9-Sep-07 20:29
bhogavalli suresh9-Sep-07 20:29 
GeneralRe: focus in edit control Pin
Nishad S9-Sep-07 20:32
Nishad S9-Sep-07 20:32 
GeneralRe: focus in edit control Pin
Wamuti9-Sep-07 21:35
Wamuti9-Sep-07 21:35 
GeneralRe: focus in edit control Pin
Nishad S9-Sep-07 22:24
Nishad S9-Sep-07 22:24 
AnswerRe: focus in edit control Pin
Sreedhar DV9-Sep-07 20:33
Sreedhar DV9-Sep-07 20:33 
AnswerRe: focus in edit control Pin
Wamuti9-Sep-07 21:25
Wamuti9-Sep-07 21:25 
GeneralRe: focus in edit control Pin
Stephen Hewitt9-Sep-07 22:03
Stephen Hewitt9-Sep-07 22:03 
QuestionRe: focus in edit control Pin
Wamuti9-Sep-07 22:47
Wamuti9-Sep-07 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.