Focus on a Toolstrip instead of a window.
Here is the routine in question:
Set p1 = Sys.Process("Viewer")
Call p1.frmMain.StripMainMenu.Click("File|Print Preview")
p1.WinFormsObject("PrintPreviewDialog", "Print preview").SetFocus
Set w1 = p1.WinFormsObject("PrintPreviewDialog", "Print preview").WinFormsObject("toolStrip1")
'p1.WinFormsObject("PrintPreviewDialog", "Print preview").SetFocus
The line remmed out was replaced with the one below it.
Here is what was happening. If I run this routine by itself, it works fine. When run the whole project, the next routine saw that the PrintPreviewDialog window was still open.
I can't figure out why setting focus to the toolbar would make a difference?
Re: Focus on a Toolstrip instead of a window.
This seems strange, setting focus to the toolbar shouldn't make any difference. Moreover, if you did not even set focus to the window, the ClickItem action should have worked correctly. Perhaps, there's something specific about this dialog (some implementation peculiarities).
How is the dialog implemented in your application?