Stopping an outside application

This is a discussion on Stopping an outside application within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing a program which gets interrupted when another window is called on top ( eg. When you receive a ...

  1. #1
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209

    Stopping an outside application

    I'm writing a program which gets interrupted when another window is called on top ( eg. When you receive a message from a chat client, for example MSN ). Is there any way to shut down this application at the start of my program ? Thanks.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    There are several solutions. One solution is to search for whatever application you want to terminate via FindWindow(). Another solution is to enumerate active processes.

    Kuphryn

  3. #3
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    I thought of FindWindow(), however people will use MSN or other clients in different languages, and I probably won't be able to find them. I haven't heard of enumeration, what is it ? How can I use it ?

    Also, is there any way to find out if the user is connected to the Internet, finding out if he has a modem, and breaking the internet connection ?

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I'm not sure I understand exactly what you're trying to do, but you could use FindWindow() and search for the class, instead of the window name. The class stays the same, no matter what language is selected.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    What is the window class ? I understand this is the first statement entered in the FindWindow() function, but how do I find it out ? Does each unique program / window have its unique class, and is it the same on every computer ?

  6. #6
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Programmer [noun] : A savage sub-species of Human ( Homo Sapiens Sapiens ), whose odd social behaviour and rituals remain little known by humans. Living on code, they spend their time in a mysterious trance-like state in front of what they call "compilers", which we believe is a gateway to their deities.
    i love it.

    you will need FindWindowEx to search for the different windows.
    when you find the window you want to close you could probley send a WM_DESTROY message or something
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Sorry my net screwed up, it posted three times.
    Last edited by bennyandthejets; 07-29-2003 at 01:52 AM.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    again
    Last edited by bennyandthejets; 07-29-2003 at 01:53 AM.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Korhedron, you've asked a big question there. I wouldn't know how to explain it exactly, because I only learnt about window classes through experience. But I'll try:

    Every window that is created in Windows is created with a particular window class. The class is either a built-in or custom made structure that defines certain aspects that the window will have. For example, the window procedure that is used, the application icon, the default menu, or the background brush (the pattern and color of the background). Look up the WNDCLASSEX structure on MSDN for more details. Basically, classes save you a lot of time by allowing you to specify the same details for a window over and over, without writing everything out.

    A good example is the BUTTON class. It's a built-in, or predefined, class in Windows. In a program, you may have many buttons. Without classes, you would have to write the window procedures (including graphics coding, mouse interaction coding, and memory allocation) again and again for every button. Instead, they encapsulated the code into a container, or class, that you can specify with just 6 letters.

    So, say you want to list all of the MSN chat windows on your screen at the current time. Instead of searching the window captions, which vary depending on who you're talking to, you search the window classes, which will be the same for every single MSN chat window. On my computer, this class is "IMWindowClass". The following code will find you the first Messenger window open:

    Code:
    HWND hwnd=FindWindow("IMWindowClass",NULL);
    If you want to find all the Messenger windows open, you'll have to use EnumWindows(), and check each window class to see if it's a match.

    And yes, this class should be the same on every computer. To find it out, use Spy++. If you don't have that, you'll have to make a program yourself that enumerates all the windows and their window classes. You can identify the window you want by the caption.

    I hope this helps.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cleanup of the application...
    By Petike in forum Windows Programming
    Replies: 1
    Last Post: 08-16-2008, 06:23 PM
  2. Problem with com application
    By amardon in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2005, 06:50 AM
  3. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 04:33 AM
  4. Win application not very portable
    By swed in forum Windows Programming
    Replies: 5
    Last Post: 10-01-2001, 12:17 PM

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