Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15482821
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: C/C++

2007-09-16 14:21:10

ucguiv3.90a多个窗体之间键盘tab切换需要注意的几个地方

  如果使用WINDOW_CreateIndirect创建了一个空白window窗体,
之后在其中创建了一个孩子listbox,当listbox中的某一项按ENTER键之后,
在listbox的右边出现一个新的window窗体的孩子,这个孩子也是一个window类型窗体
,这个孩子里边有能够获得焦点的各种控件,比如有两个Button类型控件,
如果不设置自己的回调函数,tab按键比较糟糕,因为所有按键消息都会传递到当前接收键盘消息的控件对应的parent
,就这样一直传递下去,直到传递到桌面回调函数,所以必须设立自己的回调函数,将tab消息截住,
让他tab消息停留在我们想要他停留的地方,
实例图:


下面是一个测试代码:
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { TPanel_CreateIndirect,"panel_Setup", 0, 0, ICON_PANEL_HEIGHT,LCD_XSIZE, LCD_YSIZE-ICON_PANEL_HEIGHT-PANEL_BOTTOM},
};

#define HOLE_POSX0    104
#define HOLE_POSX1    112
#define HOLE_HEIGHT    100
static const GUI_WIDGET_CREATE_INFO _BoxWindow[] = {
  { WINDOW_CreateIndirect, "",0, 40, 50, 240, HOLE_HEIGHT, WM_CF_SHOW },
};

static const GUI_WIDGET_CREATE_INFO _alisbox[] = {
  { LISTBOX_CreateIndirect, NULL, GUI_ID_LISTBOX0, 0, 0, HOLE_POSX0, 0},
};

