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

C / C++ / MFC

 
GeneralRestricting file opening with Only one instance of application like Acrobat Reader Pin
Adi Narayana15-Apr-04 4:21
Adi Narayana15-Apr-04 4:21 
GeneralRe: Restring file opening with Only one instance of application like Acrobat Reader Pin
basementman15-Apr-04 4:25
basementman15-Apr-04 4:25 
GeneralRe: Restring file opening with Only one instance of application like Acrobat Reader Pin
Adi Narayana15-Apr-04 4:37
Adi Narayana15-Apr-04 4:37 
GeneralRe: Restring file opening with Only one instance of application like Acrobat Reader Pin
vcplusplus15-Apr-04 5:40
vcplusplus15-Apr-04 5:40 
GeneralRe: Restricting file opening with Only one instance of application like Acrobat Reader Pin
David Crow15-Apr-04 7:09
David Crow15-Apr-04 7:09 
GeneralRe: Restricting file opening with Only one instance of application like Acrobat Reader Pin
Joel Lucsy16-Apr-04 3:32
Joel Lucsy16-Apr-04 3:32 
GeneralRe: Restricting file opening with Only one instance of application like Acrobat Reader Pin
Adi Narayana19-Apr-04 3:54
Adi Narayana19-Apr-04 3:54 
GeneralRe: Restricting file opening with Only one instance of application like Acrobat Reader Pin
Joel Lucsy19-Apr-04 7:11
Joel Lucsy19-Apr-04 7:11 
Well, after determining that another instance is present, (I use the IsInstancePresent code from one of the articles here), and that you have a command line that you need to pass to the other instance, then do something like:
<br />
DWORD	result;<br />
LRESULT	ok;<br />
HANDLE	fm;<br />
char	*buf;<br />
CString	fmn;<br />
DWORD	pid;<br />
UINT MyProgMsgId;<br />
<br />
MyProgMsgId = RegisterWindowMessage( "MyProgMsg" );<br />
pid = GetCurrentProcessId();<br />
fmn.Format( "MyProg%ld", pid );<br />
fm = CreateFileMapping( (HANDLE)0xffffffff, NULL, PAGE_READWRITE, 0, 8192, fmn );<br />
buf = (char*)MapViewOfFile( fm, FILE_MAP_WRITE, 0, 0, 8192 );<br />
ZeroMemory( buf, 8192 );<br />
strcpy( buf, cmdline );<br />
ok = SendMessageTimeout( HWND_BROADCAST, MyProgMsgId, pid, 0, SMTO_BLOCK|SMTO_ABORTIFHUNG, 20000, &result );<br />
UnmapViewOfFile( buf );<br />
CloseHandle( fm );<br />

Make sure the RegisterWindowMessage happens in both cases (processing the command line and full GUI). Now the MFC gui codes need a line in the message map:
<br />
ON_REGISTERED_MESSAGE(theApp.MyProgMsgId,OnMyProgMsg)<br />

and the code handler will look something like:
<br />
LRESULT CRePlotDlg::OnMyProgMsg( WPARAM w, LPARAM l )<br />
{<br />
	CString		fmn, str;<br />
	HANDLE		fm;<br />
	char		*buf;<br />
	<br />
	fmn.Format( "MyProg%ld", w );<br />
	fm = OpenFileMapping( FILE_MAP_WRITE, FALSE, fmn );<br />
	buf = (char*)MapViewOfFile( fm, FILE_MAP_WRITE, 0, 0, 8192 );<br />
	str = buf;<br />
	UnmapViewOfFile( buf );<br />
	CloseHandle( fm );<br />
	ReplyMessage( TRUE );<br />
<br />
	HandleURL( str );<br />
<br />
	return TRUE;<br />
}<br />

Note that this is just an example and you'll have to make sure that certain variables belong to the right things, but it should give you a good starting point. If you need further explanation on anything, let me know.


--
Joel Lucsy
GeneralRe: Restricting file opening with Only one instance of application like Acrobat Reader Pin
Blake Miller19-Apr-04 9:03
Blake Miller19-Apr-04 9:03 
GeneralRe: Restricting file opening with Only one instance of application like Acrobat Reader Pin
Joel Lucsy19-Apr-04 9:10
Joel Lucsy19-Apr-04 9:10 
Generaltemplate problem &amp; remove_if Pin
Anonymous15-Apr-04 4:11
Anonymous15-Apr-04 4:11 
GeneralRe: template problem &amp; remove_if Pin
antlers15-Apr-04 11:32
antlers15-Apr-04 11:32 
GeneralRe: template problem &amp; remove_if Pin
Anonymous15-Apr-04 22:18
Anonymous15-Apr-04 22:18 
GeneralActiveX Control Pin
roadragedave15-Apr-04 3:39
roadragedave15-Apr-04 3:39 
GeneralRe: ActiveX Control Pin
Cedric Moonen15-Apr-04 3:52
Cedric Moonen15-Apr-04 3:52 
GeneralRe: ActiveX Control Pin
roadragedave15-Apr-04 4:30
roadragedave15-Apr-04 4:30 
GeneralDevice context problems Pin
mikewithersone15-Apr-04 3:34
mikewithersone15-Apr-04 3:34 
GeneralRe: Device context problems Pin
PJ Arends15-Apr-04 6:05
professionalPJ Arends15-Apr-04 6:05 
GeneralRe: Device context problems Pin
mikewithersone15-Apr-04 7:34
mikewithersone15-Apr-04 7:34 
GeneralRe: Device context problems Pin
PJ Arends15-Apr-04 11:45
professionalPJ Arends15-Apr-04 11:45 
GeneralRe: Device context problems Pin
mikewithersone15-Apr-04 12:47
mikewithersone15-Apr-04 12:47 
GeneralRe: Device context problems Pin
PJ Arends15-Apr-04 12:55
professionalPJ Arends15-Apr-04 12:55 
GeneralRe: Device context problems Pin
mikewithersone15-Apr-04 13:24
mikewithersone15-Apr-04 13:24 
GeneralRe: Device context problems Pin
PJ Arends15-Apr-04 13:39
professionalPJ Arends15-Apr-04 13:39 
GeneralRe: Device context problems Pin
mikewithersone15-Apr-04 13:46
mikewithersone15-Apr-04 13:46 

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.