📄 simcontact.cpp
字号:
// SimContact.cpp : Defines the entry point for the application.
//
////#define WINCEOEM 1
//#include "stdafx.h"
//#include "SimContact.h"
//#include <windows.h>
//#include <commctrl.h>
//#define INITGUID
//#include "pimstore.h"
//#undef INITGUID
//#include "pimstoreEx.h"
//#include "Oleauto.h"
//
//#define PHONE_FIRST _T("1111111")
//#define PHONE_SECOND _T("2222222")
//#define PHONE_THIRD _T("3333333")
//#define PHONE_RESTRICTION_SECOND _T("[MobileTelephoneNumber] = \"2222222\"")
//#define PHONE_RESTRICTION_NOTSECOND _T("[MobileTelephoneNumber] <> \"2222222\"")
//#define PHONE_RESTRICTION_NOTTHIRD _T("[MobileTelephoneNumber] <> \"3333333\"")
//#define SIMONLY_RESTRICTION _T("[ContactType] = 1")
//#define NOSIM_RESTRICTION _T("[ContactType] <> 1")
//
//#pragma comment(lib,"coredll.lib")
//#pragma comment(lib,"ole32.lib")
//#pragma comment(lib,"Oleaut32.lib")
//#pragma comment(lib,"aygshell.lib")
//#pragma comment(lib,"phone.lib")
//#pragma comment(lib,"uuid.lib")
//
//// Helpful macros
//#define ARRAYSIZE(s) (sizeof(s) / sizeof(s[0]))
//#define RELEASE(x) if ((x) != NULL) { (x)->Release(); (x) = NULL; }
//#define _ErrorLabel Error
//#define CHRA(hResult) \
// if (FAILED(hResult)) { ASSERT(SUCCEEDED(hResult)); hr = (hResult); goto _ErrorLabel;}
//
//// Helper functions
//HRESULT ShowCollection(__in IPOutlookItemCollection * polItems, __in LPWSTR szTitle);
//HRESULT CreateContactByType(__in IPOutlookApp *polApp,
// int olItemType,
// __in BSTR szName,
// __in BSTR szTitle);
//void TRACE(
// LPTSTR lpszFormat,
// ...)
//{
// TCHAR szBuf[1024];
// if(SUCCEEDED(StringCchVPrintf((LPTSTR)szBuf, ARRAYSIZE(szBuf), lpszFormat, (LPSTR)(&lpszFormat + 1))))
// {
// OutputDebugString((LPCTSTR)szBuf);
// }
//}
//#define MAX_LOADSTRING 100
//
///////////////////////////////////////////////////////////////////////////////
//// WinMain
///////////////////////////////////////////////////////////////////////////////
//int Run()
//{
// HRESULT hr = S_OK;
// IPOutlookApp *polApp = NULL;
// IFolder * pFolder = NULL;
// IPOlItems3 * polItemsBase = NULL,
// * polItemsBase2 = NULL;
// IPOutlookItemCollection * polDefaultCollection = NULL,
// * polDefaultCollection2 = NULL,
// * polRestrictedNotSecondPhone = NULL,
// * polRestrictedOnlyFirstPhone = NULL,
// * polRestrictedSimOnly = NULL,
// * polRestrictedSecondPhone = NULL,
// * polRestrictedNoSim = NULL;
//
// // Logon to POOM
// CoInitializeEx(NULL, COINIT_MULTITHREADED);
// hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER, IID_IPOutlookApp, (LPVOID *) &polApp);
// CHRA(hr);
// ASSERT(polApp);
// hr = polApp->Logon(NULL);
// CHRA(hr);
//
// // Create 3 device contacts
// hr = CreateContactByType(polApp, olContactItem, _T("Device Contact 1"), PHONE_FIRST);
// CHRA(hr);
// hr = CreateContactByType(polApp, olContactItem, _T("Device Contact 2"), PHONE_SECOND);
// CHRA(hr);
// hr = CreateContactByType(polApp, olContactItem, _T("Device Contact 3"), PHONE_THIRD);
// CHRA(hr);
//
// // Create 2 SIM contacts
// hr = CreateContactByType(polApp, olSimContactItem, _T("Sim Contact 1"), PHONE_FIRST);
// CHRA(hr);
// hr = CreateContactByType(polApp, olSimContactItem, _T("Sim Contact 2"), PHONE_SECOND);
// CHRA(hr);
//
// // Sim contacts take a while to create and it isn't synchronous
// Sleep(10000);
//
// // Get the default contacts collection and display it - no SIM contacts
// hr = polApp->GetDefaultFolder(olFolderContacts, &pFolder);
// CHRA(hr);
// hr = pFolder->get_Items(&polDefaultCollection);
// CHRA(hr);
//
// hr = ShowCollection(polDefaultCollection, _T("Default contacts collection:"));
// CHRA(hr);
//
// // Include SIM contacts in the collection and display it - Device and SIM contacts
// hr = polDefaultCollection->QueryInterface(IID_IPOlItems3, (void**)&polItemsBase);
// CHRA(hr);
// hr = polItemsBase->IncludeSimContacts();
// CHRA(hr);
// hr = ShowCollection(polItemsBase, _T("Including SIM contacts:"));
// CHRA(hr);
//
// // Calling IncludeSimContacts again has no effect, but does not fail - same as previous
// hr = polItemsBase->IncludeSimContacts();
// CHRA(hr);
// hr = ShowCollection(polItemsBase, _T("Including SIM contacts second time:"));
// CHRA(hr);
//
// // Restrict to just the SIM contacts and display it - SIM contacts only
// hr = polItemsBase->Restrict(SIMONLY_RESTRICTION, &polRestrictedSimOnly);
// CHRA(hr);
// hr = ShowCollection(polRestrictedSimOnly, _T("Only SIM contacts:"));
// CHRA(hr);
//
// // Restrict to just the device contacts again and display it - no SIM contacts
// hr = polItemsBase->Restrict(NOSIM_RESTRICTION, &polRestrictedNoSim);
// CHRA(hr);
// hr = ShowCollection(polRestrictedNoSim, _T("No SIM contacts:"));
// CHRA(hr);
//
// // Restrict to just the 2nd contacts and display it - Only #2 contacts
// hr = polItemsBase->Restrict(PHONE_RESTRICTION_SECOND, &polRestrictedSecondPhone);
// CHRA(hr);
// hr = ShowCollection(polRestrictedSecondPhone, _T("Only contacts with the second phone number:"));
// CHRA(hr);
//
// // Restriction placed over default SIM restriction - only #1 device contact
// hr = pFolder->get_Items(&polDefaultCollection2);
// CHRA(hr);
// hr = polDefaultCollection2->Restrict(PHONE_RESTRICTION_NOTSECOND, &polRestrictedNotSecondPhone);
// CHRA(hr);
// hr = polRestrictedNotSecondPhone->Restrict(PHONE_RESTRICTION_NOTTHIRD, &polRestrictedOnlyFirstPhone);
// CHRA(hr);
// hr = ShowCollection(polRestrictedOnlyFirstPhone, _T("Only device contacts with the first phone number:"));
// CHRA(hr);
//
// // Include SIMs on already restricted set - Only #1 contacts
// hr = polRestrictedOnlyFirstPhone->QueryInterface(IID_IPOlItems3, (void**)&polItemsBase2);
// CHRA(hr);
// hr = polItemsBase2->IncludeSimContacts();
// CHRA(hr);
// hr = ShowCollection(polItemsBase2, _T("All contacts with the first phone number:"));
// CHRA(hr);
//
// // TODO: Show how SIM phone numbers are formatted upon Save
// // TODO: Show how to check for unsupported properties in a SIM contact
// // TODO: Show how property getters and setters fail for unsupported properties in SIM contact
// // TODO: Remove the contacts that were added here
//
//Error:
// RELEASE(polDefaultCollection);
// RELEASE(polDefaultCollection2);
// RELEASE(polRestrictedSimOnly);
// RELEASE(polRestrictedNoSim);
// RELEASE(polRestrictedSecondPhone);
// RELEASE(polItemsBase);
// RELEASE(pFolder);
// RELEASE(polApp);
// return !SUCCEEDED(hr);
//}
//
//
///////////////////////////////////////////////////////////////////////////////
//// Function: ShowCollection
//// polItems - In IPOlItems3 collection to display
//// szCollectionTitle - In title for the collection
///////////////////////////////////////////////////////////////////////////////
//HRESULT ShowCollection(__in IPOutlookItemCollection * polItems, __in LPWSTR szCollectionTitle)
//{
// HRESULT hr = S_OK;
// int i, cItems;
// BSTR szName = NULL, szPhone = NULL;
// IDispatch * pDispatch = NULL;
// IContact * pContact = NULL;
//
// hr = polItems->get_Count(&cItems);
// CHRA(hr);
// TRACE(_T("\nSim Contacts: %s"), szCollectionTitle);
//
// for(i = 1; i <= cItems; i++)
// {
// hr = polItems->Item(i, &pDispatch);
// CHRA(hr);
//
// hr = pDispatch->QueryInterface(IID_IContact, (void **)&pContact);
// CHRA(hr);
//
// SysFreeString(szName);
// hr = pContact->get_FirstName(&szName);
// CHRA(hr);
//
// SysFreeString(szPhone);
// hr = pContact->get_MobileTelephoneNumber(&szPhone);
// CHRA(hr);
//
// TRACE(_T("Sim Contacts: %s - %s\n"), szName, szPhone);
// RELEASE(pDispatch);
// RELEASE(pContact);
// }
//
//Error:
// RELEASE(pDispatch);
// RELEASE(pContact);
// SysFreeString(szName);
// SysFreeString(szPhone);
// return hr;
//}
//
//
///////////////////////////////////////////////////////////////////////////////
//// Function: CreateContactByType
//// polApp - In pOutlook application to use
//// olItemType - In type of contact to create (olContactItem or olSimContactItem)
//// szName - In name for the contact
//// szHomePhone - The home phone for the contact
///////////////////////////////////////////////////////////////////////////////
//HRESULT CreateContactByType(__in IPOutlookApp *polApp,
// int olItemType,
// __in BSTR szName,
// __in BSTR szHomePhone)
//{
// HRESULT hr = S_OK;
// IDispatch * pDispatch = NULL;
// IContact * pContact = NULL;
//
// hr = polApp->CreateItem(olItemType, &pDispatch);
// CHRA(hr);
//
// hr = pDispatch->QueryInterface(IID_IContact, (void **)&pContact);
// CHRA(hr);
//
// hr = pContact->put_FirstName(szName);
// CHRA(hr);
//
// hr = pContact->put_MobileTelephoneNumber(szHomePhone);
// CHRA(hr);
//
// hr = pContact->Save();
// CHRA(hr);
//
//Error:
// RELEASE(pContact);
// RELEASE(pDispatch);
// return hr;
//}
//// Global Variables:
//HINSTANCE g_hInst; // current instance
//HWND g_hWndMenuBar; // menu bar handle
//
//// Forward declarations of functions included in this code module:
//ATOM MyRegisterClass(HINSTANCE, LPTSTR);
//BOOL InitInstance(HINSTANCE, int);
//LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//#ifndef WIN32_PLATFORM_WFSP
//INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
//#endif // !WIN32_PLATFORM_WFSP
//
//int WINAPI WinMain(HINSTANCE hInstance,
// HINSTANCE hPrevInstance,
// LPTSTR lpCmdLine,
// int nCmdShow)
//{
// MSG msg;
//
// // Perform application initialization:
// if (!InitInstance(hInstance, nCmdShow))
// {
// return FALSE;
// }
//
//#ifndef WIN32_PLATFORM_WFSP
// HACCEL hAccelTable;
// hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SIMCONTACT));
//#endif // !WIN32_PLATFORM_WFSP
//
// // Main message loop:
// while (GetMessage(&msg, NULL, 0, 0))
// {
//#ifndef WIN32_PLATFORM_WFSP
// if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
//#endif // !WIN32_PLATFORM_WFSP
// {
// TranslateMessage(&msg);
// DispatchMessage(&msg);
// }
// }
//
// return (int) msg.wParam;
//}
//
////
//// FUNCTION: MyRegisterClass()
////
//// PURPOSE: Registers the window class.
////
//// COMMENTS:
////
//ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
//{
// WNDCLASS wc;
//
// wc.style = CS_HREDRAW | CS_VREDRAW;
// wc.lpfnWndProc = WndProc;
// wc.cbClsExtra = 0;
// wc.cbWndExtra = 0;
// wc.hInstance = hInstance;
// wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SIMCONTACT));
// wc.hCursor = 0;
// wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
// wc.lpszMenuName = 0;
// wc.lpszClassName = szWindowClass;
//
// return RegisterClass(&wc);
//}
//
////
//// FUNCTION: InitInstance(HINSTANCE, int)
////
//// PURPOSE: Saves instance handle and creates main window
////
//// COMMENTS:
////
//// In this function, we save the instance handle in a global variable and
//// create and display the main program window.
////
//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
//{
// HWND hWnd;
// TCHAR szTitle[MAX_LOADSTRING]; // title bar text
// TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
//
// g_hInst = hInstance; // Store instance handle in our global variable
//
//#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// // SHInitExtraControls should be called once during your application's initialization to initialize any
// // of the device specific controls such as CAPEDIT and SIPPREF.
// SHInitExtraControls();
//#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
//
// LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
// LoadString(hInstance, IDC_SIMCONTACT, szWindowClass, MAX_LOADSTRING);
//
//#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// //If it is already running, then focus on the window, and exit
// hWnd = FindWindow(szWindowClass, szTitle);
// if (hWnd)
// {
// // set focus to foremost child window
// // The "| 0x00000001" is used to bring any owned windows to the foreground and
// // activate them.
// SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
// return 0;
// }
//#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
//
// if (!MyRegisterClass(hInstance, szWindowClass))
// {
// return FALSE;
// }
//
// hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
// CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
//
// if (!hWnd)
// {
// return FALSE;
// }
//
//#ifdef WIN32_PLATFORM_PSPC
// // When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// // is created is not taken into account). So we resize the window after creating it
// // if a menubar is present
// if (g_hWndMenuBar)
// {
// RECT rc;
// RECT rcMenuBar;
//
// GetWindowRect(hWnd, &rc);
// GetWindowRect(g_hWndMenuBar, &rcMenuBar);
// rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
//
// MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
// }
//#endif // WIN32_PLATFORM_PSPC
//
// ShowWindow(hWnd, nCmdShow);
// UpdateWindow(hWnd);
//
//
// return TRUE;
//}
//
////
//// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
////
//// PURPOSE: Processes messages for the main window.
////
//// WM_COMMAND - process the application menu
//// WM_PAINT - Paint the main window
//// WM_DESTROY - post a quit message and return
////
////
//LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -