I want to write a convenient front-end to the old and ugly Win95 application. I nailed the problem to this:
Invoke the target executable;
Wait for application window to appear;
Wait for message box (i hope it is a message box) to appear;
Trigger an onClick event for the "OK" button of the message box;
Wait for the application to exit.
1st and 5th items are easy, it is just the System.Diagnostics.ProcessStartInfo stuff; but i have no idea where to start with the rest of items. How could it be done?
Take a look at the windows automation framework, this is a good starter codeproject.com/Articles/141842/
Sorry for the delay.
If it's not too much of an effort you could open up the executable in a disassembler (like ollydbg) and simply NOP the call to the messagebox. Then from C# you could simply wait for the process to exit instead of dismissing the messagebox using code.
Related
I want to properly close any application (not kill) running in system tray. I have tried SendKeys() but it fails. Sending Alt+F4, Alt+F then x all fail because tray applications have no main window. Any idea how to do that? the objective to to properly exit an application that performs some inner tasks upon exiting, running in system tray without terminating, just like when its titlebar exit button is clicked.
There is no simple answer to this. Each and every application has its own way of controlling life time. You can even write Forms application that does not respond to [Alt F4] to shut it down.
The only way you can an arbitrary process of which you know nothing (other than that it has put an icon into the system tray), is to terminate the process. And that, as Gian Paolo pointed out, is just not cricket.
From what you have written on the comments on the other answers, it sounds like you merely want to close a specific app. You can do this with the taskkill utility.
When a button is clicked in my form application all other controls are frozen,but if the process is time consuming I want to use a button to exit the application. How can I achieve this? Since all buttons are frozen.
You may try the BackgroundWorker. You can run the process without affecting the responsiveness of the UI. Moreover, you may cancel the process.
Referring to the example in the link, put your process logic is in backgroundWorker1_DoWork method, just follow the comment in the sample source code.
How can I show a dialog message, similar to MessageBox, which have just the "Cancel" button and can be closed by the application.
The idea is to show the dialog while the application retrieves data from a server, allowing the user to cancel this request, and closing the dialog once the request is completed.
I recall having a very similar problem in the past. I don't think there is a dialog message "out of the box" that works like that. The way I solved this was by writing a class that modeled this sort of behavior in a window and having the application spawn an instance of the window.
The silverlight message box blocks code execution while it is open so it is not possible to close it. However you can use an XNA messagebox in Silverlight which is asynchronous
This explains its use in depth
You can probably then call EndShowMessageBox for your purposes.
if your intention is to let the user know that something is loading and that they should wait. you should use a progressbar instead.
How to: Create a Custom Indeterminate Progress Bar
I'm starting a external application with System.Diagnostics.Process, this external process at one moment opens up a dialog where user has type something and then click OK. What i need is to wait with my application(the one where i started the external process) until the user has inserted something and clicked OK. After that OK i have to do some more task on that external process and then close it.
Yes, it's possible. There are a number of ways to get window information starting with a process handle and/or ID. See this question and responses for getting started. You will most likely end up using P/Invoke to the Win32 API to get this accomplished but there are dozens of good examples for getting this done.
Once you have the window handle you can use a timer polling scheme to test for the presence, or in your case, presence and then the disappearance of a window.
This is possible but there are some work behind it. First you need to run your code as unmanaged code as you will need to hook on Windows OS events with the Win32 API.
So an option would be to have a loop looking for the dialog to open, pause what ever your code are doing and continue when the dialog are gone.
If the application you are starting exists after the user interacts with the dialog, then you can just call Process.WaitFroExit() and your code will not continue until the process you started has quit.
There are quite a few helpful functions for interacting with processes in the System.Diagnostics.Process class (that I assume you are using to start this external application)
I have an game application I have written for Windows Mobile and I want to have a timer associated with the puzzle. If the program loses focus for any reason (call comes in, user switches programs, user hits the Windows button) then I want a pop up dialog box to cover the puzzle and the timer to stop. When the user closes the pop up dialog the timer can start up again.
Does anyone know how to do this?
Thanks
Take a look at the article over at OpenNETCF's Community site on determining when a Form or Process changes.
A quick way would be to use PInvoke to call GetForegroundWindow() and GetWindowText() whenever your timer ticks (once a second?).
GetForegroundWindow() returns a windows handle which you can use to call GetWindowText(). If the text of the foreground window matches your form's Text property (its caption), you know your app has the focus. You can then show or hide your puzzle in each timer tick.