MT6261菜单创建(实例代码,含窗口控件NVRAM的使用)

Posted q10040

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MT6261菜单创建(实例代码,含窗口控件NVRAM的使用)相关的知识,希望对你有一定的参考价值。

  1. 资源的定义(图片ID、字符串ID、屏幕ID、菜单ID)
    /************图片ID定义************/
    <IMAGE id="MAIN_MENU_SHOWCTRL_ICON">CUST_IMG_PATH"\\MainLCD\\MainMenu\\PAGE\\BlackWhite\\MM_GM.gif"</IMAGE>
    /**********************************/
    
    /***********字符串ID定义***********/
    <STRING id= "STR_ID_SHOW_CTRL"/>
    <STRING id= "STR_ID_SHOW_CTRL_LISTBOX"/>
    <STRING id= "STR_ID_SHOW_CTRL_EDITBOX"/>
    <STRING id= "STR_ID_SHOW_CTRL_TEXTBOX"/>
    /**********************************/
    
    /************屏幕ID定义************/
    <SCREEN id = "SCR_ID_SHOW_CTRL"/>
    <SCREEN id = "SCR_ID_SHOW_CTRL_LISTBOX"/>
    <SCREEN id = "SCR_ID_SHOW_CTRL_EDITBOX"/>
    <SCREEN id = "SCR_ID_SHOW_CTRL_TEXTBOX"/>
    /**********************************/
    
    /**********一级菜单ID定义**********/
    <MENU id="MAIN_MENU_SHOWCTRL_MENUID" type="APP_MAIN" str="STR_ID_SHOW_CTRL" img="MAIN_MENU_SHOWCTRL_ICON" highlight="highlight_show_ctrl">
        <MENUITEM id = "MENU_ID_SHOW_CTRL_LISTBOX" str = "STR_ID_SHOW_CTRL_LISTBOX"/>
        <MENUITEM id = "MENU_ID_SHOW_CTRL_EDITBOX" str = "STR_ID_SHOW_CTRL_EDITBOX"/>
        <MENUITEM id = "MENU_ID_SHOW_CTRL_TEXTBOX" str = "STR_ID_SHOW_CTRL_TEXTBOX"/>
    </MENU>
    <MAINMENUITEM id="MAIN_MENU_SHOWCTRL_MENUID" mm_page_img="MAIN_MENU_SHOWCTRL_ICON"/> 
    /**********************************/
    
    /**********二级菜单ID定义**********/
    <MENU id = "MENU_ID_SHOW_CTRL" type="APP_SUB" str = "STR_ID_SHOW_CTRL" highlight="highlight_show_ctrl">
        <MENUITEM id = "MENU_ID_SHOW_CTRL_LISTBOX" str = "STR_ID_SHOW_CTRL_LISTBOX"/>
        <MENUITEM id = "MENU_ID_SHOW_CTRL_EDITBOX" str = "STR_ID_SHOW_CTRL_EDITBOX"/>    
        <MENUITEM id = "MENU_ID_SHOW_CTRL_TEXTBOX" str = "STR_ID_SHOW_CTRL_TEXTBOX"/>
    </MENU>
    /**********************************/
    
    //注:以上资源ID定义可在“MainMenuRes.res”文件中相应位置进行
  2. 菜单的创建
    /**********一级菜单ID使用***********/
    <MENUITEM_ID>MAIN_MENU_SHOWCTRL_MENUID</MENUITEM_ID>
    /*********************************/
    
    /**********二级菜单ID使用***********/
    <MENUITEM_ID>MENU_ID_SHOW_CTRL</MENUITEM_ID>
    /*********************************/
    //注:以上资源ID定义可在“MainMenuRes.res”文件中相应位置进行
  3. 窗口及控件

    #include "common_nvram_editor_data_item.h"
    nvram_show_ctrl_struct  ShowCtrlStruct = {0};
    U8 listbox_current_index = 0;
    WCHAR editbox_buffer[MAX_STRING_LEN] = {0};
    WCHAR textbox_buffer[MAX_STRING_LEN] = {0};
    
    void highlight_hdlr(kal_uint8 index)
    {
        listbox_current_index = index ;
    }
    
    void ReadNvramShowCtrl(void)
    {
        S16 error;
        ReadRecord(NVRAM_EF_SHOWCTRL_LID,1,&ShowCtrlStruct,NVRAM_EF_SHOWCTRL_SIZE,&error);
    }
    
    void WriteNvramShowCtrl(void)
    {
        S16 error;
        WriteRecord(NVRAM_EF_SHOWCTRL_LID,1,&ShowCtrlStruct,NVRAM_EF_SHOWCTRL_SIZE,&error);
    }
    
    void StatusSetListBoxDone(void)
    {
        if(ShowCtrlStruct.listboxIndex != listbox_current_index)
        {
            ShowCtrlStruct.listboxIndex = listbox_current_index;
            WriteNvramShowCtrl();
        }
        mmi_display_popup((UI_string_type)get_string(STR_GLOBAL_DONE),MMI_EVENT_SUCCESS);
        DeleteNHistory(1);
    }
    void StatusSetEditBoxDone(void) { wcscpy(ShowCtrlStruct.string,editbox_buffer); WriteNvramShowCtrl(); mmi_display_popup((UI_string_type)get_string(STR_GLOBAL_DONE),MMI_EVENT_SUCCESS); DeleteNHistory(1); } void EntryShowCtrlListbox(void) { #define LISTBOX_ITEM_NUM 2 U8 *itemlist[LISTBOX_ITEM_NUM]; U8 *ItemIcons[LISTBOX_ITEM_NUM]; U16 index; EntryNewScreen(SCR_ID_SHOW_CTRL_LISTBOX,NULL,EntryShowCtrlListbox, NULL); itemlist[0] = (U8*) GetString((U16)(STR_GLOBAL_OFF)); for (index = 1; index < LISTBOX_ITEM_NUM; index++) { itemlist[index] = (U8*) GetString((U16)(STR_GLOBAL_ON+ index)); } RegisterHighlightHandler(highlight_hdlr); #if 0//普通带序号图标的列表控件 for (index = 0; index < LISTBOX_ITEM_NUM; index++) { ItemIcons[index] = (U8*) GetImage((U16)(gIndexIconsImageList[index])); } ReadNvramShowCtrl(); ShowCategory170Screen((PU8) GetString(STR_ID_SHOW_CTRL_LISTBOX), NULL, (PU8) GetString(STR_GLOBAL_OK), (PU8) GetImage(IMG_GLOBAL_OK), (PU8) GetString(STR_GLOBAL_BACK), (PU8) GetImage(IMG_GLOBAL_BACK), LISTBOX_ITEM_NUM, (U8 **) itemlist, ItemIcons, LIST_MENU, ShowCtrlStruct.listboxIndex, NULL); #else//单选列表控件 ReadNvramShowCtrl(); ShowCategory36Screen( STR_ID_SHOW_CTRL_LISTBOX, NULL, STR_GLOBAL_OK, IMG_GLOBAL_OK, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, LISTBOX_ITEM_NUM, (U8 **) itemlist, ShowCtrlStruct.listboxIndex, NULL); #endif SetKeyHandler(StatusSetListBoxDone, KEY_LSK,KEY_EVENT_DOWN); SetKeyHandler(GoBackHistory, KEY_RSK,KEY_EVENT_DOWN); } void EntryShowCtrlEditbox(void) { PU8 gui_buffer = NULL; EntryNewScreen(SCR_ID_SHOW_CTRL_EDITBOX, NULL, EntryShowCtrlEditbox, NULL); gui_buffer = mmi_frm_scrn_get_active_gui_buf(); ReadNvramShowCtrl(); if(!gui_buffer) { wcscpy(editbox_buffer,ShowCtrlStruct.string); } ShowCategory5Screen( NULL, NULL, STR_GLOBAL_OK, IMG_GLOBAL_OK, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, IMM_INPUT_TYPE_SENTENCE, (PU8) editbox_buffer, MAX_STRING_LEN, NULL); /*右键的处理函数在 wgui_inputs_ml_set_RSK_int()里注册好了*/ SetLeftSoftkeyFunction(StatusSetEditBoxDone, KEY_EVENT_DOWN); wgui_inputs_category_set_rsk_func(GoBackHistory); } void EntryShowCtrlTextbox(void) { PU8 guiBuffer = NULL; EntryNewScreen(SCR_ID_SHOW_CTRL_TEXTBOX, NULL, EntryShowCtrlTextbox, NULL); guiBuffer = GetCurrGuiBuffer(SCR_ID_SHOW_CTRL_TEXTBOX); ReadNvramShowCtrl(); wcscpy(textbox_buffer,ShowCtrlStruct.string); ShowCategory7Screen( NULL /*STR_ID_SHOW_CTRL_TEXTBOX*/, NULL, NULL, NULL, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, (PU8) textbox_buffer, NULL); SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP); } static mmi_ret mmi_ShowCtrl_func_select_hdlr(mmi_event_struct * evt) { cui_menu_event_struct *menu_evt = (cui_menu_event_struct*) evt; switch (menu_evt->evt_id) { case EVT_ID_CUI_MENU_LIST_ENTRY: case EVT_ID_CUI_MENU_ITEM_HILITE: { break; } case EVT_ID_CUI_MENU_ITEM_SELECT: { switch(menu_evt->highlighted_menu_id) { case MENU_ID_SHOW_CTRL_LISTBOX: EntryShowCtrlListbox(); return MMI_RET_OK; break; case MENU_ID_SHOW_CTRL_EDITBOX: EntryShowCtrlEditbox(); return MMI_RET_OK; break; case MENU_ID_SHOW_CTRL_TEXTBOX: EntryShowCtrlTextbox(); return MMI_RET_OK; break; default: break; } break; } case EVT_ID_CUI_MENU_CLOSE_REQUEST: cui_menu_close(menu_evt->sender_id); break; case EVT_ID_GROUP_DEINIT: mmi_frm_group_close(SCR_ID_SHOW_CTRL); break; } return MMI_RET_OK; } void EntryShowCtrlFunc(void) { MMI_ID menu_gid; if (mmi_frm_group_is_present(SCR_ID_SHOW_CTRL)) { mmi_frm_group_close(SCR_ID_SHOW_CTRL); } mmi_frm_group_create_ex(GRP_ID_ROOT, SCR_ID_SHOW_CTRL, mmi_ShowCtrl_func_select_hdlr, NULL, MMI_FRM_NODE_SMART_CLOSE_FLAG); menu_gid = cui_menu_create( SCR_ID_SHOW_CTRL, CUI_MENU_SRC_TYPE_RESOURCE, CUI_MENU_TYPE_FROM_RESOURCE, MENU_ID_SHOW_CTRL, MMI_FALSE, NULL); cui_menu_set_default_title_image_by_id(menu_gid, GetRootTitleIcon(STR_ID_SHOW_CTRL)); cui_menu_run(menu_gid); } void highlight_show_ctrl(void) { ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK); ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK); SetLeftSoftkeyFunction(EntryShowCtrlFunc, KEY_EVENT_UP); SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP); }

    //注:以上代码实现可在“MainMenu.c”文件中相应位置进行

     

  4. NVRAM的使用
    /************定义NV版本号************/
    #define NVRAM_EF_SHOWCTRL_LID_VERNO "000"
    /**********************************/
    
    /**********定义NV变量结构体**********/
    #define MAX_STRING_LEN    30
    typedef struct
    {
        kal_uint8 listboxIndex;
        kal_uint16 string[MAX_STRING_LEN];
    } nvram_show_ctrl_struct;
    /**********************************/
    
    /**************未知作用*************/
    LID_BIT VER_LID(NVRAM_EF_SHOWCTRL_LID) nvram_show_ctrl_struct* NVRAM_EF_SHOWCTRL_TOTAL{};
    /**********************************/
    
    //注:以上代码添加在“Common_nvram_editor_data_item.h”文件中相应位置

     

    /************NV内存初始化************/
    static nvram_show_ctrl_struct const NVRAM_EF_SHOWCTRL_DEFAULT[NVRAM_EF_SHOWCTRL_TOTAL]={
        0x00,
        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
    };
    /**********************************/
    
    /**************未知作用*************/
    {
        NVRAM_EF_SHOWCTRL_LID,
        NVRAM_EF_SHOWCTRL_TOTAL,
        NVRAM_EF_SHOWCTRL_SIZE,
        NVRAM_NORMAL(NVRAM_EF_SHOWCTRL_DEFAULT),
        NVRAM_CATEGORY_USER,
        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_FACTORY_RESET,
        "MQ25",
        VER(NVRAM_EF_SHOWCTRL_LID)
    },
    /**********************************/
    //注:以上代码添加在“Nvram_common_config.c”文件中相应位置

     

  5. /*************未知作用*************/
    NVRAM_EF_SHOWCTRL_LID,
    /**********************************/
    
    /*************NV相关量宏定义*************/
    #define NVRAM_EF_SHOWCTRL_SIZE    (sizeof(nvram_show_ctrl_struct))
    #define NVRAM_EF_SHOWCTRL_TOTAL    1
    /**********************************/
    //注:以上代码添加在“Nvram_common_defs.h”文件中相应位置

     






以上是关于MT6261菜单创建(实例代码,含窗口控件NVRAM的使用)的主要内容,如果未能解决你的问题,请参考以下文章

通过C# WinForm控件创建的WPF WIndow窗口控件无法输入的问题

VS.net (c#)如何调用另一个控件的事件

(17)Blender源码分析之闪屏窗口的菜单显示过程

(17)Blender源码分析之闪屏窗口的菜单显示过程

pyqt5-基本窗口控件

c#,求助!在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。