新工具条控件示例(23_UiToolBarPro)

新工具条控件

此示例展示以下控件的使用方法:

新工具条控件 UiToolBarPro 的使用流程

示例代码展示:

23_UiToolBarPro_1.png
23_UiToolBarPro_2.png
23_UiToolBarPro_3.png

使用 ImagingHelperImageContainer 加载SDK的图片资源

ImagingHelper *enableImg = m_imgContainer.LoadImage(GetMzResV2ModuleHandle(), MZRESV2_IDR_PNG_TRASH, true);
ImagingHelper *hlImg = m_imgContainer.LoadImage(GetMzResV2ModuleHandle(), MZRESV2_IDR_PNG_TRASH_HIGHLIGHT, true);
ImagingHelper *disImg = m_imgContainer.LoadImage(GetMzResV2ModuleHandle(), MZRESV2_IDR_PNG_TRASH_DISABLE, true);

初始化 UiToolBarPro 控件,设置左、右文本按钮以及中间两个图标按钮

m_ToolBar.SetID(MZ_IDC_TOOLBARPRO);
m_ToolBar.SetPos(0, GetHeight() - MZM_HEIGHT_TOOLBARPRO, GetWidth(), MZM_HEIGHT_TOOLBARPRO);
m_ToolBar.SetButton(TOOLBARPRO_LEFT_TEXTBUTTON, true, true, L"Exit");
m_ToolBar.SetButton(TOOLBARPRO_RIGHT_TEXTBUTTON, true, true, L"Disable");
m_ToolBar.SetIconButton(TOOLBARPRO_MIDDLE_ICONBUTTON1, true, true, enableImg, hlImg, disImg);
m_ToolBar.SetIconButton(TOOLBARPRO_MIDDLE_ICONBUTTON2, true, true, enableImg, hlImg, disImg);

处理右边固定文字按钮的消息,启用或禁用中间的图标按钮

if (nIndex == TOOLBARPRO_RIGHT_TEXTBUTTON)
{
    if (m_ToolBar.IsButtonEnabled(TOOLBARPRO_MIDDLE_ICONBUTTON1))
    {
        MzMessageBoxV2(m_hWnd, L"You pressed the Disable button!", MZV2_MB_OK);
        // 禁用中间的图标按钮
        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON1, false);
        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON2, false);
        m_ToolBar.SetButton(TOOLBARPRO_RIGHT_TEXTBUTTON, true, true, L"Enable");
    }
    else
    {
        MzMessageBoxV2(m_hWnd, L"You pressed the Enable button!", MZV2_MB_OK);
        // 启用中间的图标按钮
        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON1, true);
        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON2, true);
        m_ToolBar.SetButton(TOOLBARPRO_RIGHT_TEXTBUTTON, true, true, L"Disable");
    }
    return;
}

完整示例:

/************************************************************************/
/*
 * 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-03
 */
/************************************************************************/

//请按照以步骤运行此实例代码:
//首先, 打开VS2005/2008创建一个Win 32智能设备项目
//在项目向导中选择M8SDK, 并勾选空项目
//然后,在项目中新建一个cpp文件,将此处代码拷贝到cpp文件中
//最后,按照M8SDK的帮助文档,配置项目属性
//现在,可以运行此程序了

//包含MZFC库的头文件
#include <mzfc_inc.h>

//此代码演示了:
//  创建和初始化应用程序
//  创建和初始化窗体
//  窗口底部的工具条控件 UiToolBarPro 的使用及其命令消息的处理
//            弹出消息框 MzMessageBoxV2 的使用

#define MZ_IDC_TOOLBARPRO 101

// 从 CMzWndEx 派生的主窗口类
class CSampleMainWnd : public CMzWndEx
{
    MZ_DECLARE_DYNAMIC(CSampleMainWnd);
public:
    UiToolBarPro m_ToolBar;