static const GUI_WIDGET_CREATE_INFO _aWindow0[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK0", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_WIDGET_CREATE_INFO _aWindow1[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK1", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_WIDGET_CREATE_INFO _aWindow2[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK2", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_WIDGET_CREATE_INFO _aWindow3[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK3", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_WIDGET_CREATE_INFO _aWindow4[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK4", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_WIDGET_CREATE_INFO _aWindow5[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK5", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_WIDGET_CREATE_INFO _aWindow6[] = {
  { WINDOW_CreateIndirect,"",0 ,HOLE_POSX1,0,0,0, WM_CF_SHOW },
  { BUTTON_CreateIndirect, "OK6", GUI_ID_OK, 0, 5, 60, 20 },
  { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 0, 30, 60, 20 },
};

static const GUI_ConstString _apListBox[] = {
  "0.","1.", "2.", "3.", "4.", "5.","6.", NULL
};

#define windows_max 7
static WM_HWIN windows[windows_max];
static void show_cur_window(int index)
{int i;
    for(i = 0;i < windows_max;i++)
     WM_HideWindow(windows[i]);
    if(index >= 0)WM_ShowWindow(windows[index]);
}
static void foucs_cur_window(int index)
{
    if(index >= 0)
    {
        WM_SetFocus(windows[index]);
    }
}

static WM_CALLBACK* _cbCallback_BoxWindowT;
static void _cbCallback_BoxWindow(WM_MESSAGE * pMsg)
{WM_HWIN hObj;
 WINDOW_OBJ* pObj;
    
    switch (pMsg->MsgId)
    {
        case WM_PAINT:
            LCD_SetBkColor(GUI_WHITE);
            GUI_Clear();
            LCD_SetColor(GUI_BLACK);
            GUI_FillRect(HOLE_POSX0, 1, HOLE_POSX1-3, HOLE_HEIGHT-2);
            return;
            break;
        case WM_KEY:
            if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0)
            {int Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key;
                 hObj = pMsg->hWin;
                 pObj = LISTBOX_H2P(hObj);
                switch(Key)
                {
                    case GUI_KEY_TAB:return;
//不继续传递该key值 gliethttp
                    case GUI_KEY_LEFT:
                        {WM_HWIN hListBox;
                            hListBox = WM_GetDialogItem(WM_GetParent(pMsg->hWin), GUI_ID_LISTBOX0);
                            WM_SetFocus(hListBox);
                        }
                        break;
                }
            }
            break;
    }
    _cbCallback_BoxWindowT(pMsg);
}
static WM_CALLBACK* _cbCallback_listboxT;
static void _cbCallback_listbox(WM_MESSAGE * pMsg)
{LISTBOX_Handle hObj;
 LISTBOX_Obj* pObj;
    
    switch (pMsg->MsgId)
    {
        case WM_SET_FOCUS:
            {
                if (pMsg->Data.v == 1)
                {int index;
                    hObj = pMsg->hWin;
                    pObj = LISTBOX_H2P(hObj);
                    
//2007-09-14 gliethttp
                    if(pObj->Sel == -1)
                     LISTBOX_IncSel(hObj);
                    index = LISTBOX_GetSel(hObj);
                    show_cur_window(index);
                    
//foucs_cur_window(index);
                }
            }
            break;
        case WM_KEY:
            if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0)
            {int Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key;
                 hObj = pMsg->hWin;
                 pObj = LISTBOX_H2P(hObj);
                switch(Key)
                {
                    case GUI_KEY_UP:
                    case GUI_KEY_DOWN:
                        {int index;
                            hObj = pMsg->hWin;
                            LISTBOX_AddKey(hObj, Key);
                            index = LISTBOX_GetSel(hObj);
                            show_cur_window(index);
                            Key = (Key == GUI_KEY_UP ? GUI_KEY_DOWN:GUI_KEY_UP);
                            LISTBOX_AddKey(hObj, Key);
                        }
                        break;
                    case GUI_KEY_RIGHT:
                    case GUI_KEY_ENTER:
                        {int index;
                            hObj = pMsg->hWin;
                            index = LISTBOX_GetSel(hObj);
                            foucs_cur_window(index);
                        }
                        break;
                }
            }
            break;
    }
    _cbCallback_listboxT(pMsg);
}
static WM_CALLBACK* _cbCallback_PanelT;
static void _cbCallback_Panel(WM_MESSAGE * pMsg)
{
    switch (pMsg->MsgId)
    {
        case WM_SET_FOCUS:
            if (pMsg->Data.v == 1)
            {WM_HWIN hListBox;
                hListBox = WM_GetDialogItem(pMsg->hWin, GUI_ID_LISTBOX0);
                WM_SetFocus(hListBox);
                pMsg->Data.v = 0;
            }
            return;
    }
    _cbCallback_PanelT(pMsg);
}
static void _cbCallback(WM_MESSAGE * pMsg) {
  int NCode, Id;
  WM_HWIN hListBox,GUI_Box;
  WM_HWIN hWin = pMsg->hWin;
  switch (pMsg->MsgId) {
    case WM_INIT_DIALOG:
        GUI_Box = GUI_CreateDialogBox(ARRAY(_BoxWindow),0,hWin,0,0);
        GUI_CreateBox(ARRAY(_alisbox),GUI_Box);
        hListBox = WM_GetDialogItem(GUI_Box, GUI_ID_LISTBOX0);
        LISTBOX_SetText(hListBox, _apListBox);
        
        windows[0] = GUI_CreateDialogBox(ARRAY(_aWindow0),0,GUI_Box,0,0);
        windows[1] = GUI_CreateDialogBox(ARRAY(_aWindow1),0,GUI_Box,0,0);
        windows[2] = GUI_CreateDialogBox(ARRAY(_aWindow2),0,GUI_Box,0,0);
        windows[3] = GUI_CreateDialogBox(ARRAY(_aWindow3),0,GUI_Box,0,0);
        windows[4] = GUI_CreateDialogBox(ARRAY(_aWindow4),0,GUI_Box,0,0);
        windows[5] = GUI_CreateDialogBox(ARRAY(_aWindow5),0,GUI_Box,0,0);
        windows[6] = GUI_CreateDialogBox(ARRAY(_aWindow6),0,GUI_Box,0,0);
        
        show_cur_window(-1);
//隐藏窗体

        _cbCallback_PanelT = WM_SetCallback(hWin,_cbCallback_Panel);
        _cbCallback_BoxWindowT = WM_SetCallback(GUI_Box,_cbCallback_BoxWindow);
        _cbCallback_listboxT = WM_SetCallback(hListBox,_cbCallback_listbox);
      break;
    case WM_NOTIFY_PARENT:
      Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
      NCode = pMsg->Data.v; /* Notification code */
      switch (NCode) {
        case WM_NOTIFICATION_RELEASED: /* React only if released */
          if (Id == GUI_ID_OK) { /* OK Button */
            
//GUI_EndDialog(hWin, 0);
          }
          if (Id == GUI_ID_CANCEL) { /* Cancel Button */
            
//GUI_EndDialog(hWin, 1);
          }
          break;
      }
      break;
    default:
      WM_DefaultProc(pMsg);
  }
}
WM_HWIN panel_Setup_create(void)
{
   TPanelBox_Create(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
}

阅读(3542) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~