Not opening multiple copies of a program & sending data to another program

This is a discussion on Not opening multiple copies of a program & sending data to another program within the Windows Programming forums, part of the Platform Specific Boards category; How can I have a program detect that it is already running and if it is it needs to send ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    43

    Not opening multiple copies of a program & sending data to another program

    How can I have a program detect that it is already running and if it is it needs to send a string of data to the already running copy and close itself.

    Dont know how to do either of these any pointers in the right direction would help

    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    For the first part, I'd do;

    Code:
    HWND find;
    find = FindWindow(NULL, InsertNameHere);
    
    if (find)
    {
    MessageBox(NULL,"terminating request... this program is currently in use.",
    "Permission Denied",MB_TOPMOST);
    PostQuitMessage(0);
    return 0;  //stop duplicate versions from launching
    }
    Or, something along those lines... Add the code before the window is created,
    that way it doesn't interfer with the initial launch of your program.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    What if another window shares the same title bar? What if you wanted your title bar to change (ie, "MyTextEditor - [ filename.myext ]" )

    CreateMutex seems to be how it's done, and allows you full control over your title bar.
    (GIYF)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    I understand your argument, though I've never run across that problem -

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    43
    Thanks, create mutex works great.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I use file mapping instead of a mutex, I have posted the code previously. Both are valid methods.

    To send info between processes I use a broadcast message, search on HWND_BROADCAST .
    "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. Linking data into program
    By Kennedy in forum C Programming
    Replies: 7
    Last Post: 04-25-2007, 01:02 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 09:55 PM
  3. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM
  4. How to input multiple groups of data
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-14-2002, 10:17 PM
  5. Extracting Data From Another Program
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 02-12-2002, 01:25 AM

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