Re: How to write the scripts for Unexpected ActiveWindow
That depends on what you want to do with the unexpected active window. If you look in the Robot Gui Playback options, there are several settings made available for handling unexpected active windows. You can specify what action you want for unexpected active windows via these settings.. i.e. 'press button with focus', send 'esc', send any character... you can even tell Robot to ignore them if your heart desires. Remember, these settings are global.
If you want to handle an unexpected active window a certain way, i.e. click the OK button specifically, for example, I would recommend creating a function which suspends log output, checks for the window, and if present, clicks the OK button; if not, resume log output, and move on. Obviously, setting this through the Gui settings is much simpler. If you have a complex set of actions you need to perform on the unexpected active window, then a function is the better option.
You would have to know the window caption and button text ahead of time, of course. Also, you would constantly be checking for the window.
If you know when the window is going to pop up, i.e. input is incorrect and an error dialog pops up, you could just include the check there, and write some log output if the window is present.