Releasing window handle

I am working on testing a file copy application. I created a tiny win32 console app to help with testing. This app has to just set focus on a window named "Copy File" and exit. Then I manually click on Cancel to cancel copy or OK to continue copying.

Here is the code:

This is the code I am using:

HWND anyWindow = ::FindWindow(NULL,"Copy File");

:: SetForegroundWindow(anyWindow);

anyWindow = NULL;

Once the app bring the copy file app to forground, I click cancel and exit. Then I try to delete the file I am trying to copy. But I cannot delete the file because I get an error saying I can proceed with the delete. If I do this manually, it works fine. But if I use my test app, I get the error message. I suspect that my test app is holding on to the copy file window handle even after it exits. Is setting anyWindow window handle to NULL the right way to release the handle?

Thanks in advance for your help,

MC11

[1141 byte] By [MC11] at [2008-1-7]
# 1
Handles to windows are stored in a global list and there is no reference counting or anything on them so it will not matter. If anything, there is a lock on the file stopping this from happening. Make sure you release all handles to the file when you no longer need them. Also, if you do close down the app and then try to delete the file immediately afterwards there is no telling when Windows will release any open file handles.

crescens2k at 2007-10-2 > top of Msdn Tech,Visual C++,Visual C++ General...