News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Temporary File Creation/Deletion

Started by htek, February 09, 2005, 12:28:10 PM

Previous topic - Next topic

htek

Okay - now, I've got a program which has a function that summarizes a certain directory and the files within into an HTML file. Now - I want a certain button to display the page in the default browser [currently via ShellExecute]. However, I want the file to be deleted once the WINDOW in the target program is closed - is this even possible in a foolproof way?

I could loop enumerate windows aand look for my file in the title bar, but not all browsers will display the filename [it uses a title field] - and the HTML file is designed to have a custom title instead of using the filename.

Any ideas?

regards,


'h

doomsday

Shell ExecuteEx gives you a handle to the created process.  From there I suppose you could call GetExitCodeProcess in a loop, or one of the WaitForXXXObject functions until the browser process is terminated before deleting the generated HTML file.  Make sure you've got the approprate access (for example GetExitCodeProcess needs PROCESS_QUERY_INFORMATION access to the handle) before trying to determine if the ShellExecute'd process is finished.

To be honest, I haven't tried this yet but I can't imagine why it wouldn't work... appart from the Windows gremlins which make perfectly plausable code fall appart :)

regards,
-Brent

htek

i was thinking more of a window thing - you see, it would be possible for me to wait for the targeted browser to finish the process, but this would be infeasible considering the situation. the program i'm working on is heavily internet-related. therefore, if i'm online using the program [it's really quite useless offline], i'd have other browser windows open. I can't wait for the mozilla process to terminate either - it stays active while there's other URLs open. wouldn't want to have mozilla close on me while i'm browsing masmforum.com, WOULD I? :P

err... correct me if i'm completely wrong here :D

regards,


'h

doomsday

Hmm.. I see.  The answer is kludge.. which looks something like...

- EnumWindows (get a list of all top-leve HWNDs)
- ShellExecuteEx
- WaitForInputIdle( hBrowserProcess)
- EnumWindows (to find a window which isn't in the list, then assume the new one is your browser window)
- periodicall call IsWindow( hwndMyBrowserWindow) to tell if it's still there

I wish that there was a more elegant solution but I don't think there is one which will work across all/most browsers.

regards,
-Brent