|
发表于 2018-1-17 20:48:39
|
显示全部楼层
非常好! 测试通过。 稍微修改。
/*********************************************************************
* *
* SEGGER Microcontroller GmbH & Co. KG *
* Solutions for real time microcontroller applications *
* *
**********************************************************************
* *
* C-file generated by: *
* *
* GUI_Builder for emWin version 5.36 *
* Compiled Aug 31 2016, 10:53:09 *
* (c) 2016 Segger Microcontroller GmbH & Co. KG *
* *
**********************************************************************
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
*/
// USER START (Optionally insert additional includes)
#if defined ( __CC_ARM)
#include <includes.h>
#endif
// USER END
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x50)
#define ID_BUTTON_NO (GUI_ID_USER + 0x51)
#define ID_BUTTON_YES (GUI_ID_USER + 0x52)
#define ID_TEXT_CONFIRM (GUI_ID_USER + 0x53)
static const GUI_WIDGET_CREATE_INFO _ConfirmDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Confirm", ID_FRAMEWIN_0, 0, 0, 220, 120, 0, 0x64, 0 },
{ BUTTON_CreateIndirect, "Cancel", ID_BUTTON_NO, 25, 45, 60,30 , 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "YES", ID_BUTTON_YES, 125, 45, 60,30 , 0, 0x0, 0 },
{ TEXT_CreateIndirect, "Confirm?", ID_TEXT_CONFIRM, 5, 0, 200,50, 0, 0, 0 },
};
static void _cbConfirmDialog(WM_MESSAGE * pMsg)
{
int NCode, Id;
WM_HWIN hWin ;
hWin=pMsg->hWin;
switch (pMsg->MsgId)
{
case WM_INIT_DIALOG:
break;
case WM_KEY:
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
{
case GUI_KEY_ESCAPE:
GUI_EndDialog(hWin,1);
break;
case GUI_KEY_RIGHT:
GUI_SendKeyMsg(GUI_KEY_TAB,1);
break;
case GUI_KEY_LEFT:
GUI_SendKeyMsg(GUI_KEY_TAB,1);
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_CLICKED:/* React only if released */
if (Id == ID_BUTTON_YES)
{ /* OK Button */
GUI_EndDialog(hWin, 0);
}
else if (Id == ID_BUTTON_NO)
{ /* Cancel Button */
GUI_EndDialog(hWin, 1);
}
break;
case WM_NOTIFICATION_SEL_CHANGED:/* Selection changed */
//FRAMEWIN_SetText(hWin, "Dialog - sel changed");
break;
}
break;
case WM_PAINT:
GUI_SetBkColor(GUI_LIGHTGRAY);
GUI_Clear();
GUI_SetColor(GUI_DARKBLUE);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*******************************************************/
//自定义消息框,含确认和取消按钮,模态对话框,只有点击确认或者取消后才会执行后续程序。
//pFONT可以设定消息框的字体,x0,y0为对话框的显示位置。默认父窗口为 WM_HBKWIN。
// 消息框点击了“确认”后,返回值为0; 点击了“取消”后,返回值为1.
//
/********************************************************/
U32 User_CreateMessageBox(const char * sMessage,const char *sCaption, const GUI_FONT * pFont,U32 x0, U32 y0)
{
U32 i = 0;
WM_HWIN hDialog;
WM_HWIN hButtonYes, hButtonNo, hText;
hDialog = GUI_CreateDialogBox(_ConfirmDialogCreate,GUI_COUNTOF(_ConfirmDialogCreate),_cbConfirmDialog,WM_HBKWIN,x0,y0);
hButtonYes = WM_GetDialogItem(hDialog, ID_BUTTON_YES);
hButtonNo = WM_GetDialogItem(hDialog, ID_BUTTON_NO);
hText=WM_GetDialogItem(hDialog, ID_TEXT_CONFIRM);
FRAMEWIN_SetFont(hDialog, pFont);
FRAMEWIN_SetText(hDialog, sCaption);
FRAMEWIN_SetTextColor(hDialog, GUI_LIGHTYELLOW);
FRAMEWIN_SetTitleHeight(hDialog, 24);
FRAMEWIN_SetTextAlign(hDialog, GUI_TA_HCENTER | GUI_TA_VCENTER);
TEXT_SetFont(hText, pFont);
TEXT_SetTextAlign(hText, GUI_TA_HCENTER | GUI_TA_VCENTER);
TEXT_SetTextColor(hText, 0x00FF0000);
TEXT_SetText(hText,sMessage);
BUTTON_SetText(hButtonYes, "YES");
BUTTON_SetFont(hButtonYes, pFont);
BUTTON_SetText(hButtonNo, "NO");
BUTTON_SetFont(hButtonNo,pFont);
i = GUI_ExecCreatedDialog(hDialog);
return i;
}
|
|