Solved

autoclose all open windows c/c++ or masm32.

Posted on 2006-07-21
6
374 Views
Last Modified: 2008-02-01
Hi,

I am looking for some code to CLOSE ALL windows. (not shutdown winxp)


- find all OPEN windows  AND/OR find by Title,caption
- close it after 20 seconds. (repeat forever :-) )



0
Comment
Question by:marco_coder
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17156372
C++:

1) The GetDesktopWindow function returns a handle to the desktop window.

2) The EnumWindows function enumerates all top-level windows on the screen.

3) For each top-level window call EnumChildWindows. This call should be recursive to get all childs (call the same function for each enumerated window).

- AlexFM (http:/Q_20543904.html)
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17156381
..Then to close a window from which you have the handle, send the SC_CLOSE system message to it:
::SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL);
0
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 440 total points
ID: 17156423
Shove this in an infinite loop, and have a Sleep(20*1000); at the end of each loop.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:marco_coder
ID: 17163776
Hi,

so far i have managed to FIND the window.
And i try`d to close it but....
ERROR CODE =5 WICH = ACCESS DENIED.

see code here:
-------------------
#include <windows.h>
#include <iostream>
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")



using namespace std;
void blahblah();
int Message();


int main(int argc, TCHAR* argv[], TCHAR* envp[])
{

blahblah();

}



void blahblah()
{


      DWORD SEED=0;
      HWND hWin;
HWND hWin2;
const DWORD MINOR=30;
   for(;;)
   {

         if( hWin = FindWindow(NULL,"Million Dollar Traffic") )
{
cout << endl << " window  found" << endl; //TApplication
SendMessage(hWin,WM_QUIT,(LPARAM)0,(WPARAM)0);
//SendMessage(hWin,WM_DESTROY,(LPARAM)0,(WPARAM)0);
//SendMessage(hWin,WM_CLOSE,(LPARAM)0,(WPARAM)0);
//CloseWindow(hWin);
if(DestroyWindow(hWin)==FALSE)
Message();
}
//Internet Explorer_Server




Sleep(1000* (SEED+MINOR));
   SEED+2;
   SEED*5 /MINOR;
if(SEED>20)
SEED=1;


   } // end for


}



int Message()
{
LPVOID lpMsgBuf;
if (!FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER |
    FORMAT_MESSAGE_FROM_SYSTEM |
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL ))
{
   // Handle the error.
   return 1;
}

//MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
cout << endl << (LPCTSTR)lpMsgBuf << endl;
// Free the buffer.
LocalFree( lpMsgBuf );





return 0;

}





---------------------------


i know its complex.... i wonder how i can get ACCESS to a window instead of ACCESS DENIED.... confused..!

0
 

Author Comment

by:marco_coder
ID: 17163796
it worked!
Thanx!
0
 
LVL 1

Expert Comment

by:yogesh28577
ID: 17173843
you only specify windows title

CWnd* pWnd = CWnd::FindWindow(NULL, "india");
if (pWnd)
{
MessageBox ("found");
pWnd->GetOwner()->PostMessage(WM_QUIT);
}

here india is my application title
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question