Click here to Skip to main content
16,006,006 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Multiple different dialogs -- answered it myself Pin
David Fleming15-Jun-01 15:08
David Fleming15-Jun-01 15:08 
GeneralRe: Multiple different dialogs -- answered it myself Pin
20-Jun-01 11:08
suss20-Jun-01 11:08 
Generalhelp in mfc Pin
Julio14-Jun-01 12:16
Julio14-Jun-01 12:16 
GeneralRe: help in mfc Pin
Carlos Antollini14-Jun-01 12:25
Carlos Antollini14-Jun-01 12:25 
Generalgetting hwnd from process id Pin
14-Jun-01 12:02
suss14-Jun-01 12:02 
GeneralRe: getting hwnd from process id Pin
Oliver Daniel14-Jun-01 14:15
Oliver Daniel14-Jun-01 14:15 
GeneralRe: getting hwnd from process id Pin
Tim Deveaux14-Jun-01 14:31
Tim Deveaux14-Jun-01 14:31 
GeneralRe: getting hwnd from process id Pin
#realJSOP15-Jun-01 1:22
professional#realJSOP15-Jun-01 1:22 
This is code ripped from one of my apps. I think I got everything.

In the header file, I have this:

const int UWM_FOUNDHWNDADMIN = WM_APP + 1;

class CDlg : public CDialog
{
	//{{AFX_MSG(CD2LauncherDlg)
	//}}AFX_MSG
	afx_msg LRESULT OnFoundHwnd(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()

private:
	PROCESS_INFORMATION* m_pProcessInfo;
	HWND                 m_hwnd;

	void RunComponent();
	void GetAppHWnd();
};

static BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam);


In the CPP file, I have this:

void CDlg::RunD2RemoteAdmin()
{
	CString sFileName = GetProgramPath();
	AddBackSlash(sFileName);
	sFileName += "MyProgram.exe";

	if (FileExists(sFileName))
	{
		char cmdLine[1024];
		strcpy(cmdLine,(const char*)sFileName);

		m_pProcessInfo = new PROCESS_INFORMATION;
		if (!m_pProcessInfo)
		{
			CString sMsg;
			sMsg = "Could not allocate memory for component process info (not critical)";
			AfxMessageBox(sMsg);
			return;
		}

		STARTUPINFO StartupInfo = {0};
		StartupInfo.cb          = sizeof(STARTUPINFO);

		if (::CreateProcess(NULL, cmdLine, NULL, NULL, FALSE,
							0, NULL, NULL, &StartupInfo, m_pProcessInfo))
		{
			WaitForInputIdle(m_pProcessInfo->hProcess, 15000);
			GetAppHWnd();
		}		
	}
	else
	{
		CString sMsg;
		sMsg = "Could not find executable component";
		AfxMessageBox(sMsg);
	}
}

void CDlg::GetAppHWnd()
{
	DWORD  pid = m_pProcessInfo->dwProcessId;
	HANDLE ps  = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid);
	EnumWindows(EnumWindowsProcGetHwnd, pid);
	CloseHandle(ps);
}

LRESULT CDlg::OnFoundHwnd(WPARAM wParam, LPARAM lParam)
{
	wParam;
	lParam;

	m_hwnd = (HWND)wParam;
	DWORD dwPID = (DWORD)lParam;
	if (dwPID == m_pProcessInfo->dwProcessId)
	{
		// success
	}
	else
	{
		// failure
	}
	return 1L;
}

BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam)
{
	CString sTitle;
	CWnd::FromHandle(hwnd)->GetWindowText(sTitle);

	DWORD wndPid;
	::GetWindowThreadProcessId(hwnd, &wndPid);
	if (wndPid == (DWORD)lParam && !sTitle.IsEmpty())
	{
		// You only have to do this if you know a portion of the window 
		// title of the program in question
		if (sTitle.Find("Remote Admin Monitor") >= 0)
		{
			theApp.m_pMainWnd->SendMessage(UWM_FOUNDHWNDADMIN, (WPARAM)hwnd, lParam);
		}
		return FALSE;
	}
	else
	{
		return TRUE;
	}
}

GeneralCListCtrl Scrolling Question Pin
14-Jun-01 10:30
suss14-Jun-01 10:30 
GeneralAgain...Win9X and NT compatibility problem Pin
14-Jun-01 10:27
suss14-Jun-01 10:27 
GeneralRe: Again...Win9X and NT compatibility problem Pin
Tomasz Sowinski15-Jun-01 0:21
Tomasz Sowinski15-Jun-01 0:21 
GeneralUsing STL map<...> Pin
Rostrox14-Jun-01 10:11
Rostrox14-Jun-01 10:11 
GeneralRe: Using STL map<...> Pin
Ben Burnett14-Jun-01 15:15
Ben Burnett14-Jun-01 15:15 
GeneralRe: Using STL map<...> Pin
14-Jun-01 17:02
suss14-Jun-01 17:02 
GeneralRe: Using STL map<...> Pin
markkuk14-Jun-01 20:35
markkuk14-Jun-01 20:35 
GeneralReading and Writing files in Win32 Pin
14-Jun-01 9:11
suss14-Jun-01 9:11 
GeneralRe: Reading and Writing files in Win32 Pin
14-Jun-01 9:54
suss14-Jun-01 9:54 
GeneralGetting data from MSCOMM !!! Pin
Hadi Rezaee14-Jun-01 8:59
Hadi Rezaee14-Jun-01 8:59 
GeneralLoading small, built-in icons Pin
14-Jun-01 7:17
suss14-Jun-01 7:17 
GeneralRe: Loading small, built-in icons Pin
Ben Burnett14-Jun-01 7:41
Ben Burnett14-Jun-01 7:41 
GeneralRe: Loading small, built-in icons Pin
14-Jun-01 7:57
suss14-Jun-01 7:57 
GeneralRe: Loading small, built-in icons Pin
14-Jun-01 8:03
suss14-Jun-01 8:03 
GeneralRe: Loading small, built-in icons Pin
Ben Burnett14-Jun-01 9:19
Ben Burnett14-Jun-01 9:19 
Generalprint preview and multi frame app Pin
SAWilde14-Jun-01 6:35
SAWilde14-Jun-01 6:35 
GeneralSplitter window using C and NOT C++ Pin
14-Jun-01 6:33
suss14-Jun-01 6:33 

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.