Creating Single instance Application
-
Hi, My application while starting is placed in the systray as a icon. When i double click the icon, i get a Dialog. If i execute my application again, i get one more icon in the systray and similarly if i double click the icon twice two dialogs appear on the screen. I want to have only one icon on the systray and even if i click the icon again ( ie double click ) it should show only the previous dialog and not the new one. ie I want to have only one instance of my application at any time. Can anybody help me in doing this. Thanks in advance VMJ
-
Hi, My application while starting is placed in the systray as a icon. When i double click the icon, i get a Dialog. If i execute my application again, i get one more icon in the systray and similarly if i double click the icon twice two dialogs appear on the screen. I want to have only one icon on the systray and even if i click the icon again ( ie double click ) it should show only the previous dialog and not the new one. ie I want to have only one instance of my application at any time. Can anybody help me in doing this. Thanks in advance VMJ
Hello, In first line of InitInstance method of the Your application class, put the following code, APP_NAME -- is the DialogWindow Title. if(AfxGetMainWnd( )->FindWindow(NULL, APP_NAME)) { AfxMessageBox("Application Already running"); exit(0); } If any suggesstions let me know. Thanks , - Kannan.A.;)
-
Hello, In first line of InitInstance method of the Your application class, put the following code, APP_NAME -- is the DialogWindow Title. if(AfxGetMainWnd( )->FindWindow(NULL, APP_NAME)) { AfxMessageBox("Application Already running"); exit(0); } If any suggesstions let me know. Thanks , - Kannan.A.;)
Hello, ;-p it works fine, but if you have open another window with the same name (e.g. explorer window or application with the same name) your application won't start. Better way is to create some kernel object (MS suggest mutex) when your application starts and destroy at ending. Before creating you simply try to open such object and if succeded it means that your application is already running. Regards Bartek