После стольких поисков в Google я смог придумать следующую программу на С++, которая просто закрывает окна проводника без перезапуска процесса explorer.exe.
Здесь я использую EnumWindows и перебираю все окна и закрываю только окна проводника только на основе имени класса окна.
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
wofstream myfile;
BOOL CALLBACK enumWindowsProc(
__in HWND hWnd,
__in LPARAM lParam
) {
int length = 255;
TCHAR* buffer,*buffer1;
buffer = new TCHAR[ length + 1 ];
buffer1 = new TCHAR[ length + 1 ];
memset( buffer, 0, ( length + 1 ) * sizeof( TCHAR ) );
memset( buffer1, 0, ( length + 1 ) * sizeof( TCHAR ) );
DWORD pid;
DWORD dwThreadID = ::GetWindowThreadProcessId( hWnd, &pid);
::GetWindowText(hWnd,buffer,length +1);
wstring windowTitle = wstring( buffer );
delete[] buffer;
//cout << windowTitle.c_str();
::GetClassName(hWnd,buffer1,length +1);
wstring windowClass = wstring( buffer1 );
delete[] buffer1;
if(windowClass.compare(L"CabinetWClass") == 0 || windowClass.compare(L"ExploreWClass") == 0)
{
//::PostMessage(hWnd, WM_ENDSESSION, MAKEWORD(true,1), ENDSESSION_CLOSEAPP);
//::PostMessage(hWnd, 0x5B4, 0, 0);
PostMessage(hWnd,WM_CLOSE,0,0);
}
myfile << windowTitle.c_str();
myfile << L"|" ;
myfile << pid ;
myfile << L"|" ;
myfile << windowClass.c_str() ;
myfile << L"\n" ;
return TRUE;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
myfile.open ("processes.txt");
BOOL enumeratingWindowsSucceeded = ::EnumWindows( enumWindowsProc, NULL );
cin.get();
myfile.close();
return 0;
}
person
Engineer
schedule
23.07.2013