Click here to Skip to main content
15,900,378 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionProgramatically change paper size during execution of PageSetupDlg Pin
hx200011-Nov-09 11:06
hx200011-Nov-09 11:06 
Question[Message Deleted] Pin
hunter12348311-Nov-09 9:26
hunter12348311-Nov-09 9:26 
AnswerRe: Result search clustering using salient phrase extaction Pin
Richard MacCutchan11-Nov-09 9:50
mveRichard MacCutchan11-Nov-09 9:50 
QuestionHow to get a process name from process ID ? Pin
hongheo7611-Nov-09 9:25
hongheo7611-Nov-09 9:25 
AnswerRe: How to get a process name from process ID ? Pin
Randor 11-Nov-09 9:43
professional Randor 11-Nov-09 9:43 
GeneralRe: How to get a process name from process ID ? Pin
hongheo7611-Nov-09 10:37
hongheo7611-Nov-09 10:37 
GeneralRe: How to get a process name from process ID ? Pin
Randor 11-Nov-09 11:18
professional Randor 11-Nov-09 11:18 
AnswerRe: How to get a process name from process ID ? Pin
wangningyu11-Nov-09 21:37
wangningyu11-Nov-09 21:37 
Here is a Class to use:
// ProcessNametoID.h: interface for the CProcessNametoID class.<br />
//<br />
//////////////////////////////////////////////////////////////////////<br />
<br />
#if !defined(AFX_PROCESSNAMETOID_H__4217BFFA_FB96_4DAF_A665_3EF82774CD57__INCLUDED_)<br />
#define AFX_PROCESSNAMETOID_H__4217BFFA_FB96_4DAF_A665_3EF82774CD57__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
class CProcessNametoID  <br />
{<br />
public:<br />
	CProcessNametoID();<br />
	DWORD GetProcessID(char* m_name);<br />
	virtual ~CProcessNametoID();<br />
private:<br />
	HANDLE m_snapshot;<br />
<br />
};<br />
<br />
#endif // !defined(AFX_PROCESSNAMETOID_H__4217BFFA_FB96_4DAF_A665_3EF82774CD57__INCLUDED_)<br />


// ProcessNametoID.cpp: implementation of the CProcessNametoID class.<br />
//<br />
//////////////////////////////////////////////////////////////////////<br />
<br />
#include "stdafx.h"<br />
#include "ProcessID.h"<br />
#include "ProcessNametoID.h"<br />
#include <Tlhelp32.h><br />
<br />
#ifdef _DEBUG<br />
#undef THIS_FILE<br />
static char THIS_FILE[]=__FILE__;<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
//////////////////////////////////////////////////////////////////////<br />
// Construction/Destruction<br />
//////////////////////////////////////////////////////////////////////<br />
<br />
CProcessNametoID::CProcessNametoID()<br />
{<br />
	this->m_snapshot=NULL;<br />
}<br />
<br />
CProcessNametoID::~CProcessNametoID()<br />
{<br />
	<br />
}<br />
<br />
DWORD CProcessNametoID::GetProcessID (char* m_name)<br />
{<br />
	DWORD m_pid=0;<br />
	bool  m_status=false;<br />
	PROCESSENTRY32 m_ppe;<br />
	::memset(&m_ppe,0,sizeof(PROCESSENTRY32));<br />
	m_ppe.dwSize=sizeof(PROCESSENTRY32);<br />
	__try<br />
	{<br />
		this->m_snapshot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br />
		if(this->m_snapshot==NULL)<br />
		{<br />
			__leave;<br />
		}<br />
		<br />
		m_status=::Process32First(this->m_snapshot ,&m_ppe);	<br />
		int a=::GetLastError();<br />
		while(m_status)<br />
		{<br />
			char *current;<br />
			current=m_ppe.szExeFile;<br />
			if(lstrcmpi(m_name,current))<br />
			{<br />
				m_status=::Process32Next(this->m_snapshot ,&m_ppe);<br />
			}<br />
			else<br />
			{<br />
				m_pid=m_ppe.th32ProcessID;<br />
				m_status=false;<br />
			}<br />
		}<br />
	}<br />
	__finally<br />
	{<br />
		::CloseHandle (this->m_snapshot);<br />
		return m_pid;<br />
	}<br />
}<br />



Best Reguards !
General[OT] Re: How to get a process name from process ID ? Pin
David Crow12-Nov-09 5:26
David Crow12-Nov-09 5:26 
GeneralRe: [OT] Re: How to get a process name from process ID ? Pin
wangningyu12-Nov-09 15:53
wangningyu12-Nov-09 15:53 
Questionconverting string to time [modified] Pin
sugarandcream11-Nov-09 8:46
sugarandcream11-Nov-09 8:46 
AnswerRe: converting string to time Pin
David Crow11-Nov-09 9:05
David Crow11-Nov-09 9:05 
GeneralRe: converting string to time Pin
sugarandcream11-Nov-09 10:12
sugarandcream11-Nov-09 10:12 
QuestionRe: converting string to time Pin
David Crow11-Nov-09 10:15
David Crow11-Nov-09 10:15 
AnswerRe: converting string to time Pin
sugarandcream11-Nov-09 10:45
sugarandcream11-Nov-09 10:45 
QuestionRe: converting string to time Pin
David Crow11-Nov-09 10:53
David Crow11-Nov-09 10:53 
AnswerRe: converting string to time Pin
sugarandcream11-Nov-09 11:05
sugarandcream11-Nov-09 11:05 
GeneralRe: converting string to time Pin
David Crow12-Nov-09 2:39
David Crow12-Nov-09 2:39 
Questionre: sending a text message from main thread to a client thread Pin
Alan Kurlansky11-Nov-09 5:07
Alan Kurlansky11-Nov-09 5:07 
QuestionRe: re: sending a text message from main thread to a client thread Pin
David Crow11-Nov-09 5:12
David Crow11-Nov-09 5:12 
AnswerRe: re: sending a text message from main thread to a client thread Pin
Alan Kurlansky11-Nov-09 5:23
Alan Kurlansky11-Nov-09 5:23 
GeneralRe: re: sending a text message from main thread to a client thread Pin
David Crow11-Nov-09 5:27
David Crow11-Nov-09 5:27 
GeneralRe: re: sending a text message from main thread to a client thread Pin
Paulo Zemek11-Nov-09 5:29
Paulo Zemek11-Nov-09 5:29 
GeneralRe: re: sending a text message from main thread to a client thread Pin
Rajesh R Subramanian11-Nov-09 6:57
professionalRajesh R Subramanian11-Nov-09 6:57 
QuestionReading and writing files to the System Directory in Windows Vista using C++, MFC and fopen Pin
D_code_writer11-Nov-09 4:20
D_code_writer11-Nov-09 4:20 

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.