CommonDialog示例(17_CommonDialog)

CommonDialog

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

示例代码展示:

17_CommonDialog1.png
17_CommonDialog2.png

完整示例:

/************************************************************************/
/*
* Copyright (C) Meizu Technology Corporation Zhuhai China
* All rights reserved.
* 中国珠海, 魅族科技有限公司, 版权所有.
*
* This file is a part of the Meizu Foundation Classes library.
* Author:    ZYK
* Create on: 2009-06-26
*/
/************************************************************************/

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

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

//此代码演示了:
//  创建和初始化应用程序
//  创建和初始化窗体
//  按钮控件的使用及其命令消息的处理
//  按钮控件的ID
//  MzCommonDlg中的4个Dialog

#define MZ_IDC_InfoTipBTN        101
#define MZ_IDC_BeginWaitDlgBTN   102
#define MZ_IDC_MessageBoxExBTN   103
#define Timer_ID                 10

// 从 CMzWndEx 派生的主窗口类
class CSample1MainWnd: public CMzWndEx
{
  MZ_DECLARE_DYNAMIC(CSample1MainWnd);
public:
  UiButton m_btn1;
  UiButton m_btn2;
  UiButton m_btn3;
  
protected:
  // 窗口的初始化
  virtual BOOL OnInitDialog()
  {
    // 必须先调用基类的初始化
    if (!CMzWndEx::OnInitDialog())
    {
      return FALSE;
    }
  
    m_btn1.SetButtonType(MZC_BUTTON_GREEN);
    m_btn1.SetID(MZ_IDC_MessageBoxExBTN);
    m_btn1.SetPos(100, 50, 280, 100);
    m_btn1.SetText(L"MessageBoxEx");

    AddUiWin(&m_btn1);

     m_btn2.SetButtonType(MZC_BUTTON_ORANGE);
     m_btn2.SetID(MZ_IDC_InfoTipBTN);
     m_btn2.SetPos(100, 250, 280, 100);
     m_btn2.SetText(L"InfoTip");
 
    AddUiWin(&m_btn2);

    m_btn3.SetButtonType(MZC_BUTTON_GRAY);
    m_btn3.SetID(MZ_IDC_BeginWaitDlgBTN);
    m_btn3.SetPos(110, 450, 260, 100);
    m_btn3.SetText(L"WaitDialog");

    AddUiWin(&m_btn3);

    //自动弹出消息提示,3秒后关闭,默认时间为2秒
  MzAutoMsgBoxEx(m_hWnd, L"MzCommonDlg Sample  This is an AutoMsgBox", 3000);

    return TRUE;
  }

  // 重载命令消息的处理函数
  virtual void OnMzCommand(WPARAM wParam, LPARAM lParam)
  {
    UINT_PTR id = LOWORD(wParam);
    switch(id)
    {
    
    case MZ_IDC_MessageBoxExBTN:
      {
        //显示MessageBox
          MzMessageBoxEx(m_hWnd, L"This is a MessageBox", L"MessageBox");
      }
      break;
    case MZ_IDC_InfoTipBTN:
      {
        //设置InofTip的位置,只能修改纵坐标的位置
        POINT point;
        point.y = 200;

        //显示InfoTip,默认显示时间为两秒
        MzInfoTip(m_hWnd, L"This is an InfoTip", point);
      }
      break;
     case MZ_IDC_BeginWaitDlgBTN:
       {
        //设置定时器,3秒后关闭WaitDialog
        SetTimer(m_hWnd, Timer_ID, 3000, NULL);

        //启动WaitDialog
        MzBeginWaitDlg(m_hWnd, NULL, true);
       }
      break;
    }
  }

  virtual void OnTimer(UINT_PTR nIDEvent)
  {
    switch(nIDEvent)
    {
    case Timer_ID:
      {
      //结束WaitDialog
        MzEndWaitDlg();
      }
      break;
    }
  }
};

MZ_IMPLEMENT_DYNAMIC(CSample1MainWnd)

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

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

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


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