Detecting other prograrm instances in VC++ (MFC), please help...

This is a discussion on Detecting other prograrm instances in VC++ (MFC), please help... within the Windows Programming forums, part of the Platform Specific Boards category; I'm try to find a way in which to detect instances of other program in VC++ (MFC classes). For example, ...

  1. #1
    Unregistered
    Guest

    Question Detecting other prograrm instances in VC++ (MFC), please help...

    I'm try to find a way in which to detect instances of other program in VC++ (MFC classes).

    For example, say I have 6 Paint program running at once, but I want to limit only to 3 at a time, how do I check and close the others right before it started to run?

    Please help, I'm new to Window programming.

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    You'll probably have to use FindWindow() and SendMessage(), you can look these two functions up on MSDN... but basically you want to find the window, and send a WM_CLOSE message to it.

    It's much easier to check if your own program is being run more than once then it is to check if someone elses is. (eg Paint)

  3. #3
    Unregistered
    Guest

    Thumbs up

    Thank you, that's all the pointers I needed, the rest I can eventually figure out.

  4. #4
    Unregistered
    Guest

    Unhappy

    Turn out it wasn't that easy as I thought it would be. Could you please help me a little bit further by showing me examples of how to use that function?

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    If you know the apps name then

    hMapping = CreateFileMapping((HANDLE)0xffffffff, NULL, PAGE_READONLY, 0, 32, szAppName);

    and using the

    GetLastError()==ERROR_ALREADY_EXISTS

    returns may work (can easily limit to only one instance).

    Remember to close the handle at the end with CloseHandle().
    "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. MFC Controls and Thread Safety :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 12-06-2002, 10:36 AM
  2. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  3. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 05:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 12:33 AM

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