最近也在搞这个outlook的接口,给段代码请参考下。另外楼主问题解决了吧?想看看答案,也许对我有帮助 void CFcarDeverDlg::OnBnClickedButtonSend() { // Start Outlook. // If it is already running, you'll use the same instance... _Application olApp; COleException e; if(!olApp.CreateDispatch("Outlook.Application", &e)) { CString str; str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc); AfxMessageBox(str, MB_SETFOREGROUND); return; } // Logon. Doesn't hurt if you are already running and logged on... NameSpace olNs(olApp.GetNamespace("MAPI")); COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); olNs.Logon(covOptional, covOptional, covOptional, covOptional); // Create and open a new contact _ContactItem olItem(olApp.CreateItem(2)); // Setup Contact information... olItem.SetFullName("James Smith"); COleDateTime bdDate; bdDate.SetDate(1975, 9, 15); olItem.SetBirthday(bdDate); olItem.SetCompanyName("Microsoft"); olItem.SetHomeTelephoneNumber("704-555-8888"); olItem.SetEmail1Address("[email protected]"); olItem.SetJobTitle("Developer"); olItem.SetHomeAddress("111 Main St.\nCharlotte, NC 28226"); // Save Contact olItem.Save(); // Create a new appointment _AppointmentItem olAppt(olApp.CreateItem(1)); // Schedule it for two minutes from now... COleDateTime apptDate = COleDateTime::GetCurrentTime(); olAppt.SetStart((DATE)apptDate + DATE(2.0/(24.0*60.0))); // Set other appointment info... olAppt.SetDuration(60); olAppt.SetSubject("Meeting to discuss plans..."); olAppt.SetBody("Meeting with James to discuss plans."); olAppt.SetLocation("Home Office"); olAppt.SetReminderMinutesBeforeStart(1); olAppt.SetReminderSet(TRUE); // Save Appointment olAppt.Save(); // Prepare a new mail message _MailItem olMail(olApp.CreateItem(0)); olMail.SetTo("[email protected]"); olMail.SetSubject("About our meeting..."); olMail.SetBody( "Hi James,\n\n" "\tI'll see you in two minutes for our meeting!\n\n" "Btw: I've added you to my contact list!"); // Send the message! olMail.Send(); AfxMessageBox("All done.", MB_SETFOREGROUND); olNs.Logoff(); }
果真不支持,HWND par_Hwnd, chi_Hwnd;
par_Hwnd = ::FindWindowEx(NULL,NULL,"ATH_Note",NULL);
if( par_Hwnd == NULL )
::AfxMessageBox("找不到OutLook新邮件窗口");
chi_Hwnd=::FindWindowEx(par_Hwnd,NULL,"RichEdit20W",NULL);
if( chi_Hwnd == NULL )
::AfxMessageBox("找不到窗口");
DWORD err=::GetLastError();找不到,我尝试了窗口上的所有 直接子窗口,都找不到的
“收件人”编辑域又属于一个class为“OE_Envelope”的窗口中,而这个窗口为“新邮件”主窗口的直接子窗口,修改代码如下: HWND par_Hwnd, chi_Hwnd,chi_chi_Hwnd;
par_Hwnd = ::FindWindowEx(NULL,NULL,"ATH_Note",NULL);
if( par_Hwnd == NULL )
::AfxMessageBox("找不到OutLook新邮件窗口");
chi_Hwnd=::FindWindowEx(par_Hwnd,NULL,"OE_Envelope",NULL);
if( chi_Hwnd == NULL )
::AfxMessageBox("找不到窗口");
DWORD err=::GetLastError(); chi_chi_Hwnd = ::FindWindowEx(chi_Hwnd,NULL,"RichEdit20W",NULL);
if( chi_chi_Hwnd == NULL )
::AfxMessageBox("找不到窗口");
DWORD er=::GetLastError();
可以获得(但我发现调试的信息值和用AccExplorer工具取得的值 有两个不连续的位 值不同)顺便问一下,调试信息中的句柄值后面有{unused =????}表示什么意思?如何通过窗口句柄获取窗口中的文本值?莫非还要通过它的句柄求它的IAccessible接口?
也就是WM_GETTEXT
至于unused看看这个吧
http://xylvhp.blog.163.com/blog/static/3112361420091193318642/
不行,我在工程对话框中加一个EDIT控件IDC_EDIT1,接上述代码:CWnd *pWnd=GetDlgItem(IDC_EDIT1);
HWND hOutPutWnd = pWnd->GetSafeHwnd();
char szText[100]={0};
::SendMessage(chi_chi_Hwnd,WM_GETTEXT,100,(LPARAM)szText);
::SendMessage(hOutPutWnd,WM_SETTEXT,0,(LPARAM)szText);这样调试的时候szText为空,工程对话框中窗口的IDC_EDIT1控件自然也为空于是我就用GetWindowText函数来取: char* Text=new char();
int TextLength=0;
int i;
TextLength=::GetWindowTextLength(chi_chi_Hwnd);
i=::GetWindowText(chi_chi_Hwnd,Text,TextLength);
CString Value;
Value.Format("%s",Text);
::AfxMessageBox(Value);结果i=0,但句柄不为空,控件中也有测试文本,为啥i的值为0呢?
您是说要用钩子之类的东西?
我不用SendMessage,直接用GetWindowText不就可以不用代码注入了嘛?
所以常规操作第三方软件都是对方软件提供接口
一般都是com接口
也就是你用的IAccessible
一般是处理GET_MESSAGE吧
具体其实我也没做过
HWND hWndMainWindow,hWnd;
hWndMainWindow =::FindWindowEx(NULL,NULL,"#32770","运行");
hWnd =::FindWindowEx(hWndMainWindow,NULL,"ComboBox",NULL);//文本编辑窗口又在一个Class为ComboBox的子窗口中
EnumChildWindows(hWnd,EnumWndProc,0);
枚举函数:BOOL WINAPI EnumWndProc(HWND hwnd,LPARAM lParam)
{
IAccessible *paccWindow = NULL;
VARIANT varChild;
char szObjName[256];
BSTR tmp;
CString value;
HRESULT hr;
if( hwnd )
{
if(S_OK == (hr = AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, IID_IAccessible,(void**)&paccWindow)))
{
::AfxMessageBox("取得IAccessible接口成功!");
VariantInit(&varChild);
varChild.vt = VT_I4;
varChild.lVal = CHILDID_SELF;
if(paccWindow->get_accName(varChild,&tmp) == S_OK)
{
::AfxMessageBox("取Name值成功!");
name=tmp;
::AfxMessageBox(name);
} if( !strcmp( name,_T("打开(O)") ) )
{
::AfxMessageBox("找到‘打开’文本域!");
if(paccWindow->get_accValue(varChild,&tmp)==S_OK) {
::AfxMessageBox("取值成功!");
value=tmp;
::AfxMessageBox(value);
}
}
}
}
return TRUE;
}
然而,程序可以取出Name,却取不出Value,不知道
VariantInit(&varChild);
varChild.vt = VT_I4;
varChild.lVal = CHILDID_SELF;这两句有没有问题,但是,既然能够取出Name,就也应该取出Value啊!!! 做测试时
HRESULT hrr = paccWindow->get_accValue(varChild,&tmp2);
if(FAILED(hrr))
{
::AfxMessageBox("取Value值失败!");
DWORD err=::GetLastError();
}
会执行::AfxMessageBox("取Value值失败!");这一句,但是err的值却始终是0!!!咋回事呢?
高手们给看一下
void CFcarDeverDlg::OnBnClickedButtonSend()
{
// Start Outlook.
// If it is already running, you'll use the same instance...
_Application olApp;
COleException e;
if(!olApp.CreateDispatch("Outlook.Application", &e)) {
CString str;
str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
AfxMessageBox(str, MB_SETFOREGROUND);
return;
} // Logon. Doesn't hurt if you are already running and logged on...
NameSpace olNs(olApp.GetNamespace("MAPI"));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional); // Create and open a new contact
_ContactItem olItem(olApp.CreateItem(2)); // Setup Contact information...
olItem.SetFullName("James Smith");
COleDateTime bdDate;
bdDate.SetDate(1975, 9, 15);
olItem.SetBirthday(bdDate);
olItem.SetCompanyName("Microsoft");
olItem.SetHomeTelephoneNumber("704-555-8888");
olItem.SetEmail1Address("[email protected]");
olItem.SetJobTitle("Developer");
olItem.SetHomeAddress("111 Main St.\nCharlotte, NC 28226"); // Save Contact
olItem.Save(); // Create a new appointment
_AppointmentItem olAppt(olApp.CreateItem(1)); // Schedule it for two minutes from now...
COleDateTime apptDate = COleDateTime::GetCurrentTime();
olAppt.SetStart((DATE)apptDate + DATE(2.0/(24.0*60.0))); // Set other appointment info...
olAppt.SetDuration(60);
olAppt.SetSubject("Meeting to discuss plans..."); olAppt.SetBody("Meeting with James to discuss plans.");
olAppt.SetLocation("Home Office");
olAppt.SetReminderMinutesBeforeStart(1);
olAppt.SetReminderSet(TRUE); // Save Appointment
olAppt.Save(); // Prepare a new mail message
_MailItem olMail(olApp.CreateItem(0));
olMail.SetTo("[email protected]");
olMail.SetSubject("About our meeting...");
olMail.SetBody(
"Hi James,\n\n"
"\tI'll see you in two minutes for our meeting!\n\n"
"Btw: I've added you to my contact list!"); // Send the message!
olMail.Send(); AfxMessageBox("All done.", MB_SETFOREGROUND);
olNs.Logoff();
}