硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4029|回复: 5
收起左侧

[emWin] 初始化新建一个对话框,按键触发再建一个对话框,结果在新建对话框范围外也刷新了

[复制链接]

1

主题

11

回帖

1

积分

新手上路

积分
1
发表于 2015-10-21 17:15:42 | 显示全部楼层 |阅读模式
外接实体按键,触发创建一个新的对话框,但新建对话框范围以外的屏也刷新了,导致之前的内容无序了。调试时发现回调函数里在对话框建立完成后一直触发WM_GET_ID事件,导致范围外的不良刷新。代码如下:
[s:138]
新人什么都没有,无以回报[s:129]
/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.22                          *
*        Compiled Jul  4 2013, 15:16:01                              *
*        (c) 2013 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
// USER END

#include "DIALOG.h"
#include "WindowDlg.h"
/*********************************************************************
*
*       Debug data
*
**********************************************************************
*/
// USER START (Optionally insert additional data declaration)
int logFlag = 0;
int _logBuff[100] = {0};
int _logIndex = 0;
// USER END
TagPosition _aPosition = { 0 };

WM_HWIN CreateChildWindow(void);
/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Text", ID_TEXT_0, 0, 0, 800, 40, 0, 0x64, 0 },
    { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_0, 0, 40, 800, 320, 0, 0x0, 0 },
    // USER START (Optionally insert additional widgets)
    // USER END
};
/*********************************************************************
*
*       _aChildDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aChildDialogCreate[] = {
    { WINDOW_CreateIndirect, "Window", ID_WINDOW_1, 240, 100, 320, 240, 0, 0x0, 0 },
    { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_1, 0, 0, 320, 240, 0, 0x0, 0 },
    // USER START (Optionally insert additional widgets)
    // USER END
};
/*********************************************************************
*
*       _aTable1
*/
GUI_ConstString _aTable1[16][8] = {
    { "1-01", "1-02", "1-03", "1-04", "1-05", "1-06", "1-07", "1-08" },
    { "1-09", "1-10", "1-11", "1-12", "1-13", "1-14", "1-15", "1-16" },
    { "1-17", "1-18", "1-19", "1-20", "1-21", "1-22", "1-23", "1-24" },
    { "1-25", "1-26", "1-27", "1-28", "1-29", "1-30", "1-31", "1-32" },
    { "2-01", "2-02", "2-03", "2-04", "2-05", "2-06", "2-07", "2-08" },
    { "2-09", "2-10", "2-11", "2-12", "2-13", "2-14", "2-15", "2-16" },
    { "2-17", "2-18", "2-19", "2-20", "2-21", "2-22", "2-23", "2-24" },
    { "2-25", "2-26", "2-27", "2-28", "2-29", "2-30", "2-31", "2-32" },
    { "3-01", "3-02", "3-03", "3-04", "3-05", "3-06", "3-07", "3-08" },
    { "3-09", "3-10", "3-11", "3-12", "3-13", "3-14", "3-15", "3-16" },
    { "3-17", "3-18", "3-19", "3-20", "3-21", "3-22", "3-23", "3-24" },
    { "3-25", "3-26", "3-27", "3-28", "3-29", "3-30", "3-31", "3-32" },
    { "4-01", "4-02", "4-03", "4-04", "4-05", "4-06", "4-07", "4-08" },
    { "4-09", "4-10", "4-11", "4-12", "4-13", "4-14", "4-15", "4-16" },
    { "4-17", "4-18", "4-19", "4-20", "4-21", "4-22", "4-23", "4-24" },
    { "4-25", "4-26", "4-27", "4-28", "4-29", "4-30", "4-31", "4-32" },
};

/*********************************************************************
*
*       _aTable2
*/
GUI_ConstString _aTable2[][8] = {
    { "2-01", "2-02", "2-03", "2-04", "2-05", "2-06", "2-07", "2-08" },
    { "2-09", "2-10", "2-11", "2-12", "2-13", "2-14", "2-15", "2-16" },
    { "2-17", "2-18", "2-19", "2-20", "2-21", "2-22", "2-23", "2-24" },
    { "2-25", "2-26", "2-27", "2-28", "2-29", "2-30", "2-31", "2-32" },
};

