|
发表于 2013-7-8 14:01:52
|
显示全部楼层
本帖最后由 senjet 于 2013-7-8 14:04 编辑
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_TEXT_0 (GUI_ID_USER + 0x01)
#define ID_TEXT_1 (GUI_ID_USER + 0x02)
#define ID_TEXT_2 (GUI_ID_USER + 0x03)
#define ID_TEXT_3 (GUI_ID_USER + 0x04)
#define ID_TEXT_4 (GUI_ID_USER + 0x05)
#define ID_TEXT_5 (GUI_ID_USER + 0x06)
#define ID_IMAGE_0 (GUI_ID_USER + 0x18)
unsigned char *_acBuffer=RT_NULL;
char VerInfo_TEXT_0[21];
char VerInfo_TEXT_1[21];
char *VerInfo_Title=RT_NULL;
char *VerInfo_TEXT_2=RT_NULL;
char *VerInfo_TEXT_3=RT_NULL;
char *VerInfo_TEXT_4=RT_NULL;
char *VerInfo_TEXT_5=RT_NULL;
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "", ID_FRAMEWIN_0, 21, 6, 200, 130, 0, 0x0, 0 },
{ IMAGE_CreateIndirect, "Image", ID_IMAGE_0, 4, 4, 64, 64, 0, 0, 0 },
{ TEXT_CreateIndirect, VerInfo_TEXT_0, ID_TEXT_0, 60, 6, 128, 16, 0, 0x0, 0 },
{ TEXT_CreateIndirect, VerInfo_TEXT_1, ID_TEXT_1, 60, 22, 128, 16, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "", ID_TEXT_2, 60, 38, 128, 16, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "", ID_TEXT_3, 4, 54, 180, 16, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "", ID_TEXT_4, 4, 70, 180, 16, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "", ID_TEXT_5, 4, 86, 180, 16, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
int BMP_GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) {
int *phFile;
uint32_t NumBytesRead;
phFile = (int*)p;
//
// Check buffer size
//
if (NumBytes >512) {
NumBytes = 512;
}
//
// Set file pointer to the required position
//
lseek(*phFile,Off,SEEK_SET);
//
// Read data into buffer
//
NumBytesRead=read(*phFile, _acBuffer, NumBytes);
//
// Set data pointer to the beginning of the buffer
//
*ppData = _acBuffer;
//
// Return number of available bytes
//
return NumBytesRead;
}
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Image'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
TEXT_SetText(hItem,VerInfo_TEXT_2);
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
TEXT_SetText(hItem,VerInfo_TEXT_3);
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_4);
TEXT_SetText(hItem,VerInfo_TEXT_4);
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_5);
TEXT_SetText(hItem,VerInfo_TEXT_5);
// USER START (Optionally insert additional code for further widget initialization)
// USER END
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
WM_HWIN CreateVersionInfo() {
WM_HWIN hWin;
TEXT_SetDefaultFont(&FontHZ12_Ex);
FRAMEWIN_SetDefaultFont(&FontHZ12_Ex);
FRAMEWIN_SetDefaultBarColor(1,GUI_BLACK);
FRAMEWIN_SetDefaultTextColor(1,GUI_WHITE);
FRAMEWIN_SetDefaultClientColor(GUI_WHITE);
FRAMEWIN_SetDefaultTitleHeight(16);
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
FRAMEWIN_SetText(hWin,VerInfo_Title);
FRAMEWIN_AddCloseButton(hWin,FRAMEWIN_BUTTON_RIGHT,0);
WM_MakeModal(hWin);
WM_SetFocus(hWin);
WM_PaintWindowAndDescs(WM_HBKWIN);
return hWin;
}
void VersionInfo(void)
{
int flogo;
uint8_t OnExit=0;
rt_uint32_t event;
WM_HWIN hWin;
IMAGE_Handle hImage;
sprintf(VerInfo_TEXT_0,"SN:%02X%02X%02X%02X%02X%02X%02X%02X",Device_SN[0],Device_SN[1],Device_SN[2],Device_SN[3],Device_SN[4],Device_SN[5],Device_SN[6],Device_SN[7]);
sprintf(VerInfo_TEXT_1,"FW:%s build %s",VERNUM,BUILDNUM);
hWin=CreateVersionInfo();
_acBuffer=rt_malloc(512);
if(_acBuffer==RT_NULL)
{ rt_kprintf("No memory for image\r\n");
}else
{ flogo = open("/Logo.bmp", O_RDONLY, 0);
if(flogo<0)
{ rt_kprintf("Logo.bmp does not exists!\r\n");
}else
{ hImage = WM_GetDialogItem(hWin, ID_IMAGE_0);
IMAGE_SetBMPEx(hImage, BMP_GetData, (void*)&flogo);
}
}
OnExit=0;
while (OnExit==0)
{ if (rt_event_recv(&SYS_event, 0x000001fe,RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR,RT_WAITING_FOREVER, &event) == RT_EOK)
{ if (event&(1<<1))
{
GUI_SendKeyMsg(GUI_KEY_UP,1);
}
if (event&(1<<2))
{
GUI_SendKeyMsg(GUI_KEY_DOWN,1);
}
if (event&(1<<3))
{ GUI_SendKeyMsg(GUI_KEY_LEFT,1);
}
if (event&(1<<4))
{ GUI_SendKeyMsg(GUI_KEY_RIGHT,1);
}
if(event&(1<<5))
{
OnExit=1;
}
if(event&(1<<6))
{
OnExit=2;
}
if (event&(1<<7))
{ GUI_SendKeyMsg(GUI_KEY_SPACE,1);
}
if (event&(1<<8))
{ GUI_SendKeyMsg(GUI_KEY_TAB,1);
}
}
}
close(flogo);
rt_free(_acBuffer);
GUI_EndDialog(hWin,1);
}
红色部分是关键。使用的是emwin 5.2的Image控件,但实际上与GUI_BMP_DrawEx()差不多的 |
|