Thread: Task Manager technic

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    38

    Task Manager technic

    Hey guys,

    From my understanding when your closing a window from Task Manager, it sends a WM_CLOSE or WM_QUIT (not sure). So I used : SendMessageA(hWin,WM_CLOSE,0,0); and it worked, but unfortunately it didn't work on my other window. It works when I close it from Task Manager but not from sending a SendMessage. So can anyone tell me the way that task manager closes windows and help me out with the coding thanks.

  2. #2
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    If you opened another window such as a child window, close those windows first then close the main program's window.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    Thanks, but theres not child window. It's kinda weird because when I close it with Task Manager it works. When I send a SendMessage it doesn't work. Does Task Manager work by sending a SendMessage?

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    There are several messages sent when a window is beign closed. WM_QUIT, WM_DESTROY are the two most common. Typically you would want to PostMessage() , not SendMessage(). Post a WM_DESTROY message to the appropriate HWND then post a WM_QUIT to the same HWND and the application should exit.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    I tried doing PostMessage(hWin,WM_DESTROY,0,0);
    PostMessage(hWin,WM_QUIT,0,0);

    It tried using this on another window it worked, but when I tried on my desired window it didn't work. Is there any program that can tell me if the application received the command?

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There's a program, Spy++, that comes with Visual Studio. It allows you to monitor all messages a program receives.

    You could monitor an application and then close it through task manager to find out what it does.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Quote Originally Posted by NoFearXD View Post
    I tried doing PostMessage(hWin,WM_DESTROY,0,0);
    PostMessage(hWin,WM_QUIT,0,0);

    It tried using this on another window it worked, but when I tried on my desired window it didn't work. Is there any program that can tell me if the application received the command?
    There's also WM_CLOSE.
    If messages don't work, try ExitProcess() then on last resort do TerminateProcess().

  8. #8
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    Well thanks guys, but this guy from msdn forum replied and told me that Task Manager uses "EndTask" to close the window. So I looked it up in msdn http://msdn2.microsoft.com/en-us/library/ms633492.aspx but when I compile it says 'EndTask' : undeclared identifier. I included windows.h and it doesn't work. Any help here?

    And Queatrix thanks but I really don't want to use those. I hope the EndTask will eventually work.

  9. #9
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Why don't you read the whole page?
    Quote Originally Posted by http://msdn2.microsoft.com/en-us/library/ms633492.aspx
    Remarks

    Although you can access this function by using LoadLibrary and GetProcAddress combined in Microsoft Windows versions prior to Windows XP, the function is not accessible using the standard Include file and library linkage. The header files included in Windows XP Service Pack 1 (SP1) and Windows Server 2003 document this function and make it accessible using the appropriate Include file and library linkage. However, this function is not intended for general use. It is recommended that you do not use it in new programs because it might be altered or unavailable in subsequent versions of Windows. a
    >> And Queatrix thanks but I really don't want to use those.
    >> I hope the EndTask will eventually work.

    You may have to though, as the window your closing may be locked up.

  10. #10
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    Yup, your right, I used this tool http://www.diamondcs.com.au/index.php?page=apt to see what method was working, and EndTask didn't but TerminateProcess did. But I don't understand how come its working since you need to have the process handle which you get by using OpenProcess, but in my case OpenProcess is hooked and returns an error.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Never call TerminateProcess on anything unless you
    a) encounter a critical error in your own application and need to terminate it or
    b) you know the target application cannot close normally.

    TerminateProcess is brutal and will e.g. not allow the program to ask the user to save data.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Task Manager: Applications vs Processes
    By Shwick in forum Windows Programming
    Replies: 3
    Last Post: 08-14-2008, 06:47 AM
  2. hide from task manager
    By koyboy in forum Windows Programming
    Replies: 6
    Last Post: 05-27-2008, 04:00 PM
  3. Registry - Looking for Task Manager
    By HaVoX in forum Tech Board
    Replies: 1
    Last Post: 11-08-2005, 12:35 PM
  4. Replies: 5
    Last Post: 04-17-2003, 07:07 AM
  5. Scheduling Algo
    By BigDaddyDrew in forum C++ Programming
    Replies: 41
    Last Post: 03-08-2003, 11:00 AM