zoukankan      html  css  js  c++  java
  • 魅族m8开发 step by step(3)(BasicControl)

        接上篇,下面看下来就比较简单了,本示例为牵涉到下面新的控件

    1. UiSingleLineEdit 其实就是TextBox
    2. UiToolbar_Text 一个ToolBar
    3. CPopupMenu 一个弹出菜单

    一.首先窗体初始化

    // 从?CMzWndEx 派?生?的?主?窗?口?类?
    class CSample1MainWnd: public CMzWndEx
    {
      MZ_DECLARE_DYNAMIC(CSample1MainWnd);
    public:
      // 窗?口?中?的?按?钮?控?件?
      UiButton m_btn;
      
      // 文?字?按?钮?工?具?条?
      UiToolbar_Text m_Toolbar;
    
      // 单?行?编?辑?器?
      UiSingleLineEdit m_Edit;
    
    protected:
      // 窗?口?的?初?始?化?
      virtual BOOL OnInitDialog()
      {
        // 必?须?先?调?用?基?类?的?初?始?化?
        if (!CMzWndEx::OnInitDialog())
        {
          return FALSE;
        }
    
         // 初?始?化?单?行?编?辑?控?件?,?并?添?加?到?窗?口?中?
        m_Edit.SetPos(MZM_MARGIN_MAX,MZM_MARGIN_MAX,GetWidth()-MZM_MARGIN_MAX*2,70);
        m_Edit.SetID(MZ_IDC_TESTBTN1); //you must set an unique ID for a edit control
        m_Edit.SetTip(L"Please enter text...");    // set the tips text
        m_Edit.SetTextColor(RGB(255,0,0)); // you could also set the color of text
        
        AddUiWin(&m_Edit); // don't forget to add the control to the window
    
        // 初?始?化?按?钮?控?件?,?并?添?加?到?窗?口?中?
        m_btn.SetButtonType(MZC_BUTTON_PELLUCID);
        m_btn.SetPos(100,130,280,100);
        m_btn.SetID(MZ_IDC_TESTBTN1);
        m_btn.SetText(L"Get Edit's Text");
        //m_btn.SetTextColor(RGB(0,255,0));
        AddUiWin(&m_btn);
    
        // 初?始?化?文?字?工?具?条?,?并?添?加?到?窗?口?中?
        m_Toolbar.SetPos(0,GetHeight()-MZM_HEIGHT_TEXT_TOOLBAR,GetWidth(),MZM_HEIGHT_TEXT_TOOLBAR);
        m_Toolbar.SetButton(0, true, true, L"Exit");
        m_Toolbar.SetButton(1, true, true, L"Menu");
        m_Toolbar.SetButton(2, true, true, L"Hide button");
        m_Toolbar.SetID(MZ_IDC_TOOLBAR1);
        AddUiWin(&m_Toolbar);
    
        return TRUE;
      }

    image

    二.加命令

    我们先看来toolbar三个按钮的作用.

    1.Exit 推出程序

    if (nIndex==0)
    {
      PostQuitMessage(0);
      return;
    }


    2.Menu 创建一个PopupMenu

    CPopupMenu 用法

    首先通过AddItem方法添加按钮,然后用Create创建Menu,最后用DoModal弹出菜单,通过返回的ID参数判断按钮触发事件

    if (nIndex==1)
    {
      // 弹?出?菜?单?
      CPopupMenu ppm;
      struct PopupMenuItemProp pmip;      
    
      pmip.itemCr = MZC_BUTTON_PELLUCID;
      pmip.itemRetID = IDC_PPM_CANCEL;
      pmip.str = L"Cancel";
      ppm.AddItem(pmip);
    
      pmip.itemCr = MZC_BUTTON_ORANGE;
      pmip.itemRetID = IDC_PPM_OK;
      pmip.str = L"OK";
      ppm.AddItem(pmip);  
    
      RECT rc = MzGetWorkArea();      
      rc.top = rc.bottom - ppm.GetHeight();
      ppm.Create(rc.left,rc.top,RECT_WIDTH(rc),RECT_HEIGHT(rc),m_hWnd,0,WS_POPUP);      
      int nID = ppm.DoModal();
      if (nID==IDC_PPM_OK)
      {
        // do what you want...
      }
      if (nID==IDC_PPM_CANCEL)
      {
        // do what you want...
      }
      return;
    }


    3.Hide button 用于显示和隐藏按钮

    注意:UI更新方法(光设置属性是无法更新UI的)

    两种方法

    (1)局部更新Invalidate

    (2)整体更新(更新与控件相关的窗体)Update

    if (nIndex==2)
    {
      m_btn.SetVisible(!m_btn.IsVisible());
      m_btn.Invalidate();
      m_btn.Update();
      if (m_btn.IsVisible())
        m_Toolbar.SetButtonText(2, L"Hide button");
      else
        m_Toolbar.SetButtonText(2, L"Show button");
    
      m_Toolbar.Invalidate();
      m_Toolbar.Update();
      return;
    }


    三.MZFC字符串类CMzString

    封装了对宽字符的处理,由于用到比较多,基本数据类型的操作需要了解下.来看下获取文本框那个按钮的事件

    C_Str方法用于获取字符串指针

    case MZ_IDC_TESTBTN1:
      {
        CMzString str(64+m_Edit.GetTextLen());
        // 格式化字符串
        wsprintf(str.C_Str(), L"You'd input:\n%s", m_Edit.GetText().C_Str());
        // 弹出消息框
        MzMessageBoxEx(m_hWnd, str.C_Str(), L"", MB_OK, false);
      }
      break;

    这个示例就到这里
  • 相关阅读:
    linux下postgresql的安装与卸载
    根据高德API知道坐标获取详细地址信息
    springboot学习笔记:11.springboot+shiro+mysql+mybatis(通用mapper)+freemarker+ztree+layui实现通用的java后台管理系统(权限管理+用户管理+菜单管理)
    springboot学习笔记:10.springboot+atomikos+mysql+mybatis+druid+分布式事务
    springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源
    springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+freemarker+layui
    springboot学习笔记:7.IDEA下5步完成热部署配置
    springboot学习笔记:6.内置tomcat启动和外部tomcat部署总结
    springboot学习笔记:5.spring mvc(含FreeMarker+layui整合)
    springboot学习笔记:4.logback日志配置
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/1603207.html
Copyright © 2011-2022 走看看