PDA

View Full Version : Opening - Monitoring External Windows


Intrinsic
03-31-2005, 08:29 PM
I have attached an example of a method to:


Browse for a file
Get the selected files default viewer
Launch and monitor the opening of the default viewer
Get the window handle of the default viewer
Hide the AMS window
Set the title text of the default viewer
Monitor the closing of that default viewer window
Show the AMS window


The application does an initial check after opening the selected file and runs a function to monitor if the files viewer is open checking every 1/2 second then hides the AMS application

If the default viewer isn't in the table of enumerated processes (slow opening) then it waits 5 seconds and further checks if the window has been opened.

On opening the files default viewer it changes the window title text (A prompt to close the window to return to the AMS application)

On closing the default viewer window the AMS window shows

I am sure many users could appreciate having such an example, (I know that I would have) please feel free to correct any code, error handling as you see fit.

Hope this is useful to many users!

csd214
04-01-2005, 04:34 AM
Intrinsic, THANKS!

I find your function very valuable. Your post/project should be moved the Examples section. :yes

The only "problem" I noticed is that the file browse dialog is flickering when I start it the second time. I'm not able to use the combo box ("Look in:"), but I resolved this by adding Page.StopTimer() as the first command in Button.On Click.

Previously I have used a while loop to enumerate windows, but your solution is nicer (but have to keep track of several On Timer functions).

-- wait for system to open the file
local bHandleFound = false; local nRescueCounter = 0; local sHelpHandle;
while not bHandleFound and nRescueCounter <= 60 do
nRescueCounter = nRescueCounter + 1; -- avoid an infinitive loop!
sHelpHandle = Get_hWind(sTitle)
-- a user defined function with Window.EnumerateTitles()
if sHelpHandle then
Window.SetOrder(sHelpHandle, HWND_BOTTOM);
bHandleFound = true;
else
Application.Sleep(500); -- wait 5/10 sec
end
end


I'll try to extend your function with restriction to the top level folder.

Thanks for sharing! :)