WINDOSW MOBILE CODE 之AddContactPicture

来源:互联网 发布:php lastmodified 编辑:程序博客网 时间:2024/05/17 04:49

HRESULT SelectContact(IItem **ppItem) //这个函数的参数类型是IItem ,公有继承于IUnknown接口
{
    HRESULT         hr = S_OK;
    CHOOSECONTACT   cc = {0};
    const CEPROPID  c_propidAllEmail = PIMPR_ALL_EMAIL;

    CBR(NULL != ppItem);

    // Setup the CHOOSECONTACT structure.
    cc.cbSize       = sizeof (cc);
    cc.dwFlags      = CCF_DEFAULT | CCF_CHOOSECONTACTONLY;
    cc.hwndOwner    = NULL;

    // Display the Contact Chooser control and prompt the user to choose a contact.
    hr = ChooseContact(&cc);    //在该处调用了选择联系人的函数
    CHR(hr);

    // Get the IItem from the OID for the selected contact       
    hr = g_pPoom->GetItemFromOidEx(cc.oidContactID, 0, ppItem);
    CHR(hr);
    CBR(NULL != *ppItem);

Error:
    return hr;   
}

 

在上述的代码中,调用到了系统的函数是ChooseContact。这个函数的只有一个参数。这个参数的类型是CHOOSECONTACT结构体。

下面来详细看一下这个结构体。

typedef struct {

UINT cbSize;//这个机构的大小
HWND
hwndOwner;//联系人窗口的句柄(可为NULL)
DWORD dwFlags;//作为初始化联系人标志位
LPCWSTR lpstrTitle;
LPCWSTR lpstrChoosePropertyText;
LPCWSTR lpstrRestrictContacts;
LPCWSTR lpstrIncrementalFilter;
UINT cRequiredProperties;
const CEPROPID * rgpropidRequiredProperties;
CEOID oidContactID;
BSTR bstrContactName;
CEPROPID propidSelected;
BSTR bstrPropertyValueSelected;
} CHOOSECONTACT, *LPCHOOSECONTACT;
在该例子中仅仅使用到了这个结构体的前三个参数。可根据要求增加使用其它参数。

这个函数的使用环境是:

Pocket PC:

    Windows Mobile Version 5.0 and later.

Smartphone:

Windows Mobile Version 5.0 and later.

OS Versions:

Windows CE 5.01 and later.

Header:

         pimstore.h

Library:       
 pimstore.dll

HRESULT SelectPicture(LPTSTR pszPictureFile, DWORD dwBufferSize)

{

    HRESULT         hr      = S_OK;

    OPENFILENAMEEX  ofnex   = {0};

    BOOL            bResult = FALSE;

    CBR(NULL != pszPictureFile);
    // Setup the Picture picker structure

    ofnex.lStructSize   = sizeof(ofnex);

    ofnex.ExFlags       = OFN_EXFLAG_THUMBNAILVIEW;   

    ofnex.lpstrFile     = new TCHAR[MAX_PATH];

    ofnex.nMaxFile      = MAX_PATH;

    CBR(NULL != ofnex.lpstrFile);
    // Call the Picture picker UI. Lets the user select a pic.

    bResult = GetOpenFileNameEx(&ofnex);//此处调用了GetOpenFileNameEx函数,用来打开一个指定路径的文件

    CBR(bResult);

    // Copies the picture to the buffer passed in.

    hr = StringCchCopy(pszPictureFile, dwBufferSize, ofnex.lpstrFile);

    CHR(hr);

Error:

    delete[] ofnex.lpstrFile;

    return hr;   

}

在程序中还调用了GetOpenFileNameEx函数。这个函数的作用是:创建一个系统样式的对话框,显示了网格图,使用户可以选择已经存在的图片或视频。这个函数使用了参数类型是OPENFILENAMEEX结构体。这个结构体中参数包含了打开文件的名字和路径。在这个示例程序中还有一个很重要的方面是:这个程序中调用了COM的接口,所以在程序最初使用CoInitializeEx函数对COM进行初始化。使用CoCreateInstance函数创建一个COM对象。
在程序结束之前,要使用CoUninitialize函数对COM接口进行注销。



原创粉丝点击