Results 1 to 5 of 5

Thread: showing main window of prev running application

  1. #1

    Thread Starter
    Addicted Member chander's Avatar
    Join Date
    Nov 2000
    Location
    New Delhi , India
    Posts
    225

    showing main window of prev running application

    if a prev existance of application is running and i again run another instance of tht application then i want to popup that prev. application's main window in front as happens in Messengers .. and terminate newly created instance what to do for tht ..

    some thing like this in VB

    if app.previnstance then

    ' popup main window/form of previos running application
    termination of newly instance of application ..

    endif

    ne idea on it ??
    Chander
    Email:[email protected]

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You'd use a named mutex object for this - look it up in MSDN
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    Code:
    HANDLE hMutex;
    
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
    {
    
      hMutex = CreateMutex( NULL, FALSE, _T("ApplicationName") );
      if ( hMutex && (GetLastError() == ERROR_ALREADY_EXISTS )) {
        //Find Correct Window&Send to front;
      }
    
    //.....blah blah blah
      return 0;
    }
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    how abt this? AS i does not use Mutex before, pls coreect me, if my method is not a proper way

    PHP Code:
    int APIENTRY WinMain(HINSTANCE hInstanceHINSTANCE hPrevInstanceLPSTR lpCmdLineint nCmdShow)
    {
        
    // Check for previous instance
        
    hWnd FindWindow(TEXT("ClassName"), TEXT("WindowsTitle"));
        if (
    hWnd != NULL)
        {
            
    // Show the previous window
            
    SetForegroundWindow(hWnd);
            
    // Unload the current instance
            
    return false;
        }

        
    // Register application define class into windows system

        // Perform application initialization:

        // Main message loop:
        
    while (GetMessage(&msgNULL00)) 
        {
            
    TranslateMessage(&msg);
            
    DispatchMessage(&msg);
        }

        return 
    msg.wParam;


  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Chris: This method works too, as long as the app has a non-dialog main window.

    SetForegroundWindow is API and is used to bring the existing app to top.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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