emwin的WM_PAINT

 1 //界面实现
 2 static void _cbDummy(WM_MESSAGE* pMsg){
 3     int Id, NCode;
 4     int hour, min, second, tim;
 5     WM_HWIN hWin;
 6     char temp[4], temp1[4];
 7     char tim_t[10];
 8     hWin = pMsg->hWin;
 9 //    create_basePage(); 
10     switch (pMsg->MsgId) {
11       case WM_CREATE:
12         WM_CreateTimer(hWin, 0, 1000, 0);
13         break;
14       case WM_TIMER:
15         WM_RestartTimer(pMsg->Data.v, 1000);
16         //时间格式转换
17         break;
18       case WM_PAINT:
19         create_basePage();  //每次都重绘背景和标题
20         break;
21 
22       case WM_NOTIFY_PARENT:
23         Id = WM_GetId(pMsg->hWinSrc);
24         NCode = pMsg->Data.v;
25         switch(Id) {
26         case ID_BUTTON_0:  //设置
27             switch(NCode) {
28               case WM_NOTIFICATION_CLICKED:
29                 break;
30               case WM_NOTIFICATION_RELEASED:
31                   if(controlSet==0) {
32                     controlSet = 1;
33                     BUTTON_SetText(setbutton, Font_Back);
34                     //BUTTON_SetText(setbutton, "返回");
35                     hWinSet1 = CreateSetWindow();
36                     BUTTON_SetBitmapEx(setbutton, BUTTON_BI_UNPRESSED, &bmstart1, 32, 2);
37                   }else {
38                     controlSet = 0;
39                     BUTTON_SetText(setbutton, Font_Set);
40                     //BUTTON_SetText(setbutton, "设置");
41                     WM_DeleteWindow(hWinSet1);
42                     BUTTON_SetBitmapEx(setbutton, BUTTON_BI_UNPRESSED, &bmstart, 32, 2);
43                   }
44                 break;
45             }
46             break;
47 
48          case ID_BUTTON_1:  //启动/停止
49             switch(NCode) {
50               case WM_NOTIFICATION_CLICKED:
51                 break;
52               case WM_NOTIFICATION_RELEASED:
53                 if(startOrStop==0){
54                     startOrStop = 1;
55                     printf("start\n");
56                 }else {
57                     startOrStop = 0;
58                     printf("stop\n");
59                 }
60                 invalidStartButton(hWin);
61                 break;
62             }
63             break;
64         }
65         break;
66 
67     default:
68         WM_DefaultProc(pMsg);
69         break;
70     }
71 }
72 
73 
74 WM_HWIN CreateWindow(void) {
75     //get_gif(); //显示开机动画
76     BUTTON_SetDefaultSkinClassic(); //使用经典皮肤
77     hWinBase = WM_CreateWindow(0,  0, 480, 320, WM_CF_SHOW, _cbDummy, 0);
78     return hWinBase;
79 }

emwin中自己创建窗口,并且将所有的界面都放在WM_PAINT下面,运行定时器的时候,总是卡死,一直找不到原因,最后发现可能是内存不足,找到原因是

create_basePage(); //每次都重绘背景和标题

每次都重绘整个页面然后又没有清除导致内存不足,进行不断的尝试,发现create_basePage();放在WM_PAINT之外,不能画矩形设置背景色,并且按钮的监听也有问题,

最后只能重写,写完之后,WM_PAINT只需要放置画矩形,需要重绘的控件就能实现功能,并且也不会内存不足,引以为戒!

case WM_PAINT:
    GUI_Clear();
    GUI_DrawGradientV(0, 0, LCD_GetXSize(), LCD_GetYSize(), GUI_LIGHTGREEN, 0x71B33C);  //渐变色填充
    GUI_SetPenSize(1); //画笔像素 1
    GUI_SetColor(GUI_BLACK);  //画笔颜色黑色
    GUI_DrawRect(1, 1, 388, 52); //绘制矩形

    //画边框
    GUI_DrawRect(388, 70, 478, 250);

    //告警栏
    GUI_DrawRect(388, 125, 478, 184);

    //频率显示栏
    GUI_DrawRect(1, 52, 388, 270);

    //数据显示栏
    GUI_DrawRect(1, 270, 388, 318);

    //数据显示分栏
    GUI_DrawRect(126, 270, 252, 318);

    //画启动框
    //GUI_DrawRect(388, 220, 479, 319);

    //重绘
    //重绘倒计时
    if(strlen(time_buffer)==0 || !strcmp(time_buffer, "00:00:00")){
        TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_7), "00:00:00");
    }else {
        controlTime = 1;
        TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_7), time_buffer);
    }

 

emwin的WM_PAINT

上一篇:windows api(GDI)实现图片旋转


下一篇:为 API Gateway REST API 资源启用 CORS