我想实现这样的功能,按下ESC键从对话框一跳到对话框二,但现在跳到对话框二后就死机,版主请问对话框切换程序要怎么写,以下是我的代码,要怎么修改才能实现对话框切换,非常感谢。
void MainTask(void) {//主函数
GUI_Init();
WM_SetCallback(WM_HBKWIN, _cbBkWindow);
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);//创建对话框一
}
static void _cbCallback(WM_MESSAGE * pMsg) {//对话框一的回调函数
int i;
int NCode, Id;
WM_HWIN hDlg, hItem;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
for (i = 0; i < GUI_COUNTOF(_apLabel); i++) {
RADIO_SetText(hItem, _apLabel, i);
}
_SetFont(hDlg);
break;
case WM_KEY:
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {
case GUI_KEY_ESCAPE:
WM_DeleteWindow(hDlg);
ExecSetup();//创建对话框二
break;
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
NCode = pMsg->Data.v; /* Notification code */
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED: /* Value has changed */
_SetFont(hDlg);
break;
case WM_NOTIFICATION_RELEASED: /* React only if released */
if (Id == GUI_ID_OK) { /* OK Button */
GUI_EndDialog(hDlg, 0);
}
if (Id == GUI_ID_CANCEL) { /* Cancel Button */
GUI_EndDialog(hDlg, 1);
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
void ExecSetup(void)//建立对话框二
{
GUI_Init();
WM_SetCallback(WM_HBKWIN, &_cbBkWindow);
WM_SetCreateFlags(WM_CF_MEMDEV); // Use memory devices on all windows to avoid flicker
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
}
static void _cbCallback(WM_MESSAGE * pMsg) {//对话框二回调函数
WM_HWIN hDlg;
WM_HWIN hItem;
int Sel;
int NCode;
int Id;
GUI_PID_STATE * pState;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0);
EDIT_SetDecMode(hItem, 30, 0, 999, 0, 0); // Select decimal mode
WM_DisableWindow(hItem);
break;
case WM_KEY:
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {
case GUI_KEY_ESCAPE:
GUI_EndDialog(hDlg, 1);
break;
case GUI_KEY_ENTER:
GUI_EndDialog(hDlg, 0);
break;
}
break;
case WM_TOUCH_CHILD:
Id = WM_GetId(pMsg->hWinSrc); // Id of widget
switch (Id) {
case GUI_ID_TEXT0:
case GUI_ID_TEXT1:
case GUI_ID_TEXT2:
pState = (GUI_PID_STATE *)((WM_MESSAGE *)pMsg->Data.p)->Data.p;
if (pState) {
if (pState->Pressed) {
WM_HWIN hRadio = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
RADIO_SetValue(hRadio, Id - GUI_ID_TEXT0); // Use the text beside the radio button to
// set the value of the radio button
}
}
break;
}
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
switch (Id) {
case GUI_ID_OK:
GUI_EndDialog(hDlg, 0);
break;
case GUI_ID_CANCEL:
GUI_EndDialog(hDlg, 1);
break;
}
break;
case WM_NOTIFICATION_VALUE_CHANGED:
hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
Sel = RADIO_GetValue(hItem);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0);
WM_SetEnableState(hItem, Sel == 2);
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
|