miliraj1 wrote:
> Hi,
> 
>  need urgent help. I am trying to check that IE is launched or not, if
> yes then close it.
> 
> Can someone help me to write a code for this problem. I did try
> GetActiveWindow then CloseMainWindow but doesn't work.
> 
> other approche is here...
> 
> int _tmain(int argc, _TCHAR* argv[])
> {
>       //HWND hActiveWindow = GetActiveWindow();
>       MessageBox(GetActiveWindow(),hehe,"Checking",MB_OK);
> 
>       /*LPCWSTR wName = L"Untitled - Notepad";
>       HWND hndl =     FindWindow(NULL, wName);   
>       if (hndl == NULL)
>       {
>               DWORD dw=GetLastError();
>               A a;
>               a.ErrorExit(TEXT("_tmain"));
> 
>       }*/
>       //CloseWindow(hActiveWindow);
>       
> }
> 
> void A::ErrorExit(LPTSTR lpszFunction) 
> { 
>     // Retrieve the system error message for the last-error code
> 
>     LPVOID lpMsgBuf;
>     LPVOID lpDisplayBuf;
>     DWORD dw = GetLastError(); 
> 
>     FormatMessage(
>         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
>         FORMAT_MESSAGE_FROM_SYSTEM |
>         FORMAT_MESSAGE_IGNORE_INSERTS,
>         NULL,
>         dw,
>         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
>         (LPTSTR) &lpMsgBuf,
>         0, NULL );
> 
>     // Display the error message and exit the process
> 
>     lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
>        
> (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
> 
>     StringCchPrintf((LPTSTR)lpDisplayBuf, 
>         LocalSize(lpDisplayBuf) / sizeof(TCHAR),
>         TEXT("%s failed with error %d: %s"), 
>         lpszFunction, dw, lpMsgBuf); 
>     MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 
> 
>     LocalFree(lpMsgBuf);
>     LocalFree(lpDisplayBuf);
>     ExitProcess(dw); 
> }
> 
> thanks,
> Raj

The executable is going to be named 'iexplore.exe'.  Enumerate windows, 
for each window get the thread and process ids of the window handle. 
For each ID, open the process and get the filename of the process.  If 
the process filename is 'iexplore.exe', send a close message to the 
window (preferably with a timeout).  If the window fails to close in 
some reasonable amount of time, forcefully terminate the process.

EnumWindows()
GetWindowThreadProcessId()
OpenProcess()
TerminateProcess()
CloseHandle()

That should get you started.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to