CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 1999
    Posts
    29

    not loaded two time!!!

    I want a application which will not be loaded if it is already loaded.
    (how I can determnine if I an in the second "instance" of this application ?
    (hPrevInstance from Win31)?)


  2. #2
    Join Date
    Apr 1999
    Location
    Tel-Aviv, Israel
    Posts
    7

    Re: not loaded two time!!!

    Here is one option, though i bet there are better ones. You could keep a flag in the registry stating if there is a program of your running currently, then every program can check the flag and if it TRUE than it should close itself.

    -----------------------------------------
    Rotem Bentzur
    [email protected]

    Feel free to send questions.....

  3. #3
    Join Date
    Jul 1999
    Location
    Moscow, Russia
    Posts
    667

    Re: not loaded two time!!!

    The are some ways, just now I remember two of them:

    1. Use FindWindow

    HWND hExist=FindWindow (0,szYourWindowTitle);
    if (hExist)
    return FALSE;



    2.Create Mutex like this:

    CreateMutex(NULL,TRUE,szAnyText); // mutex will be automatically deleted when process ends.
    BOOL bAlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS);
    if(bAlreadyRunning){
    char szMsg [256];
    strcpy (szMsg, "Application already started");
    m_pMainWnd->MessageBox (szMsg, "BLA_BLA_BLA",
    MB_OK | MB_ICONWARNING | MB_APPLMODAL);
    return FALSE;
    }





    The code above shouldbe placed in InitInstance.

    Good luck,
    Oleg.


  4. #4
    Join Date
    Apr 1999
    Location
    Bruton, Somerset, England
    Posts
    47

    Re: not loaded two time!!!

    Ok then, how can you then open up any files passed as parameters in the first instance.


  5. #5
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: not loaded two time!!!

    Hi,

    it's shown in the MSDN. Search for the article ID Q141752.

    Martin

  6. #6
    Join Date
    Jul 1999
    Location
    Moscow, Russia
    Posts
    667

    Re: not loaded two time!!!

    Please, can you describe your problem in more details. What do you want as the result?

    Oleg.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured