Solved

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

Posted on 2006-07-21
6
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 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