/*********************************************************************
*
*       _aTable3
*/
GUI_ConstString _aTable3[][8] = {
    { "3-01", "3-02", "3-03", "3-04", "3-05", "3-06", "3-07", "3-08" },
    { "3-09", "3-10", "3-11", "3-12", "3-13", "3-14", "3-15", "3-16" },
    { "3-17", "3-18", "3-19", "3-20", "3-21", "3-22", "3-23", "3-24" },
    { "3-25", "3-26", "3-27", "3-28", "3-29", "3-30", "3-31", "3-32" },
};

/*********************************************************************
*
*       _aTable4
*/
GUI_ConstString _aTable4[][8] = {
    { "4-01", "4-02", "4-03", "4-04", "4-05", "4-06", "4-07", "4-08" },
    { "4-09", "4-10", "4-11", "4-12", "4-13", "4-14", "4-15", "4-16" },
    { "4-17", "4-18", "4-19", "4-20", "4-21", "4-22", "4-23", "4-24" },
    { "4-25", "4-26", "4-27", "4-28", "4-29", "4-30", "4-31", "4-32" },
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
*       _cbChildDialog
*/
static void _cbChildDialog(WM_MESSAGE * pMsg) {
    WM_HWIN hItem;
        WM_HWIN hDlg;
    int     NCode;
    int     Id;
        //GUI_RECT *Rect;
    // USER START (Optionally insert additional variables)
    // USER END
        hDlg = pMsg->hWin;
        //if(logFlag)_logBuff[_logIndex++] = pMsg->MsgId;
    switch (pMsg->MsgId) {
    case WM_INIT_DIALOG:
        //
        // Initialization of 'Listview'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_1);
        LISTVIEW_AddColumn(hItem, 50, "Name", GUI_TA_HCENTER | GUI_TA_VCENTER);
        LISTVIEW_AddColumn(hItem, 50, "Value", GUI_TA_HCENTER | GUI_TA_VCENTER);
        LISTVIEW_AddRow(hItem, NULL);
        LISTVIEW_SetGridVis(hItem, 1);
        // USER START (Optionally insert additional code for further widget initialization)
        // USER END
        break;
    case WM_NOTIFY_PARENT:
        hItem = WM_GetFocussedWindow();
        Id = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        switch (Id) {
        case ID_LISTVIEW_0: // Notifications sent by 'Listview'
            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;
            case WM_NOTIFICATION_SEL_CHANGED:
                // 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;
        case WM_KEY:
          //hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_1);
          GUI_EndDialog(hDlg,0);
          WM_SetFocus(WM_GetDialogItem(WM_HBKWIN,ID_LISTVIEW_0));
          break;
        // USER START (Optionally insert additional message handling)
        // USER END
    case WM_GET_ID:
          //pMsg->Data.v = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_1);
          break;
        default:
        WM_DefaultProc(pMsg);
        break;
    }
}
/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int     NCode;
  int     Id;
  int     i,j;
  // USER START (Optionally insert additional variables)
  // USER END
  
  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    //
    // Initialization of 'Window'
    //
    hItem = pMsg->hWin;
    WINDOW_SetBkColor(hItem, 0x00FFFFFF);
    //
    // Initialization of 'Text'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
    TEXT_SetTextColor(hItem, 0x00000000);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
    TEXT_SetFont(hItem, GUI_FONT_32B_ASCII);
    TEXT_SetText(hItem, "Building Fir Door Monitor&Control System");
    //
    // Initialization of 'Listview'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
    LISTVIEW_SetBkColor(hItem, LISTVIEW_CI_UNSEL, GUI_GREEN);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_AddColumn(hItem, 100, " ", GUI_TA_HCENTER | GUI_TA_VCENTER);
    LISTVIEW_SetGridVis(hItem, 1);
    LISTVIEW_SetHeaderHeight(hItem, 0);
    LISTVIEW_SetRowHeight(hItem, 80);
    LISTVIEW_SetFont(hItem, GUI_FONT_32B_1);
    for (i = 0; i < 4; i++){
      LISTVIEW_AddRow(hItem, _aTable1);
      //GUI_Delay(1);
    }
    // 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_LISTVIEW_0: // Notifications sent by 'Listview'
      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;
      case WM_NOTIFICATION_SEL_CHANGED:
        // 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)
    // USER END
  case WM_KEY:
//    Id = WM_GetId(pMsg->hWinSrc);
//    switch(Id){
//    case ID_LISTVIEW_0:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
      switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key){
      case GUI_KEY_F3:
        if ((_aPosition.x - 1) < 0)_aPosition.x = 15;
        else _aPosition.x--;
        if (_aPosition.x/4 != _aPosition.page){
          _aPosition.page = _aPosition.x / 4;
          for (i = 0; i < 4;i++){
            for (j = 0; j < 8; j++){
              LISTVIEW_SetItemText(hItem, j, i, _aTable1[(_aPosition.page*4) + i][j]);
            }
          }
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, 0, LISTVIEW_CI_UNSEL, GUI_BLACK);
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, 3, LISTVIEW_CI_UNSEL, GUI_WHITE);
        }
        else{
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, (_aPosition.x-_aPosition.page*4)+1, LISTVIEW_CI_UNSEL, GUI_BLACK);
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, (_aPosition.x-_aPosition.page*4), LISTVIEW_CI_UNSEL, GUI_WHITE);
        }
        break;
      case GUI_KEY_F4:
        if ((_aPosition.x + 1) > 15)_aPosition.x = 0;
        else _aPosition.x++;
        if (_aPosition.x / 4 != _aPosition.page){
          _aPosition.page = _aPosition.x / 4;
          for (i = 0; i < 4; i++){
            for (j = 0; j < 8; j++){
              LISTVIEW_SetItemText(hItem, j, i, _aTable1[(_aPosition.page*4) + i][j]);
            }
          }
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, 3, LISTVIEW_CI_UNSEL, GUI_BLACK);
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, 0, LISTVIEW_CI_UNSEL, GUI_WHITE);
        }
        else{
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, (_aPosition.x-_aPosition.page*4) - 1, LISTVIEW_CI_UNSEL, GUI_BLACK);
          LISTVIEW_SetItemTextColor(hItem, _aPosition.y, (_aPosition.x-_aPosition.page*4), LISTVIEW_CI_UNSEL, GUI_WHITE);
        }
        break;
      case GUI_KEY_F1:
        LISTVIEW_SetItemTextColor(hItem, _aPosition.y, _aPosition.x, LISTVIEW_CI_UNSEL, GUI_BLACK);
        if ((_aPosition.y - 1) <0)_aPosition.y = 7;
        else _aPosition.y--;
        LISTVIEW_SetItemTextColor(hItem, _aPosition.y, _aPosition.x, LISTVIEW_CI_UNSEL, GUI_WHITE);
        break;
      case GUI_KEY_F2:
        LISTVIEW_SetItemTextColor(hItem, _aPosition.y, _aPosition.x, LISTVIEW_CI_UNSEL, GUI_BLACK);
        if ((_aPosition.y + 1) >7)_aPosition.y = 0;
        else _aPosition.y++;
        LISTVIEW_SetItemTextColor(hItem, _aPosition.y, _aPosition.x, LISTVIEW_CI_UNSEL, GUI_WHITE);
        break;
      case GUI_KEY_OK:
