We have documents automation program on our server which written by 3rd
party developer, it works ok except that sometimes give error with OK button
and waits for user response,
If this happens, program stop working and someone must connect to server and
click OK manually.
While I can't solve problem which leads to message box directly in software
I came to idea to build small utility which check for form caption(message
box is simple form, right)
and if such message box caption exists programically click on button.
I have found how to find out message box handler by title, but how to click
on OK button in that message box(form)?
As I understand I need to iterate though all controls and somehow compare
and if OK caption exists I should execute "click" action. I don't know how
to do that and any suggestion would be welcome.
function FindWindowByTitle(WindowTitle: string): Hwnd;
NextTitle: array[0..260] of char;
// Get the first window
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
// retrieve its text
GetWindowText(NextHandle, NextTitle, 255);
if Pos(lowercase(WindowTitle), lowercase(StrPas(NextTitle))) <> 0 then
Result := NextHandle;
// Get the next window
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
Result := 0;