www.pudn.com > QRAPPuie.rar > Carddlg.cpp
// Carddlg.cpp : implementation file // #include "stdafx.h" #include "QRAPP2.h" #include "Carddlg.h" #include#include "pimstore.h" #include "simmgr.h" #include "Picpreviewdlg.h" #include "QRAPP2Dlg.h" #include "comutil.h" #include "CappreviewDlg.h" // CCarddlg dialog IMPLEMENT_DYNAMIC(CCarddlg, CDialog) CCarddlg::CCarddlg(CWnd* pParent /*=NULL*/) : CDialog(CCarddlg::IDD, pParent) , m_szName(_T("")) , m_szTitle(_T("")) , m_szDepartment(_T("")) , m_szCompany(_T("")) , m_szTel(_T("")) , m_szTel1(_T("")) , m_szTel2(_T("")) , m_szZip(_T("")) , m_szAddress(_T("")) , m_szMobile(_T("")) , m_szMobile1(_T("")) , m_szMobile2(_T("")) , m_szFAX(_T("")) , m_szFAX1(_T("")) , m_szFAX2(_T("")) , m_szEmail(_T("")) , m_szEmail1(_T("")) , m_szEmail2(_T("")) , m_szEmail3(_T("")) , m_szUrl(_T("")) , m_szFirstname(_T("")) , m_szLastname(_T("")) { } CCarddlg::~CCarddlg() { } void CCarddlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDIT_NAME, m_ctrlName); DDX_Control(pDX, IDC_EDIT_TITLE, m_ctrlTitle); DDX_Control(pDX, IDC_EDIT_DEPARTMENT, m_ctrlDepartment); DDX_Control(pDX, IDC_EDIT_COMPANY, m_ctrlCompany); DDX_Control(pDX, IDC_EDIT_ADDRESS, m_ctrlAddress); DDX_Control(pDX, IDC_EDIT_ZIPCODE, m_ctrlZip); DDX_Control(pDX, IDC_EDIT_PHONE, m_ctrTel1); DDX_Control(pDX, IDC_EDIT_MOBILE, m_ctrlMobile1); DDX_Control(pDX, IDC_EDIT_EMAIL, m_ctrlEmail1); DDX_Control(pDX, IDC_EDIT_URL, m_ctrlUrl); DDX_Control(pDX, IDC_EDIT_FAX, m_ctrlFax1); DDX_Control(pDX, IDC_EDIT_PHONESECOND, m_ctrlTel2); DDX_Control(pDX, IDC_EDIT_MOBILESECOND, m_ctrlMobile2); DDX_Control(pDX, IDC_EDIT_FAXSECOND, m_ctrlFax2); DDX_Control(pDX, IDC_EDIT_EMAILSECOND, m_ctrlEmail2); } BEGIN_MESSAGE_MAP(CCarddlg, CDialog) ON_COMMAND(ID_OPTION_SAVETOCONTACT, &CCarddlg::OnOptionSavetocontact) ON_COMMAND(ID_OPTION_SENDSMS, &CCarddlg::OnOptionSendsms) ON_COMMAND(ID_RETURN, &CCarddlg::OnReturn) ON_COMMAND(ID_OPTION_GETQRCODE, &CCarddlg::OnOptionGetqrcode) ON_COMMAND(ID_OPTION_SAVETOFILE, &CCarddlg::OnOptionSavetofile) ON_WM_VSCROLL() ON_WM_PAINT() ON_WM_CTLCOLOR() ON_COMMAND(ID_OPTION_SAVETOSIM, &CCarddlg::OnOptionSavetosim) ON_WM_ACTIVATE() END_MESSAGE_MAP() // CCarddlg message handlers BOOL CCarddlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here if (!m_dlgCommandBar.Create(this) || !m_dlgCommandBar.InsertMenuBar(IDR_MENU_CARD)) { TRACE0("Failed to create CommandBar\n"); return FALSE; // fail to create } NameParse(m_szName.GetBuffer()); m_szName.ReleaseBuffer(); MultiPropertyParse();//multiple telnum.. m_ctrlName.SetWindowTextW(m_szName); m_ctrlTitle.SetWindowTextW(m_szTitle); m_ctrlDepartment.SetWindowTextW(m_szDepartment); m_ctrlCompany.SetWindowTextW(m_szCompany); m_ctrlZip.SetWindowTextW(m_szZip); m_ctrlAddress.SetWindowTextW(m_szAddress); m_ctrTel1.SetWindowTextW(m_szTel1); m_ctrlTel2.SetWindowTextW(m_szTel2); m_ctrlMobile1.SetWindowTextW(m_szMobile1); m_ctrlMobile2.SetWindowTextW(m_szMobile2); m_ctrlFax1.SetWindowTextW(m_szFAX1); m_ctrlFax2.SetWindowTextW(m_szFAX2); m_ctrlEmail1.SetWindowTextW(m_szEmail1); // m_ctrlEmail1.SetFocus(); if (!m_szEmail2.IsEmpty() && !m_szEmail3.IsEmpty()) { CString sEmailEditbox2 = m_szEmail2+_T(",")+m_szEmail3; m_ctrlEmail2.SetWindowTextW(sEmailEditbox2); } else { m_ctrlEmail2.SetWindowTextW(m_szEmail2); } m_ctrlUrl.SetWindowTextW(m_szUrl); m_ctrTel1.Isphonenum = TRUE; m_ctrlTel2.Isphonenum = TRUE; m_ctrlMobile1.Isphonenum = TRUE; m_ctrlMobile2.Isphonenum = TRUE; m_ctrlEmail1.Isemail = TRUE; m_ctrlEmail2.Isemail = TRUE; m_ctrlUrl.Isurl = TRUE; GetDlgItem(IDC_STATIC_APP_CARD)->SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CCarddlg::OnOptionSavetocontact() { // TODO: Add your command handler code here //TCHAR pszName[64] = {0}; m_ctrlName.GetWindowTextW(m_szName); m_ctrlTitle.GetWindowTextW(m_szTitle); m_ctrlDepartment.GetWindowTextW(m_szDepartment); m_ctrlCompany.GetWindowTextW(m_szCompany); m_ctrTel1.GetWindowTextW(m_szTel1); m_ctrlTel2.GetWindowTextW(m_szTel2); m_ctrlZip.GetWindowTextW(m_szZip); m_ctrlAddress.GetWindowTextW(m_szAddress); m_ctrlMobile1.GetWindowTextW(m_szMobile1); m_ctrlMobile2.GetWindowTextW(m_szMobile2); m_ctrlFax1.GetWindowTextW(m_szFAX1); m_ctrlFax2.GetWindowTextW(m_szFAX2); m_ctrlEmail1.GetWindowTextW(m_szEmail); m_ctrlEmail2.GetWindowTextW(m_szEmail2); m_ctrlUrl.GetWindowTextW(m_szUrl); ////////////////////////// IPOutlookApp * polApp = NULL; //Declare and initialize a pointer to the IPOutlookApp interface object IUnknown * g_pUnknown = NULL; /// BOOL bSuccess = FALSE; HRESULT hr; hr = CoInitializeEx( NULL, 0); //Initialize COM if (hr != S_OK) { AfxMessageBox(_T("添加失败!"),0,0); return; } // Get the application object hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void **)&g_pUnknown); if (hr != S_OK) { CoUninitialize(); //0111 AfxMessageBox(_T("添加失败!"),0,0); return; } hr = g_pUnknown->QueryInterface(IID_IPOutlookApp, (void**)&polApp); //Get a reference to the Outlook Mobile application interface object if (hr != S_OK) { CoUninitialize(); //0111 AfxMessageBox(_T("添加失败!"),0,0); return; } //Logon to the Outlook Mobile COM server hr = polApp->Logon(NULL); if (hr != S_OK) { polApp->Release(); CoUninitialize(); //0111 AfxMessageBox(_T("添加失败!"),0,0); // pOutApp->Release(); return; } /**********************************/ IFolder * pFolder; IPOutlookItemCollection * polItems; IContact * pContact; // Get the Contacts folder. hr = polApp->GetDefaultFolder(olFolderContacts, &pFolder); if (hr != S_OK) { polApp->Logoff(); polApp->Release(); CoUninitialize(); AfxMessageBox(_T("添加失败!"),0,0); return; } // Get the Contacts Items collection. hr = pFolder->get_Items(&polItems); if (hr != S_OK) { pFolder->Release(); polApp->Logoff(); polApp->Release(); CoUninitialize(); AfxMessageBox(_T("添加失败!"),0,0); return; } // Find Contact by FirstName LastName. TCHAR matchstr[100]; lstrcpy(matchstr,TEXT("[FirstName] = \"")); lstrcat(matchstr,m_szFirstname); lstrcat(matchstr,TEXT("\" ")); lstrcat(matchstr,TEXT("[LastName] = \"")); lstrcat(matchstr,m_szLastname); lstrcat(matchstr,TEXT("\"")); polItems->Find(matchstr, // TEXT("[FirstName] = \"宋\" [LastName] = \"绍京\"") (IDispatch**)&pContact); if (pContact!=NULL)// item that passes the restriction exists { if (AfxMessageBox(_T("联系人姓名存在 是否覆?"), MB_YESNO)==IDNO) { // Release objects. pFolder->Release(); polItems->Release(); pContact->Release(); polApp->Logoff(); polApp->Release(); CoUninitialize(); return; } } else { //to AddNewContact // Create an contact item. hr = polApp->CreateItem(olContactItem,(IDispatch **)&pContact); if (hr != S_OK) { pFolder->Release(); polItems->Release(); // pContact->Release(); polApp->Logoff(); polApp->Release(); CoUninitialize(); //0111 AfxMessageBox(_T("添加失败!"),0,0); return; } } // Set the appointment start date. /* BSTR bstrFirstName= NULL; bstrFirstName= _com_util::ConvertStringToBSTR("first name"); */ pContact->put_FirstName(m_szFirstname.AllocSysString()); //firstname lastname ,隔开 pContact->put_LastName(m_szLastname.AllocSysString()); //firstname lastname ,隔开 pContact->put_JobTitle(m_szTitle.AllocSysString()); pContact->put_Department(m_szDepartment.AllocSysString()); pContact->put_JobTitle(m_szTitle.AllocSysString()); pContact->put_CompanyName(m_szCompany.AllocSysString()); pContact->put_OfficeLocation(m_szAddress.AllocSysString()); pContact->put_BusinessAddressPostalCode(m_szZip.AllocSysString()); /*add telephone to contact phonenum1,phonenum2...*/ pContact->put_BusinessTelephoneNumber(m_szTel1.AllocSysString()); pContact->put_Business2TelephoneNumber(m_szTel2.AllocSysString()); /* add email to contact email1 email 2 email3...*/ pContact->put_Email1Address(m_szEmail1.AllocSysString()); pContact->put_Email2Address(m_szEmail2.AllocSysString()); pContact->put_Email3Address(m_szEmail3.AllocSysString()); pContact->put_MobileTelephoneNumber(m_szMobile.GetBuffer()); m_szMobile.ReleaseBuffer(); pContact->put_BusinessFaxNumber(m_szFAX1.GetBuffer()); m_szFAX.ReleaseBuffer(); pContact->put_HomeFaxNumber(m_szFAX2.AllocSysString()); pContact->put_BusinessAddressPostalCode(m_szZip.GetBuffer()); m_szZip.ReleaseBuffer(); // Add the new appointment to the appointment collection. hr = pContact->Save(); if (hr != S_OK) { AfxMessageBox(_T("添加失败!"),0,0); // pOutApp->Release(); // EndDialog(hDlg, IDCANCEL); } else { AfxMessageBox(_T("成功保存到联系人!"),0,0); } // Free resources. pFolder->Release(); polItems->Release(); pContact->Release(); //Log off and release the application object polApp->Logoff(); polApp->Release(); /// CoUninitialize(); /// } void CCarddlg::OnOptionSendsms() { // TODO: Add your command handler code here CString szSmsMessagebody; m_ctrlName.GetWindowTextW(m_szName); m_ctrlTitle.GetWindowTextW(m_szTitle); m_ctrlDepartment.GetWindowTextW(m_szDepartment); m_ctrlCompany.GetWindowTextW(m_szCompany); m_ctrTel1.GetWindowTextW(m_szTel1); m_ctrlTel2.GetWindowTextW(m_szTel2); m_ctrlZip.GetWindowTextW(m_szZip); m_ctrlAddress.GetWindowTextW(m_szAddress); m_ctrlMobile1.GetWindowTextW(m_szMobile1); m_ctrlMobile2.GetWindowTextW(m_szMobile2); m_ctrlFax1.GetWindowTextW(m_szFAX1); m_ctrlFax1.GetWindowTextW(m_szFAX2); m_ctrlEmail1.GetWindowTextW(m_szEmail1); m_ctrlEmail2.GetWindowTextW(m_szEmail2); m_ctrlUrl.GetWindowTextW(m_szUrl); //mobile if (!m_szMobile1.IsEmpty()) m_szMobile = m_szMobile1; if (!m_szMobile2.IsEmpty()) { if (!m_szMobile.IsEmpty()) { m_szMobile +=_T(","); m_szMobile +=m_szMobile2; } else { m_szMobile = m_szMobile2; } } //fax if (!m_szFAX1.IsEmpty()) m_szFAX = m_szFAX1; if (!m_szFAX2.IsEmpty()) { if (!m_szFAX.IsEmpty()) { m_szFAX += _T(","); m_szFAX += m_szFAX2; } else { m_szFAX = m_szFAX2; } } // tel if (!m_szTel1.IsEmpty()) m_szTel = m_szTel1; if (!m_szTel2.IsEmpty()) { if (!m_szTel.IsEmpty()) { m_szTel += _T(","); m_szTel += m_szTel2; } else { m_szTel = m_szTel2; } } //email if (!m_szEmail1.IsEmpty()) m_szEmail = m_szEmail1; if (!m_szEmail2.IsEmpty()) { if (!m_szEmail.IsEmpty()) { m_szEmail +=_T(","); m_szEmail +=m_szEmail2; } else { m_szEmail = m_szEmail2; } } /////////////////////////////////////////////// if (!m_szName.IsEmpty()) szSmsMessagebody = TEXT("姓名:")+m_szName; if (!m_szTitle.IsEmpty()) szSmsMessagebody+=TEXT(";职位:")+m_szTitle; if (!m_szDepartment.IsEmpty()) szSmsMessagebody+=TEXT(";部门:")+m_szDepartment; if (!m_szCompany.IsEmpty()) szSmsMessagebody+=TEXT(";公司:")+m_szCompany; if (!m_szAddress.IsEmpty()) szSmsMessagebody+=TEXT(";地址:")+m_szAddress; if (!m_szZip.IsEmpty()) szSmsMessagebody+=TEXT(";邮编;")+m_szZip; if (!m_szTel.IsEmpty()) szSmsMessagebody+=TEXT(";电话:")+m_szTel; if (!m_szMobile.IsEmpty()) szSmsMessagebody+=TEXT(";移动电话:")+m_szMobile; if (!m_szFAX.IsEmpty()) szSmsMessagebody+=TEXT(";传真:")+m_szFAX; if (!m_szEmail.IsEmpty()) szSmsMessagebody+=TEXT(";电子邮件;")+m_szEmail; if (!m_szUrl.IsEmpty()) szSmsMessagebody+=TEXT(";网址:")+m_szUrl; /* TCHAR szCmdLine[164]; lstrcpy(szCmdLine,TEXT("-service \"SMS\" -body \"" ));//messagebody\" lstrcat(szCmdLine,szSmsMessagebody); lstrcat(szCmdLine,TEXT("\"")); m_AppMenuFunc.CreateTmailProcess(szCmdLine);*/ //////////////// LPWSTR p = NULL; CString starts(TEXT("-service \"SMS\" -body \"" )); m_AppMenuFunc.AddBeforeQuotation(szSmsMessagebody,&p); CString szCmdLine = starts + p; if (p!= NULL) { delete []p; p=NULL; } szCmdLine = szCmdLine + TEXT("\""); m_AppMenuFunc.CreateTmailProcess(szCmdLine); } BOOL CCarddlg::NameParse(const TCHAR* lpszString) { ASSERT(lpszString != NULL); BOOL flag = ExistCommaChar(lpszString); if (!flag) { m_szFirstname = lpszString; m_szLastname = TEXT(""); return TRUE; } int tempvallen = lstrlen(lpszString)+1; TCHAR* first = new TCHAR[tempvallen];// firstname lasename TCHAR* last = new TCHAR[tempvallen]; ZeroMemory(first,tempvallen*sizeof(TCHAR)); ZeroMemory(last,tempvallen*sizeof(TCHAR)); int i=0; while (i 64 && *p<123) return TRUE; else return FALSE; } BOOL CCarddlg::ExistCommaChar(const TCHAR* lpszString) { ASSERT(lpszString != NULL); BOOL bResult = FALSE; int n = lstrlen(lpszString); for (int i=0; i bottom) - (rects->top)); CDialog::SetScrollRange(SB_VERT,0,110,true); //设置制定滚动条的最大和最小滚动位置 CDialog::GetScrollRange(SB_VERT,&minpos, &maxpos); //获得制定滚动条的当前最大和最小滚动位置 maxpos = CDialog::GetScrollLimit(SB_VERT);//获得滚动条的范围 //maxpos = pScrollBar->GetScrollLimit(); static int curpos = CDialog::GetScrollPos(SB_VERT);//获得滚动条当前的位置 //curaddlian=&curpos; SCROLLINFO info; switch (nSBCode) { case SB_TOP: // Scroll to far left. curpos = minpos; CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); break; case SB_BOTTOM: // Scroll to far right. curpos = maxpos; CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); break; case SB_ENDSCROLL: // End scroll. break; case SB_LINEUP: // Scroll left. if (curpos > minpos) { curpos-=10; CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); } break; case SB_LINEDOWN: // Scroll right. //if(maxpos==101){AfxMessageBox(_T("i am here"));} if (curpos < maxpos) { curpos+=10; //AfxMessageBox(_T("ok here")); CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); } //AfxMessageBox(_T("linedown")); break; case SB_PAGEUP: // Scroll one page left. // Get the page size. //pScrollBar->GetScrollInfo(&info, SIF_ALL); CDialog::GetScrollInfo(SB_VERT,&info, SIF_ALL); if (curpos > minpos) { //curpos = max(minpos, curpos - (int) info.nPage); curpos = max(minpos, curpos - 10); CDialog::ScrollWindowEx(0,10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); } break; case SB_PAGEDOWN: // Scroll one page right. //pScrollBar->GetScrollInfo(&info, SIF_ALL); CDialog::GetScrollInfo(SB_VERT,&info, SIF_ALL); if (curpos < maxpos) { curpos = min(maxpos, curpos + (int) info.nPage); curpos = min(maxpos, curpos + 10); CDialog::ScrollWindowEx(0,-10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); } break; case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position postmp1=nPos; if(curpos postmp1) { curpos = nPos; // of the scroll box at the end of the drag // operation. CDialog::ScrollWindowEx(0,10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); } break; case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is int postmp2=curpos; curpos = nPos; // position that the scroll box has been dragged // to. CDialog::ScrollWindowEx(0,postmp2-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN); CDialog::UpdateWindow(); CDialog::SetScrollPos(SB_VERT,curpos,true); break; } UpdateData(FALSE); Invalidate(); CDialog::OnVScroll(nSBCode, nPos, pScrollBar); } void CCarddlg::MultiPropertyParse(void) { //telphone1,2.. TCHAR *pTelAllstr = m_szTel.GetBuffer(); if (!ExistCommaChar(pTelAllstr)) { m_szTel.ReleaseBuffer(); m_szTel1 = m_szTel; } else { int nLen = lstrlen(pTelAllstr); TCHAR *tmpTelnum = new TCHAR[nLen+1]; ZeroMemory(tmpTelnum,sizeof(TCHAR)*(nLen+1)); TCHAR *cur = tmpTelnum; TCHAR *p = pTelAllstr; for (int i=0; i SetBkColor(RGB(206,214,255)); //背景色为白206 214 225 pDC->SetTextColor(RGB(0,0,0)); //前景色为黑 hbr = CreateSolidBrush(RGB(206,214,255)); //其它区域也为白 255,255,255 } // TODO: Return a different brush if the default is not desired return hbr; } void CCarddlg::OnOptionSavetosim() { // TODO: Add your command handler code here HRESULT hrSim; HSIM hSim; DWORD dUsed = 0; DWORD dTotal = 0; CString sNameAlreadyExists(L""); CString sAddName = m_szLastname + m_szFirstname; SIMPHONEBOOKENTRY spbe; ZeroMemory(&spbe,sizeof(SIMPHONEBOOKENTRY)); hrSim = SimInitialize(0,NULL,NULL,&hSim); if (hrSim!=S_OK) { AfxMessageBox(L"读SIM卡出错,添加失败!",0,0); return; } hrSim = SimGetPhonebookStatus(hSim,SIM_PBSTORAGE_SIM,&dUsed,&dTotal); if (dUsed ==dTotal ) { AfxMessageBox(L"SIM卡已满,添加失败!",0,0); hrSim = SimDeinitialize(hSim); return; } for (int pbEntryCount = 0;pbEntryCount