Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th April 2007, 21:40   #1  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
How to monitor a Win32 application?

Hi!

I'd like to write a small tool that can monitor another Win32 application and detect the occurrence of a certain message (dialog box). I don't need to send anything back to the host application, just monitor it and perform a certain task once the message occurs.

To be more concrete: I want to monitor Avidemux until the encoding process is completed and the "Done!" message appears. Then I want shut down the computer, which is an easy task to do. Only problem is to detect the right moment for shutdown.

BTW: I want to use Delphi7 to write my tool.

Any suggestions are welcome
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote
Old 4th April 2007, 22:35   #2  |  Link
jeffy
Registered User
 
Join Date: Jan 2007
Posts: 943
Something like this?
http://www.delphidabbler.com/article...=2#progrunning
(Finding if your program is running)
jeffy is offline   Reply With Quote
Old 4th April 2007, 23:08   #3  |  Link
JohnnyMalaria
Registered User
 
Join Date: Sep 2006
Posts: 602
Windows provides a number of API functions that can help you:

FindWindow and FindWindowEx

You'll need to look at the documentation on MSDN and translate the syntax to suit Delphi.

Firstly, use FindWindow to find Avidemux' top-level window:

HWND FindWindow( LPCTSTR lpClassName,
LPCTSTR lpWindowName
);

lpClassName can be NULL.
lpWindowName will be a zero-terminated string with the name (i.e., caption) of the window to find - whatever Avidemux' main caption is.

HWND FindWindowEx( HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow
);

hwndParent will be the top-level Avidemux window handle. This function will search all its child windows for a match. Set lpszWindow to the caption of the message dialog you are waiting on. The documentation isn't clear if lpszClass can be NULL or not. If not, and you don't know it, you'll have to use FindWindow() instead - but it will search all windows (not just Avidemux').

This all assumes that the message dialog's caption is meaningful (so it isn't confused with another process' windows). If not, you'll have to enumerate all the windows within each window to find out what resource items (buttons, static text, etc) are there.

If you have access to Spy++ (or non-MS equivalent), it will help you tremendously in finding out what window class, caption etc to search for.

I'd set up a Windows timer to perform the search every 5 minutes or so (or however often you feel is sufficient).

Sorry I can't help with specific Delphi (it's been a l-o-n-g time since I succumbed to the dark side and moved from Pascal to C++).

Note: a different approach would be to use Windows' process monitoring functions to monitor Avidemux' CPU usage and, when it has dropped to 0 for, say, 30 seconds, you can assume the conversion has finished. Again, I'd use a Windows timer and determine the CPU usage every so often. If you know that the only CPU-intensive process will be Avidemux, you could simply monitor the overall system CPU usage instead. (Later versions of the Windows API make it easier to get process-specific information but, typically, the Delphi support for these latest API functions is somewhat behind that found in Microsoft's compilers).

Hope this helps....
__________________
John Miller
Enosoft DV Processor - Free for personal use
JohnnyMalaria is offline   Reply With Quote
Old 4th April 2007, 23:21   #4  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Thanks

The problem is, the caption of Avidemux' main-window differs every time. It depends on the filename you process.
Furthermore the dialog window I'm waiting for has a blank caption :-(
So I will have to check for the control, which holds the text message. It's some GTK+ component I guess...


//EDIT

It looks like that:

__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 4th April 2007 at 23:27.
LoRd_MuldeR is offline   Reply With Quote
Old 5th April 2007, 03:36   #5  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
I think I found a solution:
Instead of waiting for the "Done" dialog to appear, I just wait for the "Encoding..." dialog to close.

Result can be found here:
http://forum.doom9.org/showpost.php?...&postcount=396
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote
Old 8th April 2007, 22:48   #6  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Here is a new version including sources:
http://mulder.brhack.net/public/down...2007-04-08.zip


//EDIT

And another optimization:
http://mulder.brhack.net/public/down...2007-04-09.zip
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 9th April 2007 at 00:59.
LoRd_MuldeR is offline   Reply With Quote
Old 11th April 2007, 07:14   #7  |  Link
julesh
Registered User
 
Join Date: Jan 2005
Posts: 18
Quote:
Originally Posted by LoRd_MuldeR View Post
To be more concrete: I want to monitor Avidemux until the encoding process is completed and the "Done!" message appears. Then I want shut down the computer, which is an easy task to do. Only problem is to detect the right moment for shutdown.
Why not simply change avidemux so that it can do this itself? That's the power of open source...
julesh is offline   Reply With Quote
Old 12th April 2007, 16:40   #8  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Quote:
Originally Posted by julesh View Post
Why not simply change avidemux so that it can do this itself? That's the power of open source...
Well, Mean said that those are OS specific features and because Avidemux is primarily developed for Linux, this is Low Priority work. Once it will be implemented into Avidemux, my tool will become redundant. But until then it saves some work
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 12th April 2007 at 17:04.
LoRd_MuldeR is offline   Reply With Quote
Old 12th April 2007, 21:23   #9  |  Link
masken
uhm... ?
 
Join Date: Oct 2001
Location: Gothenburg, Sweden
Posts: 281
Another option is AutoIt:
http://www.autoitscript.com/
masken is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:41.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.