marco_coder
asked on
autoclose all open windows c/c++ or masm32.
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 :-) )
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 :-) )
..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);
::SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_DEST ROY,(LPARA M)0,(WPARA M)0);
//SendMessage(hWin,WM_CLOS E,(LPARAM) 0,(WPARAM) 0);
//CloseWindow(hWin);
if(DestroyWindow(hWin)==FA LSE)
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_BU FFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSE RTS,
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..!
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,(
//SendMessage(hWin,WM_DEST
//SendMessage(hWin,WM_CLOS
//CloseWindow(hWin);
if(DestroyWindow(hWin)==FA
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_BU
FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_IGNORE_INSE
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..!
ASKER
it worked!
Thanx!
Thanx!
you only specify windows title
CWnd* pWnd = CWnd::FindWindow(NULL, "india");
if (pWnd)
{
MessageBox ("found");
pWnd->GetOwner()->PostMess age(WM_QUI T);
}
here india is my application title
CWnd* pWnd = CWnd::FindWindow(NULL, "india");
if (pWnd)
{
MessageBox ("found");
pWnd->GetOwner()->PostMess
}
here india is my application title
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)