Click here to Skip to main content
15,892,965 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: to Run UNIX based EXE [MKS] through Shell in VC++ application Pin
David Crow13-May-08 3:35
David Crow13-May-08 3:35 
QuestionMenu item in Visual C++ greyed out and doesn't send command message Pin
Bluesray11-May-08 11:40
Bluesray11-May-08 11:40 
QuestionHow do I code Spin Control dialog button Pin
Kwanalouie11-May-08 9:08
Kwanalouie11-May-08 9:08 
AnswerRe: How do I code Spin Control dialog button Pin
JudyL_MD11-May-08 12:23
JudyL_MD11-May-08 12:23 
AnswerRe: How do I code Spin Control dialog button Pin
David Crow11-May-08 16:42
David Crow11-May-08 16:42 
QuestionProblem with Domodal overide behavior Pin
tom groezer11-May-08 8:25
tom groezer11-May-08 8:25 
AnswerRe: Problem with Domodal overide behavior Pin
Mark Salsbery11-May-08 11:10
Mark Salsbery11-May-08 11:10 
AnswerRe: Problem with Domodal overide behavior Pin
Mark Salsbery11-May-08 12:11
Mark Salsbery11-May-08 12:11 
Here's an example of method 1 in my previous post:

//--------------------------------------
// IDD_PROCESSWAITER dialog resource
//--------------------------------------

IDD_PROCESSWAITER DIALOGEX 0, 0, 193, 50
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
CAPTION "Waiting..."
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    CTEXT           "Waiting for process to complete...",IDC_STATIC,7,17,179,8
END



//--------------------------------------
// ProcessWaiter.h
//--------------------------------------

#pragma once

// CProcessWaiter dialog

class CProcessWaiter : public CDialog
{
	DECLARE_DYNAMIC(CProcessWaiter)

	CString ProcessPathname;

	static UINT __cdecl ProcessCreatorAndWaiterThread(LPVOID pParam);

public:
	CProcessWaiter(CWnd* pParent = NULL);   // standard constructor
	virtual ~CProcessWaiter();

	INT_PTR ExecuteProcessAndWait(LPCTSTR pathname);

// Dialog Data
	enum { IDD = IDD_PROCESSWAITER };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()

protected:
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	virtual void OnCancel();
	afx_msg LRESULT OnThreadComplete(WPARAM wParam, LPARAM lParam);
};



//--------------------------------------
// ProcessWaiter.cpp
//--------------------------------------

// ProcessWaiter.cpp : implementation file
//

#include "stdafx.h"
#include "ProcessWaiter.h"


#define WMX_THREADCOMPLETE (WM_APP + 42)

// CProcessWaiter dialog

IMPLEMENT_DYNAMIC(CProcessWaiter, CDialog)

CProcessWaiter::CProcessWaiter(CWnd* pParent /*=NULL*/)
	: CDialog(CProcessWaiter::IDD, pParent)
{
}

CProcessWaiter::~CProcessWaiter()
{
}

INT_PTR CProcessWaiter::ExecuteProcessAndWait(LPCTSTR pathname)
{
	ProcessPathname = pathname;

	return DoModal();
}


UINT __cdecl CProcessWaiter::ProcessCreatorAndWaiterThread(LPVOID pParam)
{
	CProcessWaiter *pThis = (CProcessWaiter*) pParam;

	PROCESS_INFORMATION ProcessInfo;
	STARTUPINFO StartupInfo;
	memset(&StartupInfo, 0, sizeof(STARTUPINFO));
	StartupInfo.cb = sizeof(STARTUPINFO);  

	if (0 != ::CreateProcess(pThis->ProcessPathname,//  LPCTSTR lpApplicationName,
							NULL,					//  LPTSTR lpCommandLine,
							NULL,					//  LPSECURITY_ATTRIBUTES lpProcessAttributes,
							NULL,					//  LPSECURITY_ATTRIBUTES lpThreadAttributes,
							FALSE,					//  BOOL bInheritHandles,
							NORMAL_PRIORITY_CLASS,	//  DWORD dwCreationFlags,
							NULL,					//  LPVOID lpEnvironment,
							NULL,					//  LPCTSTR lpCurrentDirectory,
							&StartupInfo,			//  LPSTARTUPINFO lpStartupInfo,
							&ProcessInfo			//  LPPROCESS_INFORMATION lpProcessInformation
							))
	{
		::WaitForSingleObject(ProcessInfo.hProcess, INFINITE);

		::CloseHandle(ProcessInfo.hProcess);  
		::CloseHandle(ProcessInfo.hThread);  
	}

	pThis->PostMessage(WMX_THREADCOMPLETE);

	return 0;
}


