Discussion:
Programmatically clicking an OK button - win32
(too old to reply)
Matthew Miller
2012-09-14 14:28:17 UTC
Permalink
Raw Message
Hi,

I'm working on an application to detect a pop-up dialog and then
automatically dismiss it. I'm writing this as a C++/Win32 app. The
dialog box is generated by IE 7 and I can detect the window, but
several methods to get the OK button to "click" have failed.

Doing searches for other people's solutions, sending these messages to
the button handle seems to have worked in a lot of situations:

PostMessage( handle, WM_LBUTTONDOWN, 0, 0 )
PostMessage( handle, WM_LBUTTONUP, 0, 0 )
PostMessage( handle, BM_SETSTATE, 1, 0 )

It has no effect on the button state in my tests though.

I can send tab characters to the main window and see that the OK
button gets focus, but then sending return characters does nothing.

To learn more about this I used Spy++ to get information about the
window hierarchy and what messages are delievered when I manually
click the OK button.

Looking at the message log and reading about WM_MOUSEACTIVATE seamed
to offer a solution. The log info shows that 0002166C was the button
window. So in my code I tried this:

GetClassNameA( handle, str, str_size );

if( strcmp( str, "Internet Explorer_Server" ) != 0 )
return TRUE; // Not the window we're interested in.

