UiButton_Gradient按钮控件示例(15_UiButton_Gradient)

UiButton_Gradient 按钮控件

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

渐变按钮控件UiButton_Gradient的使用流程

示例代码展示:

15_UiButton_Gradient1.png
15_UiButton_Gradient2.png
15_UiButton_Gradient3.png

设置按钮渐变颜色:

  //GradientButtonColor结构体 定义UiButton_Gradient颜色
  GradientButtonColor btncolor1;
  
  btncolor1.cr1 = RGB(10, 10, 10);
  btncolor1.cr2 = RGB(40, 40, 40);
  btncolor1.cr3 = RGB(90, 90, 90);
  btncolor1.cr4 = RGB(150, 150, 150);

  m_btn2.SetGradientColor(btncolor2);

完整示例:

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

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

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

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

// UiButton_Gradient按钮控件的ID
#define MZ_IDC_TESTBTN1  101
#define MZ_IDC_TESTBTN2  102

//GradientButtonColor结构体 定义UiButton_Gradient颜色
GradientButtonColor btncolor1;
GradientButtonColor btncolor2;

// 从 CMzWndEx 派生的主窗口类
class CSample1MainWnd: public CMzWndEx
{
  MZ_DECLARE_DYNAMIC(CSample1MainWnd);
public:
  // 窗口中的UiButton_Gradient控件
  UiButton_Gradient m_btn1;
  UiButton_Gradient m_btn2;
protected:
  // 窗口的初始化
  virtual BOOL OnInitDialog()
  {
    // 必须先调用基类的初始化
    if (!CMzWndEx::OnInitDialog())
    {
      return FALSE;
    }

    btncolor1.cr1 = RGB(10, 10, 10);
    btncolor1.cr2 = RGB(40, 40, 40);
    btncolor1.cr3 = RGB(90, 90, 90);
    btncolor1.cr4 = RGB(150, 150, 150);

    btncolor1.cr1s = RGB(180, 180, 180);
    btncolor1.cr2s = RGB(200, 200, 200);
    btncolor1.cr3s = RGB(222, 222, 222);
    btncolor1.cr4s = RGB(255, 255, 255);

    // 初始化窗口中的控件
    m_btn1.SetButtonType(MZC_BUTTON_DEFAULT);
    m_btn1.SetPos(100,150,280,100);
    m_btn1.SetGradientColor(btncolor1);
    m_btn1.SetID(MZ_IDC_TESTBTN1);
    m_btn1.SetText(L"Hello MZFC!");
    m_btn1.SetTextColor(RGB(255,255,255));

    AddUiWin(&m_btn1);
  
    btncolor2.cr1 = RGB(30, 0, 0);
    btncolor2.cr2 = RGB(60, 0, 0);
    btncolor2.cr3 = RGB(90, 0, 0);
    btncolor2.cr4 = RGB(150, 0, 0);

    btncolor2.cr1s = RGB(0, 130, 0);
    btncolor2.cr2s = RGB(0, 180, 0);
    btncolor2.cr3s = RGB(0, 200, 0);
    btncolor2.cr4s = RGB(0, 255, 0);

    // 初始化窗口中的控件
    m_btn2.SetButtonType(MZC_BUTTON_DEFAULT);
    m_btn2.SetPos(100,350,280,100);
    m_btn2.SetGradientColor(btncolor2);
    m_btn2.SetID(MZ_IDC_TESTBTN2);
    m_btn2.SetText(L"Hello MZFC!");
    m_btn2.SetTextColor(RGB(255,255,255));

    AddUiWin(&m_btn2);
    return TRUE;
  }

  // 重载命令消息的处理函数
  virtual void OnMzCommand(WPARAM wParam, LPARAM lParam)
  {
   UINT_PTR id = LOWORD(wParam);
   switch(id)
   {
   case MZ_IDC_TESTBTN1:
     {
      if(1 == MzMessageBoxEx(m_hWnd, L"You have pressed Exit button, Really want exit?", L"Exit", MB_YESNO, false))
      PostQuitMessage(0);
     }
     break;
   case MZ_IDC_TESTBTN2:
     {
      if(1 == MzMessageBoxEx(m_hWnd, L"You have pressed Exit button, Really want exit?", L"Exit", MB_YESNO, false))
      PostQuitMessage(0);
     }
     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