void CProcessWaiter::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CProcessWaiter, CDialog)
	ON_MESSAGE(WMX_THREADCOMPLETE, &CProcessWaiter::OnThreadComplete)
END_MESSAGE_MAP()


// CProcessWaiter message handlers

BOOL CProcessWaiter::OnInitDialog()
{
	CDialog::OnInitDialog();

	AfxBeginThread(&CProcessWaiter::ProcessCreatorAndWaiterThread, this);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CProcessWaiter::OnOK()
{
	// Do nothing!
}

void CProcessWaiter::OnCancel()
{
	// Do nothing!
}

LRESULT CProcessWaiter::OnThreadComplete(WPARAM wParam, LPARAM lParam)
{
	EndDialog(0);

	return 0;
}



//--------------------------------------
// Example usage
//--------------------------------------

#include "stdafx.h"
#include "ProcessWaiter.h"
...
	CProcessWaiter ProcessWaiter(this);
	ProcessWaiter.ExecuteProcessAndWait(_T("C:\\Windows\\system32\\notepad.exe"));


Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: Problem with Domodal overide behavior Pin
Nelek11-May-08 13:02
protectorNelek11-May-08 13:02 
GeneralRe: Problem with Domodal overide behavior Pin
tom groezer11-May-08 21:16
tom groezer11-May-08 21:16 
GeneralRe: Problem with Domodal overide behavior Pin
Mark Salsbery12-May-08 5:16
Mark Salsbery12-May-08 5:16 
QuestionProblem with Domodal overide behavior Pin
tom groezer11-May-08 8:24
tom groezer11-May-08 8:24 
AnswerRe: Problem with Domodal overide behavior Pin
Nelek11-May-08 13:01
protectorNelek11-May-08 13:01 
QuestionTPM in windows XP. Pin
Green Fuze11-May-08 4:09
Green Fuze11-May-08 4:09 
QuestionRe: TPM in windows XP. Pin
David Crow11-May-08 16:51
David Crow11-May-08 16:51 
AnswerRe: TPM in windows XP. Pin
Green Fuze12-May-08 0:21
Green Fuze12-May-08 0:21 
QuestionIs there any way to remove process from Task manager ? Pin
Yanshof11-May-08 2:45
Yanshof11-May-08 2:45 
AnswerRe: Is there any way to remove process from Task manager ? Pin
Hamid_RT11-May-08 4:26
Hamid_RT11-May-08 4:26 
GeneralRe: Is there any way to remove process from Task manager ? Pin
Yanshof11-May-08 4:33
Yanshof11-May-08 4:33 
GeneralRe: Is there any way to remove process from Task manager ? Pin
Hamid_RT11-May-08 5:07
Hamid_RT11-May-08 5:07 
GeneralRe: Is there any way to remove process from Task manager ? Pin
Yanshof11-May-08 18:42
Yanshof11-May-08 18:42 
GeneralRe: Is there any way to remove process from Task manager ? Pin
Hamid_RT11-May-08 19:04
Hamid_RT11-May-08 19:04 
AnswerRe: Is there any way to remove process from Task manager ? Pin
Maximilien11-May-08 5:03
Maximilien11-May-08 5:03 
GeneralRe: Is there any way to remove process from Task manager ? Pin
Yanshof11-May-08 18:41
Yanshof11-May-08 18:41 
GeneralRe: Is there any way to remove process from Task manager ? Pin
David Crow12-May-08 2:48
David Crow12-May-08 2:48 

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.