PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Deleting a wmv file.

I executed the wmv by using shellExecutex, then now after playing it, i want to delete it, I tired to delete but because the wmv is running in the background i'm unable to delete. Any one got a idea

Thanks in advance.
Do you mean close the program or delete a file?

In addition, why are you starting WMV in the first place? There might be a better way to do what you're trying to do.
It's a bit of a hack but you could use FindWindow to find the WMP window and send it a WM_CLOSE message.

Or persuade Microsoft that the smart minimize button was a galactically bad idea ;)
As Damian said, you need to clarify what you are trying to do. It sounds like you need to accomplish three different things:

Tell the player to close.
Determine if the player has closed.
Delete the WMV file.

If you check ShellExecuteEx's SHELLEXECUTEINFO struct docs you'll see:
<b>SEE_MASK_NOCLOSEPROCESS</b> Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates.

So to find out when the application closes, do a WaitForSingleObject on the HANDLE of the player application.

I'm not sure off the top of my head the best way to find the main window given a process handle. Try searching the net. You may have to iterate every top-level window and find the ones that are owned by the process handle you have. When you determine the correct window, then send it a WM_CLOSE like Dave H said. You can hardcode the name of the window or its class and search by that, but then if a different player is used (or possibly if a newer version of that player is released) then your app will not be able to find the window to close it.

As a last resort you can try killing the process using TerminateProcess, but that's not a good idea.

Dan East
Sorry but i'm just a newbie. can you guide me on how to use the Findwindow and WM_CLOSE

Currently i just coded

HWND winHandle
winHandle = FindWindow(what should i put here,NULL)

I know thats for the class name but how do i know the class name.

Thanks
or should i do this..

CWnd* pWnd=CWnd::FindWindows(_T("Does anyone know the classfile for WMP",NULL);

if(pWnd)
pWnd->SendMessage(WM_CLOSE);