// Send a message to activate the button window and have it process a mouse click.
PostMessage( handle, WM_MOUSEACTIVATE, (WPARAM) dialog_handle, MAKELPARAM( HTCLIENT, WM_LBUTTONDOWN );

Based on the window hierarchy and message log, I think the window with
the class name "Internet Explorer_Server" is the button. Maybe I'm
wrong, because it does seem like an odd class name for a button...

Below is a link to the window hierarchy image, message log when I
manually click the OK button. Last is the code that's executed on a 1
second timer ticket, looking for the window.

Any insight and help is appreciated!


Image of the window hierarchy:
Loading Image...

Message log when manually clicking the OK button:
<00001> 0002166C S WM_NCHITTEST xPos:348 yPos:262
<00002> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00003> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00004> 000215D0 S SB_ISSIMPLE
<00005> 000215D0 R SB_ISSIMPLE fSimple:False
<00006> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00007> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:170 yPos:62
<00008> 000215D0 S SB_ISSIMPLE
<00009> 000215D0 R SB_ISSIMPLE fSimple:False
<00010> 0002166C S WM_NCHITTEST xPos:347 yPos:262
<00011> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00012> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00013> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00014> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:169 yPos:62
<00015> 0002166C S WM_NCHITTEST xPos:346 yPos:262
<00016> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00017> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00018> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00019> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:168 yPos:62
<00020> 0002166C S WM_NCHITTEST xPos:344 yPos:262
<00021> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00022> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00023> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00024> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:166 yPos:62
<00025> 0002166C S WM_NCHITTEST xPos:343 yPos:262
<00026> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00027> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00028> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00029> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:165 yPos:62
<00030> 0002166C S WM_NCHITTEST xPos:340 yPos:262
<00031> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00032> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00033> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00034> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:162 yPos:62
<00035> 000215D0 S SB_ISSIMPLE
<00036> 000215D0 R SB_ISSIMPLE fSimple:False
<00037> 000215D0 S SB_ISSIMPLE
<00038> 000215D0 R SB_ISSIMPLE fSimple:False
<00039> 0002166C P WM_PAINT hdc:00000000
<00040> 0002166C S WM_NCHITTEST xPos:338 yPos:262
<00041> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00042> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00043> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00044> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:160 yPos:62
<00045> 0002166C S WM_NCHITTEST xPos:337 yPos:262
<00046> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00047> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00048> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00049> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:159 yPos:62
<00050> 0002166C S WM_NCHITTEST xPos:337 yPos:262
<00051> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00052> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00053> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00054> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:159 yPos:62
<00055> 0002166C S WM_NCHITTEST xPos:336 yPos:262
<00056> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00057> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00058> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00059> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:158 yPos:62
<00060> 0002166C S WM_NCHITTEST xPos:334 yPos:262
<00061> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00062> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00063> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00064> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:156 yPos:62
<00065> 0002166C S WM_NCHITTEST xPos:334 yPos:264
<00066> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00067> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00068> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00069> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:156 yPos:64
<00070> 0002166C S WM_NCHITTEST xPos:333 yPos:264
<00071> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00072> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00073> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00074> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:155 yPos:64
<00075> 0002166C S WM_NCHITTEST xPos:332 yPos:264
<00076> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00077> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00078> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00079> 0002166C P WM_MOUSEMOVE fwKeys:0000 xPos:154 yPos:64
<00080> 0002166C S WM_NCHITTEST xPos:332 yPos:264
<00081> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00082> 0002166C S WM_NCHITTEST xPos:332 yPos:264
<00083> 0002166C R WM_NCHITTEST nHittest:HTCLIENT
<00084> 000415C8 S WM_PARENTNOTIFY fwEvent:WM_LBUTTONDOWN xPos:154 yPos:64
<00085> 000415C8 R WM_PARENTNOTIFY
<00086> 000215B8 S WM_PARENTNOTIFY fwEvent:WM_LBUTTONDOWN xPos:154 yPos:64
<00087> 000215B8 R WM_PARENTNOTIFY
<00088> 001E0E8E S WM_PARENTNOTIFY fwEvent:WM_LBUTTONDOWN xPos:154 yPos:64
<00089> 001E0E8E R WM_PARENTNOTIFY
<00090> 0002166C S WM_MOUSEACTIVATE hwndTopLevel:001E0E8E nHittest:HTCLIENT uMsg:WM_LBUTTONDOWN
<00091> 000415C8 S WM_MOUSEACTIVATE hwndTopLevel:001E0E8E nHittest:HTCLIENT uMsg:WM_LBUTTONDOWN
<00092> 000215B8 S WM_MOUSEACTIVATE hwndTopLevel:001E0E8E nHittest:HTCLIENT uMsg:WM_LBUTTONDOWN
<00093> 001E0E8E S WM_MOUSEACTIVATE hwndTopLevel:001E0E8E nHittest:HTCLIENT uMsg:WM_LBUTTONDOWN
<00094> 001E0E8E R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE
<00095> 000215B8 R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE
<00096> 000415C8 R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE
<00097> 0002166C R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE
<00098> 001E0E8E S WM_WINDOWPOSCHANGING lpwp:0E7FEE00
<00099> 001E0E8E R WM_WINDOWPOSCHANGING
<00100> 001E0E8E S WM_SYNCPAINT
<00101> 001E0E8E S WM_NCPAINT hrgn:00000001
<00102> 001E0E8E S WM_GETTEXT cchTextMax:510 lpszText:0E7FE100
<00103> 001E0E8E R WM_GETTEXT cchCopied:118 lpszText:0E7FE100 ("T")
<00104> 001E0E8E R WM_NCPAINT
<00105> 001E0E8E S WM_ERASEBKGND hdc:CC01256D
<00106> 001E0E8E R WM_ERASEBKGND fErased:True
<00107> 001E0E8E R WM_SYNCPAINT
<00108> 001E0E8E P WM_PAINT hdc:00000000
<00109> 001E0E8E S WM_WINDOWPOSCHANGED lpwp:0E7FEE00
<00110> 001E0E8E R WM_WINDOWPOSCHANGED
<00111> 001E0E8E S WM_ACTIVATEAPP fActive:True dwThreadID:00000000
<00112> 001E0E8E R WM_ACTIVATEAPP
<00113> 001E0E8E S WM_NCACTIVATE fActive:True
<00114> 00031586 S message:0x041F [User-defined:WM_USER+31] wParam:00000086 lParam:00000001
<00115> 000215C6 S message:0x041F [User-defined:WM_USER+31] wParam:00000086 lParam:00000001
<00116> 000215C6 R message:0x041F [User-defined:WM_USER+31] lResult:00000000
<00117> 00031578 S message:0x041F [User-defined:WM_USER+31] wParam:00000086 lParam:00000001
<00118> 0004157E S CCM_SETWINDOWTHEME pwStr:0E7FE260
<00119> 0004157E S WM_THEMECHANGED
<00120> 0004157E R WM_THEMECHANGED
<00121> 00071574 S WM_THEMECHANGED
<00122> 00071574 S WM_WINDOWPOSCHANGING lpwp:0E7FD5A0
<00123> 00071574 R WM_WINDOWPOSCHANGING
<00124> 00071574 R WM_THEMECHANGED
<00125> 0003159A S WM_THEMECHANGED
<00126> 0003159A R WM_THEMECHANGED
<00127> 0004157E R CCM_SETWINDOWTHEME
<00128> 000315A4 S CCM_SETWINDOWTHEME pwStr:0E7FE058
<00129> 000315A4 S WM_THEMECHANGED
<00130> 00031578 S WM_NOTIFY idCtrl:0 pnmh:0E7FD638
<00131> 000315A4 S TB_SETBUTTONSIZE dxButton:26 dyButton:25
<00132> 000315A4 R TB_SETBUTTONSIZE fSucceeded:True
<00133> 000315A4 S TB_SETPADDING cx:4 cy:0
<00134> 000315A4 R TB_SETPADDING cxPrev:4 cyPrev:0
<00135> 00031578 R WM_NOTIFY
<00136> 000315A4 R WM_THEMECHANGED
<00137> 000315A4 R CCM_SETWINDOWTHEME
<00138> 000315A4 S TB_SETBUTTONINFOW iID:103 lptbbi:0E7FDF78
<00139> 000315A4 R TB_SETBUTTONINFOW fSucceeded:True
<00140> 000315A4 S TB_SETBUTTONINFOW iID:100 lptbbi:0E7FDF78
<00141> 000315A4 R TB_SETBUTTONINFOW fSucceeded:True
<00142> 000315A4 S TB_SETBUTTONINFOW iID:102 lptbbi:0E7FDF78
<00143> 000315A4 R TB_SETBUTTONINFOW fSucceeded:True
<00144> 000315A4 S TB_SETBUTTONINFOW iID:101 lptbbi:0E7FDF78
<00145> 000315A4 R TB_SETBUTTONINFOW fSucceeded:True
<00146> 000315A4 S TB_SETBUTTONINFOW iID:202 lptbbi:0E7FDF78
<00147> 000315A4 R TB_SETBUTTONINFOW fSucceeded:True
<00148> 000315A4 S TB_GETMAXSIZE lpSize:0E7FDFF4
<00149> 000315A4 R TB_GETMAXSIZE
<00150> 000315A4 S TB_SETBUTTONSIZE dxButton:26 dyButton:25
<00151> 000315A4 R TB_SETBUTTONSIZE fSucceeded:True
<00152> 000315A4 S TB_SETPADDING cx:4 cy:0
<00153> 000315A4 R TB_SETPADDING cxPrev:4 cyPrev:0
<00154> 000315A4 S WM_WINDOWPOSCHANGING lpwp:0E7FDF60
<00155> 000315A4 R WM_WINDOWPOSCHANGING
<00156> 0004157E S WM_WINDOWPOSCHANGING lpwp:0E7FDFD4
<00157> 0004157E R WM_WINDOWPOSCHANGING
<00158> 0003157A S RB_IDTOINDEX uBandID:1
<00159> 0003157A R RB_IDTOINDEX iIndex:1
<00160> 0003157A S RB_GETBANDINFOW uBand:1 lprbbi:0E7FDF50
<00161> 0003157A R RB_GETBANDINFOW fSucceeded:True
<00162> 0003157A S RB_IDTOINDEX uBandID:1
<00163> 0003157A R RB_IDTOINDEX iIndex:1
<00164> 0003157A S RB_GETBANDINFOW uBand:1 lprbbi:0E7FDEF4
<00165> 0003157A R RB_GETBANDINFOW fSucceeded:True
<00166> 0003157A S RB_SETBANDINFOW uBand:1 lprbbi:0E7FDEF4
<00167> 0003157A R RB_SETBANDINFOW fSucceeded:True
<00168> 0003157A S RB_GETBANDCOUNT
<00169> 0003157A R RB_GETBANDCOUNT iCount:3
<00170> 0003157A S RB_GETBARHEIGHT
<00171> 0003157A R RB_GETBARHEIGHT cyHeight:32
<00172> 00031578 R message:0x041F [User-defined:WM_USER+31] lResult:00000000
<00173> 000215B0 S message:0x041F [User-defined:WM_USER+31] wParam:00000086 lParam:00000001
<00174> 000415A8 S message:0x041F [User-defined:WM_USER+31] wParam:00000086 lParam:00000001
<00175> 000315AE S EM_SETMARGINS fwMargin:EC_LEFTMARGIN | EC_RIGHTMARGIN | EC_USEFONTINFO wLeft:0 wRight:0
<00176> 000315AE R EM_SETMARGINS
<00177> 000315AE S WM_SHOWWINDOW fShow:False fuStatus:0 (ShowWindow was called)
<00178> 000315AE R WM_SHOWWINDOW
<00179> 000315AE S WM_WINDOWPOSCHANGING lpwp:0E7FDFC0
<00180> 000315AE R WM_WINDOWPOSCHANGING
<00181> 000315AE S WM_CHILDACTIVATE
<00182> 000315AE R WM_CHILDACTIVATE
<00183> 000315AE S WM_SHOWWINDOW fShow:True fuStatus:0 (ShowWindow was called)
<00184> 000315AE R WM_SHOWWINDOW
<00185> 000415AA S WM_WINDOWPOSCHANGING lpwp:0E7FDFC0
<00186> 000415AA R WM_WINDOWPOSCHANGING
<00187> 000415AA S WM_CHILDACTIVATE
<00188> 000415AA R WM_CHILDACTIVATE
<00189> 000215B4 S TB_SETEXTENDEDSTYLE dwExStyle:TBSTYLE_EX_DOUBLEBUFFER
<00190> 000215B4 R TB_SETEXTENDEDSTYLE dwPrevStyle:TBSTYLE_EX_DOUBLEBUFFER
<00191> 000415A8 R message:0x041F [User-defined:WM_USER+31] lResult:00000000
<00192> 000215B0 R message:0x041F [User-defined:WM_USER+31] lResult:00000000
<00193> 0003157A S CCM_SETWINDOWTHEME pwStr:3E1D6BA8
<00194> 0003157A S WM_THEMECHANGED
<00195> 0003157A R WM_THEMECHANGED
<00196> 0003157A R CCM_SETWINDOWTHEME
<00197> 0003157A S WM_WINDOWPOSCHANGING lpwp:0E7FE7F8
<00198> 0003157A R WM_WINDOWPOSCHANGING
<00199> 00031586 S WM_WINDOWPOSCHANGING lpwp:0E7FE7F8
<00200> 00031586 R WM_WINDOWPOSCHANGING
<00201> 000215B8 S WM_WINDOWPOSCHANGING lpwp:0E8FFEC4
<00202> 000215B8 R WM_WINDOWPOSCHANGING
<00203> 00051588 S WM_WINDOWPOSCHANGING lpwp:0E7FE664
<00204> 00051588 R WM_WINDOWPOSCHANGING
<00205> 000215B8 S WM_WINDOWPOSCHANGING lpwp:0E8FFEC4
<00206> 000215B8 R WM_WINDOWPOSCHANGING
<00207> 00051588 S WM_WINDOWPOSCHANGING lpwp:0E7FE704
<00208> 00051588 R WM_WINDOWPOSCHANGING
<00209> 000215B8 S WM_WINDOWPOSCHANGING lpwp:0E8FFEC4
<00210> 000215B8 R WM_WINDOWPOSCHANGING
<00211> 00051588 S WM_WINDOWPOSCHANGING lpwp:0E7FE6F4
<00212> 00051588 R WM_WINDOWPOSCHANGING
<00213> 000215B8 S WM_WINDOWPOSCHANGING lpwp:0E8FFEC4
<00214> 000215B8 R WM_WINDOWPOSCHANGING
<00215> 00051588 S WM_WINDOWPOSCHANGING lpwp:0E7FE794
<00216> 00051588 R WM_WINDOWPOSCHANGING
<00217> 00031586 R message:0x041F [User-defined:WM_USER+31] lResult:00000000
<00218> 001E0E8E R WM_NCACTIVATE
<00219> 001E0E8E S WM_ACTIVATE fActive:WA_CLICKACTIVE fMinimized:False hwndPrevious:(null)
<00220> 00031586 S message:0x0427 [User-defined:WM_USER+39] wParam:00000002 lParam:00000000
<00221> 00031578 S message:0x0427 [User-defined:WM_USER+39] wParam:00000002 lParam:00000000
<00222> 00031578 R message:0x0427 [User-defined:WM_USER+39] lResult:00000000
<00223> 00031586 R message:0x0427 [User-defined:WM_USER+39] lResult:00000000
<00224> 0002166C S WM_IME_SETCONTEXT fSet:1 (LONG)iShow:C000000F
<00225> 0002166C S WM_IME_NOTIFY dwCommand:00000002 dwData:00000000
<00226> 0002166C R WM_IME_NOTIFY
<00227> 0002166C R WM_IME_SETCONTEXT
<00228> 0002166C S WM_SETFOCUS hwndLoseFocus:(null)
<00229> 0002166C R WM_SETFOCUS
<00230> 001E0E8E R WM_ACTIVATE
<00231> 0002166C S WM_SETCURSOR hwnd:0002166C nHittest:HTCLIENT wMouseMsg:WM_LBUTTONDOWN
<00232> 0002166C R WM_SETCURSOR fHaltProcessing:False
<00233> 0002166C P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:154 yPos:64
<00234> 000215B8 P message:0x0428 [User-defined:WM_USER+40] wParam:00000000 lParam:00000000
<00235> 000215B8 P message:0x0422 [User-defined:WM_USER+34] wParam:00000002 lParam:00000000
<00236> 000215B8 P WM_PAINT hdc:00000000
<00237> 000215B8 S WM_NCPAINT hrgn:8E04284A
<00238> 000215B8 R WM_NCPAINT
<00239> 000415C8 P WM_PAINT hdc:00000000
<00240> 000415C8 S WM_NCPAINT hrgn:9104284A
<00241> 000415C8 R WM_NCPAINT
<00242> 000215B8 P WM_CLOSE
<00243> 001E0E8E P message:0x049F [User-defined:WM_USER+159] wParam:00001D68 lParam:000016A8
<00244> 000215B8 S WM_PARENTNOTIFY fwEvent:WM_DESTROY idChild:A001 (40961) hwndChild:000215D0
<00245> 000215B8 R WM_PARENTNOTIFY
<00246> 001E0E8E S WM_PARENTNOTIFY fwEvent:WM_DESTROY idChild:0000 (0) hwndChild:000215D8
<00247> 001E0E8E R WM_PARENTNOTIFY
<00248> 000215B8 S WM_PARENTNOTIFY fwEvent:WM_DESTROY idChild:0000 (0) hwndChild:000415C8
<00249> 000215B8 R WM_PARENTNOTIFY
<00250> 001E0E8E S WM_PARENTNOTIFY fwEvent:WM_DESTROY idChild:0000 (0) hwndChild:000215B8
<00251> 001E0E8E R WM_PARENTNOTIFY
<00252> 001E0E8E S WM_NCHITTEST xPos:332 yPos:264
<00253> 001E0E8E R WM_NCHITTEST nHittest:HTCLIENT
<00254> 001E0E8E S WM_SETCURSOR hwnd:001E0E8E nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00255> 001E0E8E R WM_SETCURSOR fHaltProcessing:False
<00256> 001E0E8E P WM_MOUSEMOVE fwKeys:0000 xPos:154 yPos:64
<00257> 001E0E8E P WM_PAINT hdc:00000000
<00258> 001E0E8E S WM_ERASEBKGND hdc:520123C6
<00259> 001E0E8E R WM_ERASEBKGND fErased:True
<00260> 001E0E8E S WM_NCHITTEST xPos:332 yPos:264
<00261> 001E0E8E R WM_NCHITTEST nHittest:HTCLIENT
<00262> 001E0E8E S WM_SETCURSOR hwnd:001E0E8E nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00263> 001E0E8E R WM_SETCURSOR fHaltProcessing:False
<00264> 001E0E8E P WM_MOUSEMOVE fwKeys:0000 xPos:154 yPos:64
<00265> 001E0E8E P message:0x0497 [User-defined:WM_USER+151] wParam:00001D68 lParam:00000000
<00266> 001E0E8E P message:0x0465 [User-defined:WM_USER+101] wParam:00000000 lParam:00000000
<00267> 0003157A S WM_SETREDRAW fRedraw:False
<00268> 0003157A R WM_SETREDRAW
<00269> 0003157A S RB_GETBANDCOUNT
<00270> 0003157A R RB_GETBANDCOUNT iCount:3
<00271> 001E0E8E S WM_PARENTNOTIFY fwEvent:WM_DESTROY idChild:0000 (0) hwndChild:00031586
<00272> 001E0E8E R WM_PARENTNOTIFY
<00273> 001E0E8E S WM_WINDOWPOSCHANGING lpwp:0E7FEAE4
<00274> 001E0E8E R WM_WINDOWPOSCHANGING
<00275> 001E0E8E S WM_WINDOWPOSCHANGED lpwp:0E7FEAE4
<00276> 001E0E8E R WM_WINDOWPOSCHANGED
<00277> 001E0E8E S WM_DESTROY
<00278> 001E0E8E R WM_DESTROY
<00279> 001E0E8E S WM_NCDESTROY
<00280> 001E0E8E S WM_SETICON fType:True hicon:00000000
<00281> 001E0E8E R WM_SETICON hPrevIcon:0002106D
<00282> 001E0E8E S WM_SETICON fType:False hicon:00000000
<00283> 001E0E8E R WM_SETICON hPrevIcon:001A1057
<00284> 001E0E8E R WM_NCDESTROY


// Code:


case WM_TIMER:

hwin = FindWindow( NULL, TEXT("Timeout Warning. Click OK to not end the session. - Windows Internet Explorer") );

if( hwin != NULL ) {

dialog_handle = hwin; // Save the handle for the call back function.

SetForegroundWindow( hwin ); // Bring the dialog forward and give it focus.

// Send a TAB to focus the button.
scan = MapVirtualKey( VK_TAB, MAPVK_VK_TO_VSC ); // Build the generic lparam to be used for WM_KEYDOWN/WM_KEYUP/WM_CHAR
tab_lparam = 0x00000001 | (LPARAM)(scan << 16); // Scan code, repeat=1
scan = MapVirtualKey( VK_RETURN, MAPVK_VK_TO_VSC ); // Build the generic lparam to be used for WM_KEYDOWN/WM_KEYUP/WM_CHAR
ret_lparam = 0x00000001 | (LPARAM)(scan << 16); // Scan code, repeat=1

PostMessage( hwin, WM_KEYDOWN, VK_TAB, 0x000f0001 );
PostMessage( hwin, WM_KEYUP, VK_TAB, 0xc00f0001 );

// Send mouse click messages to every handle.
EnumChildWindows( hwin, SendMouseClicks, 0 );
}

break;




BOOL CALLBACK SendMouseClicks(HWND handle, LPARAM lp ) {

const int str_size = 200;
char str[str_size];

GetClassNameA( handle, str, str_size );

if( strcmp( str, "Internet Explorer_Server" ) != 0 )
return TRUE; // Not the window we're interested in.

// Send a message to activate the button window and have it process a mouse click.
PostMessage( handle, WM_MOUSEACTIVATE, (WPARAM) dialog_handle, MAKELPARAM( HTCLIENT, WM_LBUTTONDOWN );

PostMessage( handle, WM_LBUTTONDOWN, 0, 0 );
PostMessage( handle, WM_LBUTTONUP, 0, 0 );
PostMessage( handle, BM_SETSTATE, 1, 0 );
return TRUE;
}
Deanna Earley
2012-09-14 15:11:11 UTC
Permalink
Raw Message
Post by Matthew Miller
Hi,
I'm working on an application to detect a pop-up dialog and then
automatically dismiss it. I'm writing this as a C++/Win32 app. The
dialog box is generated by IE 7 and I can detect the window, but
several methods to get the OK button to "click" have failed.
Bear in mind that most dialogs like this are explicitly asking for user
approval and go to great lengths to stop it being automated.
--
Deanna Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
Matthew Miller
2012-09-14 16:01:14 UTC
Permalink
Raw Message
Post by Deanna Earley
Bear in mind that most dialogs like this are explicitly asking for user
approval and go to great lengths to stop it being automated.
Understood. :) In this case, I've got a test dialog I can display (it's only an HTML form with a button) and it seems identical to the one presented by the actual application dialog. Spy++ shows the same window hierarchy and I get the same behavior with both test and actual dialogs.

Best regards.

Matthew
Charles Calvert
2012-10-11 01:44:25 UTC
Permalink
Raw Message
On Fri, 14 Sep 2012 07:28:17 -0700 (PDT), Matthew Miller
Post by Matthew Miller
I'm working on an application to detect a pop-up dialog and then
automatically dismiss it. I'm writing this as a C++/Win32 app. The
dialog box is generated by IE 7 and I can detect the window, but
several methods to get the OK button to "click" have failed.
Doing searches for other people's solutions, sending these messages to
PostMessage( handle, WM_LBUTTONDOWN, 0, 0 )
PostMessage( handle, WM_LBUTTONUP, 0, 0 )
PostMessage( handle, BM_SETSTATE, 1, 0 )
Try WM_CLICK instead.

[snip rest]
--
Charles Calvert | Websites
Celtic Wolf, Inc. | Web Applications
http://www.celticwolf.com/ | Software
(703) 580-0210 | Databases
Loading...