One process at a time

This is a discussion on One process at a time within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I want to have one process of my app running at a time. How can I do this? OK, ...

  1. #1
    Mox
    Mox is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    41

    One process at a time

    Hi,

    I want to have one process of my app running at a time. How can I do this?
    OK, that's the basic question. Now I'll give some more details:
    I'm making a control panel app. I've kept it pretty basic for testing purpose. So this is the code:
    Code:
    BOOL CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(uMsg)
    	{
    	case WM_CLOSE:
    		EndDialog(hWnd, 0);
    		return true;
    	}
    
    	return false;
    }
    
    LONG CALLBACK CPlApplet(HWND  hwndCPl,	
    						UINT  uMsg,	
    						LONG  lParam1,
    						LONG  lParam2)
    {
    	CPLINFO *		CL;
    
    	switch (uMsg) { 
            case CPL_INIT:      // first message, sent once 
    			return true;
                break; 
     
            case CPL_GETCOUNT:  // second message, sent once 
                return 1; 
     
            case CPL_INQUIRE: // third message, sent once per app 
    			CL = (CPLINFO *) lParam2;
    
    			CL->idIcon	= IDI_MAIN;
    			CL->idInfo	= IDS_INFO;
    			CL->idName	= IDS_NAME;
    			
                break; 
     
            case CPL_SELECT:    // applet icon selected 
                break; 
     
            case CPL_DBLCLK:    // applet icon double-clicked  
    			DialogBox(g_hMod, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
    			break;
    			
            case CPL_STOP:      // sent once per app. before CPL_EXIT 
                break; 
     
            case CPL_EXIT:    // sent once before FreeLibrary is called 
                break; 
     
            default: 
                break; 
        } 
    	return 0;
    }
    So when it starts, I create a modal dialog box, without a parent. This is what I want (non parent) because then it is displayed in the taskbar. (or is there another way to put it there with a parent) But now if you create multiple instances of it, it kinda works and doesn't work. There's only one instance created (the second call does nothing, I don't know why), but the window doesn't get focus and that's also what I want.
    If I give the dialog box a parent it does get focus (but like I said I want it in the task bar).
    Is there a way around this?
    And another question. I create control panels with "rundll32.exe shell32.dll,Control_RunDLL file.cpl". So there all controlled by rundll, which I guess only opens the control panel app one time, so subsequent calls to the same cpl are ignored?

    I hope you could follow it, if not just say so and I'll try again

    Joren

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The way I ensure there is only one copy of my program running, I think that's what you mean, is to call CreateMutex() with a name unique to my application, then a call to GetLastError(). If the application created the mutex, then there are no other instances running, if there were, GetLastError() will return ERROR_ALREADY_EXISTS and I exit.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I have posted code for file mapping to tell if your app is already running, do a search.

    If you want your app to appear in the task bar create a window, with a reg. class, and hide it. Or create it with 1x1 dimensions and move it if the user moves your dialog.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When does a process not consume time
    By chasek92009 in forum C Programming
    Replies: 2
    Last Post: 10-21-2007, 07:34 PM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. time synchronization problem
    By freeindy in forum C Programming
    Replies: 1
    Last Post: 04-19-2007, 06:25 AM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21