金牌会员
- 积分
- 1383
- 金钱
- 1383
- 注册时间
- 2015-2-3
- 在线时间
- 197 小时
|
发表于 2016-8-1 18:02:12
|
显示全部楼层
本帖最后由 yyx112358 于 2016-8-3 16:34 编辑
画图需要首先在其它事件(比如按下按钮事件或者自定义事件)当中无效化窗口(告诉EMWIN这个窗口需要重绘了),然后EMWIN会调用回调函数中WM_PAINT部分代码重绘,所以画图需要放在WM_PAINT当中。
给一个示例
[mw_shl_code=c,true]static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
// USER START (Optionally insert additional variables)
U32 i = 0;
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Monitor'
//
hItem = pMsg->hWin;
WINDOW_SetBkColor(hItem, 0x00E6E6E6);
//
// Initialization of 'CLOSE'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
//
// Initialization of 'Fit'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
//
// Initialization of '111 111'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
TEXT_SetFont(hItem, GUI_FONT_D32);
// USER START (Optionally insert additional code for further widget initialization)
// USER END
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'CLOSE'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
WM_DeleteWindow( pMsg->hWin );
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_1: // Notifications sent by 'Fit'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
case WM_PAINT:
{
GUI_COLOR tmpcolor = GUI_GetColor();
GUI_FONT tmpfont = *GUI_GetFont();
GUI_RECT rect = { 0, 0, 240, 240 };
char str[32];
GUI_SetClipRect( &rect );
GUI_SetFont( &GUI_Font20_ASCII );
for ( i = 0; i < 3; i++ )
{
GUI_SetColor( MYPURPLE );
GUI_DrawCircle( ZIGBEE_Image.O.x*3, 240-ZIGBEE_Image.O.y*3, ZIGBEE_Image.R*3 );
GUI_DrawCircle( ZIGBEE_Image.O.x*3, 240-ZIGBEE_Image.O.y*3, ZIGBEE_Image.R*3 - 3 );
GUI_DrawCircle( ZIGBEE_Image.O.x*3, 240-ZIGBEE_Image.O.y*3, ZIGBEE_Image.R*3 - 2 );
GUI_DrawCircle( ZIGBEE_Image.O.x*3, 240-ZIGBEE_Image.O.y*3, ZIGBEE_Image.R*3-1 );
GUI_SetColor( 0xC59A2C );
sprintf( str, "%3.1f", ZIGBEE_Image.R );
if ( ZIGBEE_Image.O.x*3 <60 )
GUI_DispStringHCenterAt( str, ZIGBEE_Image.O.x*3+10 , 240-ZIGBEE_Image.O.y*3 -10);
else if ( ZIGBEE_Image.O.x*3 >180 )
GUI_DispStringHCenterAt( str, ZIGBEE_Image.O.x*3-10, 240-ZIGBEE_Image.O.y*3-10 );
else
GUI_DispStringHCenterAt( str, ZIGBEE_Image.O.x*3 , 240-ZIGBEE_Image.O.y*3 );
}
GUI_SetColor( MYRED );
GUI_FillCircle( ZIGBEE_Image.CrossPoint.x*3, 240-ZIGBEE_Image.CrossPoint.y*3, 5 );
GUI_SetColor( tmpcolor );
GUI_FillRect( 0, 240, 240, 100 );
}
break;
case WM_MONITOR_UPDATE:
{
GUI_RECT rect = { 0, 0, 240, 240 };
TEXT_Handle hTEXT_Monitor;
char str[16];
ZIGBEE_Image = *(Monitor_Data*)pMsg->Data.p;
WM_InvalidateArea( &rect );
hTEXT_Monitor = WM_GetDialogItem( pMsg->hWin, ID_TEXT_0 );
sprintf( str, "%3.1f %3.1f", ZIGBEE_Image.CrossPoint.x, ZIGBEE_Image.CrossPoint.y );
TEXT_SetText( hTEXT_Monitor, str );
WM_InvalidateWindow( hTEXT_Monitor );
}
break;
case WM_DELETE:
DESKTOP_Reset_APPRunning();
break;
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}[/mw_shl_code]
PS:这是在Window窗口控件当中做的,Framewin对话框控件似乎不行
效果图
|
|