//        hItem = WM_GetDialogItem(WM_HBKWIN, ID_WINDOW_0);
//        hItem = LISTVIEW_CreateEx(200,50,100,150,hItem,WM_CF_SHOW,0,ID_LISTVIEW_1);
//        LISTVIEW_AddColumn(hItem, 50, "Name", GUI_TA_HCENTER | GUI_TA_VCENTER);
//        LISTVIEW_AddColumn(hItem, 50, "Value", GUI_TA_HCENTER | GUI_TA_VCENTER);
//        LISTVIEW_SetGridVis(hItem, 1);
//        LISTVIEW_SetRowHeight(hItem, 30);
        CreateChildWindow();
        logFlag = 1;
        break;
      }
//      break;
//    case ID_LISTVIEW_1:
//      
//      break;
//    }
   
    break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateWindow
*/
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
  WM_HWIN hWin;
  
  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}
/*********************************************************************
*
*       CreateChildWindow
*/

WM_HWIN CreateChildWindow(void) {
    WM_HWIN hWin,htem;
    hWin = WM_GetDialogItem(WM_HBKWIN, ID_LISTVIEW_0);
    htem = GUI_CreateDialogBox(_aChildDialogCreate, GUI_COUNTOF(_aChildDialogCreate), _cbChildDialog, hWin, 0, 0);
    //WM_MakeModal(hWin);
       // WM_InvalidateWindow(hWin);
        //WM_Paint(hWin);
        
        return htem;
}

// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
发表于 2015-10-21 17:39:31 | 显示全部楼层
这个函数有问题:hWin = WM_GetDialogItem(WM_HBKWIN, ID_LISTVIEW_0);  
这里是要获取 ID_LISTVIEW_0的句柄吗,这个ID_LISTVIEW_0是建立在这个函数
CreateWindow创建的对话框上面,而不是桌面窗口WM_HBKWIN,上面。
回复

使用道具 举报

1

主题

11

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2015-10-22 09:00:28 | 显示全部楼层

回 eric2013 的帖子

eric2013:
这个函数有问题:hWin = WM_GetDialogItem(WM_HBKWIN, ID_LISTVIEW_0);  
这里是要获取 ID_LISTVIEW_0的句柄吗,这个ID_LISTVIEW_0是建立在这个函数
CreateWindow创建的对话框上面,而不是桌面窗口WM_HBKWIN,上面。

您的意思是CreateWindow()创建对话框的所有组件的父窗口都是这个对话框,不是桌面窗口。我把它修改成
hWin = WM_GetDialogItem(_hParentDlg, ID_LISTVIEW_0);
htem = GUI_CreateDialogBox(_aChildDialogCreate, GUI_COUNTOF(_aChildDialogCreate), _cbChildDialog, hWin, 0, 0);
_hParentDlg是执行CreateWindow()时返回的对话框句柄。可是新建对话框之外的区域还是刷新了。
图片如下:

初始对话框

初始对话框

新建对话框后

新建对话框后
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
发表于 2015-10-23 00:29:07 | 显示全部楼层

回 犹豫的大三 的帖子

犹豫的大三:您的意思是CreateWindow()创建对话框的所有组件的父窗口都是这个对话框,不是桌面窗口。我把它修改成
hWin = WM_GetDialogItem(_hParentDlg, ID_LISTVIEW_0);
htem = GUI_CreateDialogBox(_aChildDialogCreate, GUI_COUNTOF(_aChildDialogCreate), _cbChildDialog, hWin, 0, 0);
.. (2015-10-22 09:00) 
估计listview控件不支持作为父窗口。
你可以直接这样创建:
htem = GUI_CreateDialogBox(_aChildDialogCreate, GUI_COUNTOF(_aChildDialogCreate), _cbChildDialog,_hParentDlg , 0, 0);
回复

使用道具 举报

1

主题

11

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2015-10-26 11:00:34 | 显示全部楼层

回 eric2013 的帖子

eric2013:估计listview控件不支持作为父窗口。
你可以直接这样创建:
htem = GUI_CreateDialogBox(_aChildDialogCreate, GUI_COUNTOF(_aChildDialogCreate), _cbChildDialog,_hParentDlg , 0, 0); (2015-10-23 00:29) 
麻烦eric大哥了,我今天换了个屏试了试,发现没有这个问题了。[s:139]竟然是屏的问题,浪费Eric大哥的时间了,是在抱歉啦!
这是一个教训,以后不会在一棵树上吊死的,要多换几棵树试试![s:132]
回复

使用道具 举报

4

主题

64

回帖

76

积分

初级会员

积分
76
发表于 2015-10-27 13:42:56 | 显示全部楼层

回 犹豫的大三 的帖子

犹豫的大三:麻烦eric大哥了,我今天换了个屏试了试,发现没有这个问题了。[s:139]竟然是屏的问题,浪费Eric大哥的时间了,是在抱歉啦!
这是一个教训,以后不会在一棵树上吊死的,要多换几棵树试试![s:132] (2015-10-26 11:00) 
对,多试几颗,总有一颗能吊死[s:123]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-16 11:42 , Processed in 0.059968 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表