Solved

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

Posted on 2006-07-21
6
341 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now