Click here to Skip to main content
15,887,812 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Environment variable Pin
Jack200955-May-09 2:28
Jack200955-May-09 2:28 
AnswerRe: Environment variable Pin
Stuart Dootson5-May-09 3:16
professionalStuart Dootson5-May-09 3:16 
QuestionChoosing an IPC mechanism Pin
Rajesh R Subramanian5-May-09 1:46
professionalRajesh R Subramanian5-May-09 1:46 
AnswerRe: Choosing an IPC mechanism Pin
ParagPatel5-May-09 2:18
ParagPatel5-May-09 2:18 
GeneralRe: Choosing an IPC mechanism Pin
Rajesh R Subramanian5-May-09 2:28
professionalRajesh R Subramanian5-May-09 2:28 
AnswerRe: Choosing an IPC mechanism Pin
Stuart Dootson5-May-09 3:10
professionalStuart Dootson5-May-09 3:10 
GeneralRe: Choosing an IPC mechanism Pin
Rajesh R Subramanian5-May-09 4:08
professionalRajesh R Subramanian5-May-09 4:08 
AnswerRe: Choosing an IPC mechanism Pin
Randor 5-May-09 6:54
professional Randor 5-May-09 6:54 
Rajesh R Subramanian wrote:
The console app must be notified of the progress of this lengthy operation periodically.


Mailslots, sockets and named pipes.... all for a simple integer percentage value? SendMessage returns a value in its LRESULT which can be used in the console application to retrieve small values such as percentage complete.

Something like this:

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#include <Psapi.h>
#pragma comment(lib, "psapi")

#define WM_PERCENTAGE WM_USER + 1033

BOOL CALLBACK GetPercentageProc(HWND hWnd, LPARAM lParam)
{
    int nLen = GetWindowTextLength(hWnd);
	TCHAR szTitle[MAX_PATH];
    GetWindowText(hWnd, szTitle, MAX_PATH);
	if(_tcsstr(szTitle,_T("YourApplicationTitle")))
	{
		DWORD dwPID;
		TCHAR szModule[MAX_PATH];
		HMODULE hModule;
		DWORD dwNeeded;
		GetWindowThreadProcessId(hWnd,&dwPID);
		HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,dwPID);
		if(EnumProcessModules(hProcess,&hModule,sizeof(hModule),&dwNeeded))
		{
			GetModuleFileNameEx(hProcess,hModule,szModule,sizeof(szModule));
		}
		else
		{
			GetProcessImageFileName(hProcess,szModule,sizeof(szModule));
		}
		TCHAR * p = _tcsrchr(szModule,_T('\\'));
		if(0 == _tcscmp(++p,_T("YourExecutable.exe")))
		{
			LRESULT dwPercent = SendMessage(hWnd,WM_PERCENTAGE,0,0);
			DWORD dwP =  dwPercent;
			//Do whatever with your percentage value here.
		}
	}
    return TRUE;
}

int main()
{
	EnumWindows(GetPercentageProc, NULL);
	_getch();
	return 0;
}


Note that its recommended to use RegisterWindowMessage [^] for IPC although I did not use it in my example.

Best Wishes,
-David Delaune
GeneralRe: Choosing an IPC mechanism Pin
Rajesh R Subramanian6-May-09 1:34
professionalRajesh R Subramanian6-May-09 1:34 
QuestionDLL performance during the day? Pin
Chesnokov Yuriy5-May-09 0:40
professionalChesnokov Yuriy5-May-09 0:40 
AnswerRe: DLL performance during the day? Pin
CPallini5-May-09 1:45
mveCPallini5-May-09 1:45 
JokeRe: DLL performance during the day? Pin
Rajesh R Subramanian5-May-09 1:54
professionalRajesh R Subramanian5-May-09 1:54 
GeneralRe: DLL performance during the day? Pin
CPallini5-May-09 2:27
mveCPallini5-May-09 2:27 
AnswerRe: DLL performance during the day? Pin
Randor 5-May-09 5:36
professional Randor 5-May-09 5:36 
QuestionCleint Server - Connection refused. Pin
ganesh.dp4-May-09 23:27
ganesh.dp4-May-09 23:27 
QuestionMFC Pin
p_19604-May-09 23:17
p_19604-May-09 23:17 
AnswerRe: MFC Pin
Rajesh R Subramanian4-May-09 23:20
professionalRajesh R Subramanian4-May-09 23:20 
GeneralRe: MFC Pin
p_19604-May-09 23:32
p_19604-May-09 23:32 
GeneralRe: MFC Pin
Rajesh R Subramanian4-May-09 23:36
professionalRajesh R Subramanian4-May-09 23:36 
AnswerRe: MFC Pin
Chandrasekharan P4-May-09 23:23
Chandrasekharan P4-May-09 23:23 
GeneralBad answer! Pin
Rajesh R Subramanian4-May-09 23:26
professionalRajesh R Subramanian4-May-09 23:26 
GeneralRe: Bad answer! Pin
Chandrasekharan P4-May-09 23:29
Chandrasekharan P4-May-09 23:29 
GeneralRe: Bad answer! Pin
Cedric Moonen4-May-09 23:31
Cedric Moonen4-May-09 23:31 
GeneralRe: Bad answer! Pin
CPallini4-May-09 23:35
mveCPallini4-May-09 23:35 
GeneralRe: Bad answer! Pin
Rajesh R Subramanian4-May-09 23:35
professionalRajesh R Subramanian4-May-09 23:35 

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.