I'm writing a C program under Windows that should send an ENTER key to a dialog box to close it automatically.
I retrieve the handle to the top level window I'm interested in (by means of EnumDesktopWindows()) and then try to send an ENTER key using SendMessage (note also that closing the window by sending WM_CLOSE works fine).
None of the following works:
SendMessage( hTargetWindow, WM_CHAR, VK_RETURN, 0 );
SendMessage( hTargetWindow, WM_CHAR, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYDOWN, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYUP, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYDOWN, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_CHAR, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYUP, VK_RETURN, 1 );
and so on...
As a possibly simpler scenario, I also tried to send an ascii key to, say, notepad.
How is this supposed to work?
Thanks in advance