为什么sendmessage和postmessage到outlook对话框失败了 [英] Why sendmessage and postmessage to outlook dialog failed

查看:174
本文介绍了为什么sendmessage和postmessage到outlook对话框失败了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载每日报告并自动删除Outlook中的邮件。但总会弹出一个对话框警告:程序正在尝试访问您存储在Outlook中的电子邮件地址....。与 http://www.brighthub.com/computing/windows-platform/articles/32410相同.aspx [ ^ ]

所以我尝试使用多线程将CLICK消息发布到对话框上的OK Button控件以关闭对话框窗口。 Thread1用于访问outlook应用程序,而thread2使用Findwindow API来获取对话框窗口的句柄,然后找到复选框控件的句柄和OK按钮控件。

句柄都被正确收集(与SPY ++相同),sendmessage在复选框上工作,但sendmessage和postmessge都不能单击OK按钮,postmessage返回-1。

通过逐步调试,有时候postmessage工作,有时根本不工作。



任何回复的人都会非常感激。

我的API声明和调用代码如下:



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:

 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)

推荐答案

按钮命令是通常使用带有按钮ID的wParam作为WM_COMMAND发送。
Button commands are usually sent as WM_COMMAND with the wParam with the button ID.


由于您将WM_COMMAND命令发布到按钮而不是对话框,因此它无效e按钮在。



您需要了解按钮将其按钮ID发布到包含它的窗口,而lParam应该是按钮的句柄。目前也发布消息



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



现在我不知道在VB上对api的GetParent调用是什么样的,所以我会在C中编写你需要的东西转换它

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


这篇关于为什么sendmessage和postmessage到outlook对话框失败了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