3 Simple Questions PLEASE HELP URGENT 
Author Message
 3 Simple Questions PLEASE HELP URGENT

Hi,
I have 3 simple questions for which I need the solution asap..please
help me
I work on vc++ 5.0 and windnt.

1)  I have an application (a dialog based application) running , When I
logoff the machine  with the applicaiton still running I need to throw a
dialog to the user saying the application is still ruuning and need to
do some gracefull shutdown HOW TO DO IT ?

2) How to get the logon username from the system?.. I need this
information in my applicaiton..how to get the user name of the user.

3) I need to check if the applicaiton is already running and if the user
trys to start the application , if its already running I should not
start it...I mwean there should be only one instance of the applicaiton
running in the system..
please help me out
its very urgent I am stuck
thank you
vijju}
happy new year



Tue, 19 Jun 2001 03:00:00 GMT  
 3 Simple Questions PLEASE HELP URGENT

Quote:
> Hi,
> I have 3 simple questions for which I need the solution asap..please
> help me
> I work on vc++ 5.0 and windnt.

> 1)  I have an application (a dialog based application) running , When I
> logoff the machine  with the applicaiton still running I need to throw a
> dialog to the user saying the application is still ruuning and need to
> do some gracefull shutdown HOW TO DO IT ?

Handle the WM_QUERYENDSESSION and WM_ENDSESSION messages appropiately.
Quote:

> 2) How to get the logon username from the system?.. I need this
> information in my applicaiton..how to get the user name of the user.

Unless you have special security needs, specially on NT, GetUserName() will
probably do the job for you.

Quote:

> 3) I need to check if the applicaiton is already running and if the user
> trys to start the application , if its already running I should not
> start it...I mwean there should be only one instance of the applicaiton
> running in the system..

The usual method is to create a named mutex when the application starts,
then call GetLastError() and see if it returns ERROR_ALREADY_EXISTS. If it
does, then another instance of your app is running.

Quote:
> please help me out
> its very urgent I am stuck
> thank you
> vijju}
> happy new year

--
Tomas Restrepo

http://members.xoom.com/trestrep/


Tue, 19 Jun 2001 03:00:00 GMT  
 3 Simple Questions PLEASE HELP URGENT

Quote:
>> 3) I need to check if the applicaiton is already running and if the user
>> trys to start the application , if its already running I should not
>> start it...I mwean there should be only one instance of the applicaiton
>> running in the system..
> The usual method is to create a named mutex when the application starts,
> then call GetLastError() and see if it returns ERROR_ALREADY_EXISTS. If it
> does, then another instance of your app is running.

There's an easier way to detect if a previous instance of a program is running.
I use the FindWindow API providing the ClassName and NULL to the function.
It'll return a handle to the window, if one is found. If a window of your
window class name is found, you can be 99.99% sure that it's your program
that's running (same thing with a mutex). I recommend using GUIDGEN from the
SDK and setting it's output to your window class' name. This will create a
*theoretically* globally unique identifier, which will reduce the chances of
having a ClassName used by another programmer. This only thing a mutex will
allow you to do that this method won't is to have a more "stylish" window class
name (who cares?). Using the mutex method will require you to do the procedure
below, so you're better off not using a mutex (post if you object).

Include something like this in your InitInstance function, before you create
your main window:

/////

hwnd = FindWindow( ClassName, NULL );

if ( hwnd ) // If a window of the classname was found...
{ // (A previous instance of this application is running.)

  MessageBox( NULL, "A previous instance of this program is running."
              "Error", MB_ICONEXCLAMATION" ); // Display the problem

  if( IsIconic( hwnd )) // if window is iconic (minimized)...
      ShowWindow( hwnd, SW_RESTORE ); // Restore it

  SetForegroundWindow( hwnd ); // Set it as the foreground wnd
  return FALSE; // InitInstance returns FALSE, ending the new instance.
 }

/////

Happy New Year, :)

Andy G.



Tue, 19 Jun 2001 03:00:00 GMT  
 3 Simple Questions PLEASE HELP URGENT
I've got a correction to make on one of the lines of code that I posted earlier
on...

It should be:

  MessageBox( NULL, "A previous instance of this program is running.",
              "Error", MB_ICONEXCLAMATION ); // Display the problem

Instead of:

  MessageBox( NULL, "A previous instance of this program is running."
              "Error", MB_ICONEXCLAMATION" ); // Display the problem

Andy G.



Tue, 19 Jun 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 3 Simple Questions PLEASE HELP URGENT

2. Newbie needs urgent help, simple question

3. URGENT URGENT PLEASE HELP ME ActiveX multiples classes

4. Urgent IDL question, please help

5. Please Help With URGENT Question

6. simple variable question (fixed ...please help)

7. simple variable question (please help)

8. A Simple Question From A Beginner (Please Help)

9. Very Simple Question (Reading INI), Please Help!

10. PLEASE HELP - Simple array question

11. Simple Question- PLEASE HELP!!!

12. Can someone please help with this simple question.

 

 
Powered by phpBB® Forum Software