Activating Single instance
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
-
Hi if your instance is already running you should call showwindow() with maximise option. Hope it works The Best Relligion is Science. Once you understand it, you will know God.
I had tried that option but the application crashes when I do that. Given below is the implementation.. CLimitSingleInstance g_SingleInstanceObj(TEXT("{A79AAE6A-62E1-4c0e-B678-72F127AD4B03}")); BOOL CKolOSDBuilderApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. if (g_SingleInstanceObj.IsAnotherInstanceRunning()) { AfxMessageBox("An instance is already running"); return FALSE; } laiju
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
I sometimes use the following method to only run a single instance, I simply use FindWindow to look for the window's title. Yes, I know if two programs have the same title this logic will fail, but that is 'unlikely'
if((hWnd = FindWindow(NULL, szTitle)) != NULL) { ShowWindow(hWnd, SW_RESTORE); SetForegroundWindow(hWnd); MessageBeep(MB_ICONEXCLAMATION); return(0); }
"An education isn't how much you have committed to memory, or even how much you know. It's being able to differentiate between what you do know and what you don't." - Anatole France
-
i tried using the variable theApp.m_pMainWnd to post a message ,but i think this doesnt have a valid pointer which crashes the application. BOOL CKolOSDBuilderApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. if (g_SingleInstanceObj.IsAnotherInstanceRunning()) { theApp.m_pMainWnd->SendMessage(WM_CLOSE_PROJECT,0,0); return FALSE; } laiju
-
i tried using the variable theApp.m_pMainWnd to post a message ,but i think this doesnt have a valid pointer which crashes the application. BOOL CKolOSDBuilderApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. if (g_SingleInstanceObj.IsAnotherInstanceRunning()) { theApp.m_pMainWnd->SendMessage(WM_CLOSE_PROJECT,0,0); return FALSE; } laiju
Remember that you post the message to your own application. You'll have to find a way to obtain the process handle of the previous application. You can always write a DLL that is shared among your applications and store various data there... There are a lot of ways to solve your problem! Behind every great black man... ... is the police. - Conspiracy brother Blog[^]
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
http://www.codeproject.com/cpp/avoidmultinstance.asp[^] laiju wrote: Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I used the technique described in Dr Newcomer's article to do just that in two of my articles, for an MFC example see here[^] and for a Win32 API example see here[^].
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!
-
I sometimes use the following method to only run a single instance, I simply use FindWindow to look for the window's title. Yes, I know if two programs have the same title this logic will fail, but that is 'unlikely'
if((hWnd = FindWindow(NULL, szTitle)) != NULL) { ShowWindow(hWnd, SW_RESTORE); SetForegroundWindow(hWnd); MessageBeep(MB_ICONEXCLAMATION); return(0); }
"An education isn't how much you have committed to memory, or even how much you know. It's being able to differentiate between what you do know and what you don't." - Anatole France
It will also fail if the app is an MDI or SDI app that has the opened file name in the caption.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
One way to do it is to create a mutex and an event in the application. The mutex is used to determine whether the application is already running or not. The event is used to signal the process which created it to show itself. All you need to do in the "single instance" process, is to listen to the event and respond to signals sent on it. See CreateEvent(), SetEvent(), and ResetEvent() in the MSDN docs. Good music: In my rosary[^]
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
laiju wrote: Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. See here.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
Using the class CLimitSingleInstance I have managed to enusure that only one instance of my application is active. I would like to do one more enhancement. Whenever there is an attempt to run multiple instance the current running instance should be restored to full view. I think it has to be done in the InitInstance() of my appln. Can anyone suggest the procedure. laiju
hi, Obviously u know the caption of your application..[I mean caption on the tittle bar of parent window] use FindWindow API to search with that window caption...if FindWindow API succeeds u will get the handle for that.. then u send the window resize message with that handle otherwise go as normal... try this in InitInstance... With Regards Prabhu.S www.PraxUnited.com