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
Solved

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

Posted on 2006-07-21
6
367 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…

839 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