UiCustomList自由定义数据的扩展列表控件
此示例展示以下控件的使用方法:
列表控件UiCustomList使用流程
UiCustomList m_list;
//定义列表子项对象 IItemCollection* pItemColl = new IItemCollection; //省略pItemColl的各项参数的设置 //详细参见UiCustomList.h //添加子项到列表项 m_list.SetCustomItemCollection(pItemColl);
示例代码展示:
从 IItemCollection 派生的自定义数据集
class IItemCollection_S : public IItemCollection{...}
初始化 UiCustomList 控件
m_list.SetPos(0, 0, 480, GetHeight() - MZM_HEIGHT_TEXT_TOOLBAR); m_list.SetID(MZ_IDC_CUSTOMLIST); m_list.EnableGridlines(true); m_list.EnableDragModeH(true); m_list.SetItemAttribute(UILISTEX_ITEMTYPE_PHONE); m_list.EnableUltraGridlines(true); m_list.UpdateItemAttribute_Del(); m_list.SetSplitLineMode(UILISTEX_SPLITLINE_LEFT); m_list.EnablePressedHoldSupport(true); m_list.EnableScrollBarV(true); AddUiWin(&m_list);
把自定义数据集IItemCollection_S加载到UiCustomList列表控件
IItemCollection_S* pItemColl = new IItemCollection_S; m_list.SetCustomItemCollection(pItemColl);
完整示例:
/************************************************************************/ /* * Copyright (C) Meizu Technology Corporation Zhuhai China * All rights reserved. * 中国珠海, 魅族科技有限公司, 版权所有. * * This file is a part of the Meizu Foundation Classes library. * Author: * Create on: 2009-12-26 */ /************************************************************************/ //请按照以步骤运行此实例代码: //首先, 打开VS2005/2008创建一个Win 32智能设备项目 //在项目向导中选择M8SDK, 并勾选空项目 //然后,在项目中新建一个cpp文件,将此处代码拷贝到cpp文件中 //最后,按照M8SDK的帮助文档,配置项目属性 //现在,可以运行此程序了 // 包含MZFC库的头文件 #include <mzfc_inc.h> #include "resource.h" //此代码演示了: // 创建和初始化应用程序 // 创建和初始化窗体 // 使用 UiCustomList 自由定义数据的扩展列表控件 #define MZ_IDC_CUSTOMLIST 104 #define MZ_IDC_TOOLBAR 105 // 从 IItemCollection 派生的自定义数据类 class IItemCollection_S : public IItemCollection { public: virtual ImagingHelper* GetImageFirst(int nIndex) { ImagingHelper* pImg = m_container.LoadImage(MzGetInstanceHandle(), IDR_PNG_SMS_LIST_READ, true); return pImg; } virtual ImagingHelper* GetImageSecond(int nIndex) { ImagingHelper* pImg = NULL; return pImg; } virtual ImagingHelper* GetImageFirst_Pressed(int nIndex) { return NULL; } virtual ImagingHelper* GetImageSecond_Pressed(int nIndex) { ImagingHelper* pImg = NULL; return pImg; } virtual CMzString GetTitle(int nIndex) { CMzString str(20); wsprintf(str,L"标题Title:%d",nIndex); return str; } virtual CMzString GetDescription(int nIndex) { CMzString str(50); wsprintf(str,L"Description:%d",nIndex); return str; } virtual CMzString GetPostscript1(int nIndex) { CMzString str(50); str = L"05月13日"; return str; } virtual CMzString GetPostscript2(int nIndex) { CMzString str(20); str = L"1次响铃"; return str; } virtual int GetItemCount() { return 10; } virtual void SetMultiSelect(int nIndex,bool isSelect) { return; } virtual bool IsEnableDragDelete(int nIndex) { return false; } virtual bool IsMultiSelected(int nIndex) { return true; } virtual int GetItemHeight(int nIndex) { return 60; } virtual void SetItemHeight(int nIndex,int height) { return; } virtual void RemoveItem(int nIndex) { return; } virtual DrawItemFun GetDrawItemFunPointer(int nIndex) { return NULL; } virtual void UpdateItemAttribute(int nIndex,__inout ItemAttribute& itemAttr,void* pData) { UiCustomList* pList = (UiCustomList*)pData; //改变字体的颜色 if (nIndex == 5) { itemAttr.m_tpDescription.m_fontColor = RGB(255, 50, 20); } } private: ImageContainer m_container; }; // 从 CMzWndEx 派生的窗口类 class CustomList_MainWnd : public CMzWndEx { MZ_DECLARE_DYNAMIC(CustomList_MainWnd); UiCustomList m_list; UiToolBarPro m_toolbar; protected: // 窗口初始化 virtual BOOL OnInitDialog() { // 必须先调用基类的初始化 if (!CMzWndEx::OnInitDialog()) { return FALSE; } // 初始化 UiToolBarPro 控件 m_toolbar.SetID(MZ_IDC_TOOLBAR); m_toolbar.SetPos(0, GetHeight()-MZM_HEIGHT_TEXT_TOOLBAR, 480, MZM_HEIGHT_TEXT_TOOLBAR); m_toolbar.SetButton(TOOLBARPRO_LEFT_TEXTBUTTON, true, true, L"Exit"); AddUiWin(&m_toolbar); // 初始化 UiCustomList 控件 m_list.SetPos(0, 0, 480, GetHeight() - MZM_HEIGHT_TEXT_TOOLBAR); m_list.SetID(MZ_IDC_CUSTOMLIST); m_list.EnableGridlines(true); m_list.EnableDragModeH(true); m_list.SetItemAttribute(UILISTEX_ITEMTYPE_PHONE); m_list.EnableUltraGridlines(true); m_list.UpdateItemAttribute_Del(); m_list.SetSplitLineMode(UILISTEX_SPLITLINE_LEFT); m_list.EnablePressedHoldSupport(true); m_list.EnableScrollBarV(true); AddUiWin(&m_list); IItemCollection_S* pItemColl = new IItemCollection_S; m_list.SetCustomItemCollection(pItemColl); return TRUE; } // 重载 MZFC 的命令消息处理函数 virtual void OnMzCommand(WPARAM wParam, LPARAM lParam) { UINT_PTR id = LOWORD(wParam); switch(id) { case MZ_IDC_TOOLBAR: // 点击了按钮控件 { int index = lParam; switch(index) { case TOOLBARPRO_LEFT_TEXTBUTTON: { PostQuitMessage(0); break; } } break; } } } }; MZ_IMPLEMENT_DYNAMIC(CustomList_MainWnd) // 从 CMzApp 派生的应用程序类 class CSampleApp : public CMzApp { public: // 应用程序的主窗口 CustomList_MainWnd m_MainWnd; // 初始化应用程序 virtual BOOL Init() { // 初始化 COM 组件 CoInitializeEx(0, COINIT_MULTITHREADED); // 创建窗口 RECT rcWork = MzGetWorkArea(); m_MainWnd.Create(rcWork.left,rcWork.top,RECT_WIDTH(rcWork),RECT_HEIGHT(rcWork), 0, 0, 0); //m_MainWnd.SetBgColor(RGB(254,249,220)); m_MainWnd.Show(); return TRUE; } }; // 全局应用程序变量 CSampleApp theApp;