Getting all window handles on taskbar

This is a discussion on Getting all window handles on taskbar within the Windows Programming forums, part of the Platform Specific Boards category; Hi. Here is my problem: I want to get the HWND of every window that is running and terminate the ...

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    Getting all window handles on taskbar

    Hi.
    Here is my problem:
    I want to get the HWND of every window that is running and terminate the window except my own window
    (it's for a program to protect my computer).

    I just can't get it good to work, I have tried many things but all didn't work, here is some code:

    PHP Code:
    //In the infinity loop, near the PeekMessage function

    Other_Window GetWindow Main_WindowGW_HWNDPREV );//Get a window from the taskbar

            
    if ( Main_Window != Other_Window )//Check if it is my own window
            
    {

                
    DWORD Process_ID;

                
    GetWindowThreadProcessId Other_Window, & Process_ID );

                
    HANDLE Illigal_Process OpenProcess PROCESS_TERMINATEFALSEProcess_ID );

                
    TerminateProcess Illigal_Process);

                
    CloseHandle Illigal_Process );
            } 
    What goes wrong: first of all, it doesn't do anything, but if I press Ctrl + Alt + Delete it immediate terminates the Windows Task Manager,
    which is good but all the other applications are still running and if I press on the Taskbar the code terminates explorer.exe.
    I tried to prevent this by: GetDesktopWindow() != Other_Window, doesn't work.

    How can I get all the HWND's of visible windows in the taskbar to terminate them that only my program stands and without terminating explorer.exe?

  2. #2
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Woot, I finally got it now, here is an example how to get all visible windows that are running on desktop, from this code I can do what I want:

    PHP Code:
    #include <iostream>
    #include <windows.h>

    using namespace std;

    bool CALLBACK Process_Windows HWND Window )
    {

        
    char Window_Caption 1024 ],
             
    Window_Class 1024 ];

        if ( 
    IsWindowVisible Window ) )
        {

            if ( 
    GetWindowText WindowWindow_Caption1024 ) <= )
            {

                
    cout << "\"No Caption\"";
            }

            else
            {

                
    cout << Window_Caption;
            }

            
    cout << endl;

            if ( 
    GetClassName WindowWindow_Class1024 ) <= )
            {

                
    cout << "\"No Class\"";
            }

            else
            {

                
    cout << Window_Class;
            }

            
    cout << endl << endl;
        }

        return 
    true;
    }

    int main()
    {

        
    EnumWindows ( ( WNDENUMPROC Process_Windows);

        
    cin.get();

    Oh and thanks for the loads and loads of reply's, I even couldn't read them all because there were so many...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

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