    ImageContainer m_imgContainer;

protected:
    // 窗口的初始化
    virtual BOOL OnInitDialog()
    {
        // 必须先调用基类的初始化
        if (!CMzWndEx::OnInitDialog())
        {
            return FALSE;
        }

        ImagingHelper *enableImg = m_imgContainer.LoadImage(GetMzResV2ModuleHandle(), MZRESV2_IDR_PNG_TRASH, true);
        ImagingHelper *hlImg = m_imgContainer.LoadImage(GetMzResV2ModuleHandle(), MZRESV2_IDR_PNG_TRASH_HIGHLIGHT, true);
        ImagingHelper *disImg = m_imgContainer.LoadImage(GetMzResV2ModuleHandle(), MZRESV2_IDR_PNG_TRASH_DISABLE, true);

        // 初始化 UiToolBarPro 控件
        m_ToolBar.SetID(MZ_IDC_TOOLBARPRO);
        m_ToolBar.SetPos(0, GetHeight() - MZM_HEIGHT_TOOLBARPRO, GetWidth(), MZM_HEIGHT_TOOLBARPRO);
        m_ToolBar.SetButton(TOOLBARPRO_LEFT_TEXTBUTTON, true, true, L"Exit");
        m_ToolBar.SetButton(TOOLBARPRO_RIGHT_TEXTBUTTON, true, true, L"Disable");
        m_ToolBar.SetIconButton(TOOLBARPRO_MIDDLE_ICONBUTTON1, true, true, enableImg, hlImg, disImg);
        m_ToolBar.SetIconButton(TOOLBARPRO_MIDDLE_ICONBUTTON2, true, true, enableImg, hlImg, disImg);

        AddUiWin(&m_ToolBar);

        return TRUE;
    }

    // 重载 MZFC 的命令消息处理函数
    virtual void OnMzCommand(WPARAM wParam, LPARAM lParam)
    {
        UINT_PTR id = LOWORD(wParam);
        switch(id)
        {
        case MZ_IDC_TOOLBARPRO:
            {
                int nIndex = lParam;

                // 处理左边固定文字按键的消息,退出程序
                if (nIndex == TOOLBARPRO_LEFT_TEXTBUTTON)
                {
                    // 使用新UI消息框
                    MzMessageBoxV2(m_hWnd, L"You pressed the Exit button!", MZV2_MB_OK);
                    PostQuitMessage(0);
                    return;
                }

                // 处理中间图标按钮的消息
                if (nIndex == TOOLBARPRO_MIDDLE_ICONBUTTON1)
                {
                    // 使用新UI消息框
                    MzMessageBoxV2(m_hWnd, L"You pressed the Trash1 icon!", MZV2_MB_OK);
                    return;
                }
                if (nIndex == TOOLBARPRO_MIDDLE_ICONBUTTON2)
                {
                    MzMessageBoxV2(m_hWnd, L"You pressed the Trash2 icon!", MZV2_MB_OK);
                    return;
                }

                // 处理右边固定文字按钮的消息,启用或禁用中间的图标按钮 
                if (nIndex == TOOLBARPRO_RIGHT_TEXTBUTTON)
                {
                    if (m_ToolBar.IsButtonEnabled(TOOLBARPRO_MIDDLE_ICONBUTTON1))
                    {  
                        MzMessageBoxV2(m_hWnd, L"You pressed the Disable button!", MZV2_MB_OK);
                        // 禁用中间的图标按钮
                        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON1, false);
                        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON2, false);
                        m_ToolBar.SetButton(TOOLBARPRO_RIGHT_TEXTBUTTON, true, true, L"Enable");
                    }
                    else
                    {
                        MzMessageBoxV2(m_hWnd, L"You pressed the Enable button!", MZV2_MB_OK);
                        // 启用中间的图标按钮 
                        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON1, true);
                        m_ToolBar.EnableButton(TOOLBARPRO_MIDDLE_ICONBUTTON2, true);
                        m_ToolBar.SetButton(TOOLBARPRO_RIGHT_TEXTBUTTON, true, true, L"Disable");
                    }
                    return;
                }
            }
            break;
        }
    }
};

MZ_IMPLEMENT_DYNAMIC(CSampleMainWnd);

// 从 CMzApp 派生的应用程序类
class CSampleMainApp : public CMzApp
{
public:
    // 应用程序的主窗口
    CSampleMainWnd 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(MzGetThemeColor(TCI_WINDOW_BG));
        m_MainWnd.Show();

        // 成功则返回 TRUE
        return TRUE;
    }
};

// 全局的应用程序对象
CSampleMainApp theApp;

Generated at Tue Feb 9 15:09:54 2010 for Meizu M8 SDK Documentation by  doxygen 1.6.1