Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to download the daily report and delete the mail in outlook automaticly. But there always popups a dialogbox warning:"A program is trying to access e-mail addresses you have stored in Outlook....". the same to http://www.brighthub.com/computing/windows-platform/articles/32410.aspx[^]
So I try to use multithreading to post a CLICK message to the OK Button control on the dialogbox to close the dialogbox window. Thread1 to access the outlook application,while thread2 use Findwindow API to get the handle of the dialogbox window, then find the handle of the checkbox control and the OK button control.
the handles are all correctly collected(the same as SPY++),the sendmessage works on the checkbox,But neither sendmessage nor postmessge can make a click on the OK button, postmessage returns -1.
By using step by step debug,Sometimes the postmessage works,sometimes not at all.

Anybody replied will be greatly appreciated.
My API declaration and calling code are following:

VB
 dllimport("user32.dll",> _
    Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
    End Function

.....
PostMessage(btn_hwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
Posted
Updated 4-Aug-14 22:05pm
v4

Button commands are usually sent as WM_COMMAND with the wParam with the button ID.
 
Share this answer
 
Comments
marshell_w 5-Aug-14 4:06am    
Dear boer:
For the dialogbox window is created by outlook, I get the button ID with SPY++ and Convert to decimal 4774. Then I use the code:

Public Const WM_COMMAND As Integer = &H111
.....
PostMessage(btn_hwnd, WM_COMMAND, 4774, IntPtr.Zero) it still does not work, but seems the Button is focused. can you give me some example?

I turned back to test the other buttons,such as the HELP button, use the following:
PostMessage(btn_HELP_hwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
PostMessage(btn_HELP_hwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero)

It works,the window is closed and the help window opened.

Does the allow(or OK) button is blocked by microsoft or the Multithreading?
And when I use the FindWindowEX, it just cannot get the controls by the caption or classname on the microsoft outlook dialogbox window. So I have to turn to the enumwindows.

It's really driving me mad.
It's not working because you are posting the WM_COMMAND command to the button not the dialog the button is in.

You need to understand a button posts it's button ID to the window containing it and the lParam should be the handle to the button the handle you are currently posting the message too

http://msdn.microsoft.com/en-us/library/windows/desktop/ms647591%28v=vs.85%29.aspx[^]

Now I dont know what the call to GetParent on the the api looks like in VB but so I will write what you need in C convert it
PostMessage(GetParent(btn_HELP_hwnd), WM_COMMAND, 4777, (LPARAM) btn_HELP_hwnd);

So I am posting the message to the parent of the button and filling in all the parameters as required to meet the call requirement
 
Share this answer
 
Comments
marshell_w 6-Aug-14 21:48pm    
Dear boer:
Thanks a lot. I think that's the problem, I am trying to get through it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900