Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString Find Pin
8-Jul-01 5:29
suss8-Jul-01 5:29 
GeneralSingle application instance Pin
Joe Moldovan7-Jul-01 12:35
Joe Moldovan7-Jul-01 12:35 
GeneralRe: Single application instance Pin
Tim Deveaux7-Jul-01 12:55
Tim Deveaux7-Jul-01 12:55 
GeneralRe: Single application instance Pin
l a u r e n7-Jul-01 23:00
l a u r e n7-Jul-01 23:00 
GeneralRe: Single application instance Pin
Stan Shannon8-Jul-01 1:07
Stan Shannon8-Jul-01 1:07 
GeneralRe: Single application instance Pin
Vu Nguyen7-Dec-01 14:43
Vu Nguyen7-Dec-01 14:43 
GeneralRe: Single application instance Pin
Vu Nguyen10-Dec-01 10:29
Vu Nguyen10-Dec-01 10:29 
GeneralRe: Single application instance Pin
Joe Moldovan8-Jul-01 10:15
Joe Moldovan8-Jul-01 10:15 
Great ideas but just as much work as my original. Pity that hInstance is not atomic across multi-cpu systems but that's asking a lot.

Here is my solution for anyone who is interested. I don't think its very elegant but it works.

At the beginning of xxxApp::InitInstance()look for an event.

BOOL CTestApp::InitInstance()
{
// See if an instance of myself is already running
if (( eDoIExist = OpenEvent( EVENT_ALL_ACCESS, NULL,
"YesIExist" )) != NULL )
{
// Yes. There is someone out there. Wake it up.
SetEvent( eDoIExist );
// And get out
return FALSE;
}

// No. I am the first so set up an event.
eDoIExist = CreateEvent( NULL, TRUE, FALSE, "YesIExist" );

..... Later in the init code when the main window (in my case a dialog) is
..... set up

CTestDlg dlg;
m_pMainWnd = &dlg;

// Create a background thread to look for any other instance and send it
// the main window
::CreateThread( NULL, 0, LookForMyself, m_pMainWnd , 0, NULL );

..... At the end of the same source

DWORD WINAPI LookForMyself( LPVOID lpParameter )
{
// Forever
do
{
WaitForSingleObject( eDoIExist, INFINITE );

// This is just a little flashy way of re-activating the running
// instance
((CDialog *)lpParameter)->ShowWindow( SW_SHOWMINIMIZED );
((CDialog *)lpParameter)->ShowWindow( SW_RESTORE );

// Reset and wait for more intruders
ResetEvent( eDoIExist );

} while ( TRUE );

return 0;
}

Thank you all for your responses!

GeneralRe: Single application instance Pin
8-Jul-01 13:21
suss8-Jul-01 13:21 
GeneralRe: Single application instance Pin
8-Jul-01 13:25
suss8-Jul-01 13:25 
GeneralRe: Single application instance Pin
9-Jul-01 3:56
suss9-Jul-01 3:56 
GeneralRe: Single application instance Pin
Bret Faller9-Jul-01 11:27
Bret Faller9-Jul-01 11:27 
QuestionHow to create a menu bar in ATL control Pin
Oliver Daniel7-Jul-01 8:59
Oliver Daniel7-Jul-01 8:59 
AnswerRe: How to create a menu bar in ATL control Pin
7-Jul-01 10:10
suss7-Jul-01 10:10 
GeneralRe: How to create a menu bar in ATL control Pin
Oliver Daniel8-Jul-01 3:01
Oliver Daniel8-Jul-01 3:01 
Generalfile opening Pin
7-Jul-01 7:15
suss7-Jul-01 7:15 
GeneralRe: file opening Pin
7-Jul-01 9:33
suss7-Jul-01 9:33 
GeneralRe: file opening Pin
7-Jul-01 21:32
suss7-Jul-01 21:32 
GeneralRe: file opening Pin
Michael Dunn7-Jul-01 19:54
sitebuilderMichael Dunn7-Jul-01 19:54 
GeneralRe: file opening Pin
8-Jul-01 10:35
suss8-Jul-01 10:35 
GeneralDeskTop Icon Pin
Muhammad Nauman Khan7-Jul-01 6:52
Muhammad Nauman Khan7-Jul-01 6:52 
GeneralDeskTop Icon Pin
Muhammad Nauman Khan7-Jul-01 6:52
Muhammad Nauman Khan7-Jul-01 6:52 
GeneralMenu in MDI Child Pin
Simon Brown7-Jul-01 6:14
Simon Brown7-Jul-01 6:14 
GeneralDialog Resizing Pin
7-Jul-01 4:23
suss7-Jul-01 4:23 
GeneralRe: Dialog Resizing Pin
User 110607-Jul-01 5:05
User 110607-Jul-01 5:05 

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.