硬汉嵌入式论坛

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

[emWin] emWin消息结构体中关于目标窗口、源窗口问题

[复制链接]

1

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2014-7-21 10:32:32 | 显示全部楼层 |阅读模式
emWin消息结构体中关于目标窗口、源窗口问题
  1. /*********************************************************************
  2. *                SEGGER Microcontroller GmbH & Co. KG                *
  3. *        Solutions for real time microcontroller applications        *
  4. **********************************************************************
  5. *                                                                    *
  6. *        (c) 1996 - 2014  SEGGER Microcontroller GmbH & Co. KG       *
  7. *                                                                    *
  8. *        Internet: www.segger.com    Support:  support@segger.com    *
  9. *                                                                    *
  10. **********************************************************************
  11. ** emWin V5.24 - Graphical user interface for embedded applications **
  12. emWin is protected by international copyright laws.   Knowledge of the
  13. source code may not be used to write a similar product.  This file may
  14. only be used in accordance with a license and should not be re-
  15. distributed in any way. We appreciate your understanding and fairness.
  16. ----------------------------------------------------------------------
  17. File        : WIDGET_Edit.c
  18. Purpose     : Example demonstrating the use of a EDIT widget
  19. Requirements: WindowManager - (x)
  20.               MemoryDevices - ( )
  21.               AntiAliasing  - ( )
  22.               VNC-Server    - ( )
  23.               PNG-Library   - ( )
  24.               TrueTypeFonts - ( )
  25. ----------------------------------------------------------------------
  26. */
  27. #include "GUI.h"
  28. #include "EDIT.h"
  29. /*********************************************************************
  30. *
  31. *       Defines
  32. *
  33. **********************************************************************
  34. */
  35. #define WM_APP_SHOW_TEXT (WM_USER + 0)
  36. #define TEXT_MAXLEN      40
  37. /*********************************************************************
  38. *
  39. *       Static code
  40. *
  41. **********************************************************************
  42. */
  43. /*********************************************************************
  44. *
  45. *       _cbBk
  46. */
  47. static void _cbBk(WM_MESSAGE * pMsg) {
  48.   static WM_HWIN hEdit=0;
  49.   static U8      ShowText=0;
  50.   char           aBuffer[TEXT_MAXLEN];
  51.   //hEdit    = 0;
  52.   //ShowText = 0;
  53.   switch (pMsg->MsgId) {
  54.   case WM_PAINT:
  55.     GUI_SetBkColor(GUI_RED);
  56.     GUI_Clear();
  57.     GUI_SetFont(&GUI_Font24_ASCII);
  58.     GUI_DispStringHCenterAt("WIDGET_Edit - Sample", 160, 5);
  59.     GUI_SetFont(&GUI_Font8x16);
  60.     if (ShowText) {
  61.       GUI_DispStringHCenterAt("The string you have modified is:", 160, 90);
  62.       EDIT_GetText(hEdit, aBuffer, TEXT_MAXLEN);//EDIT_GetText检索指定编辑字段的用户输入
  63.       GUI_DispStringHCenterAt(aBuffer, 160, 110);//GUI_DispStringHCenterAt在指定位置水平居中显示字符串
  64.     } else {
  65.       GUI_DispStringHCenterAt("Use keyboard to modify string...", 160, 90);
  66.     }
  67.     break;
  68.     /*
  69.     桌面窗口中自定义的消息,如果收到这个消息后,隐藏编辑框,
  70.     设置ShowText=1,然后将桌面窗口设置为无效,从而会执行桌面窗口的WM_PAINT消息,
  71.     最后给桌面窗口建立一个定时器,时间是3000ms
  72.     */
  73.   case WM_APP_SHOW_TEXT:
  74.     if (hEdit == 0) {
  75.       hEdit = pMsg->hWinSrc;
  76.     }
  77.     WM_HideWindow(hEdit);
  78.     ShowText = 1;
  79.     WM_InvalidateWindow(WM_HBKWIN);
  80.     WM_CreateTimer(WM_HBKWIN, 0, 3000, 0);//创建定时器,其功能是经过指定周期后,向指定窗口发送消息。该定时器与指定窗口相关联。向句柄为WM_HBKWIN的窗口发送定时消息
  81.     break;
  82.   case WM_TIMER:
  83.     ShowText = 0;
  84.     WM_InvalidateWindow(WM_HBKWIN);
  85.     WM_ShowWindow(hEdit);
  86.     break;
  87.   default:
  88.     WM_DefaultProc(pMsg);
  89.   }
  90. }
  91. /*********************************************************************
  92. *
  93. *       _cbEdit
  94. *   编辑框回调函数
  95. */
  96. static void _cbEdit(WM_MESSAGE * pMsg) {
  97.   const WM_KEY_INFO * pInfo;
  98.   WM_MESSAGE          Msg;
  99.   switch (pMsg->MsgId) {
  100.   case WM_KEY:
  101.     pInfo = (WM_KEY_INFO *)pMsg->Data.p;
  102.     if (pInfo->Key == GUI_KEY_ENTER) {
  103.       if (pInfo->PressedCnt == 0) {//PressedCnt按键被放开
  104.         Msg.MsgId   = WM_APP_SHOW_TEXT;
  105.         Msg.hWinSrc = pMsg->hWin;//?
  106.         WM_SendMessage(WM_HBKWIN, &Msg);//
  107.         return;
  108.       }
  109.     }
  110.   }
  111.   EDIT_Callback(pMsg);//emWin库中自带的编辑框回调函数EDIT_Callback(pMsg)
  112. }
  113. /*********************************************************************
  114. *
  115. *       Public code
  116. *
  117. **********************************************************************
  118. */
  119. /*********************************************************************
  120. *
  121. *       MainTask
  122. */
  123. void MainTask(void) {
  124.   EDIT_Handle hEdit;
  125.   GUI_Init();
  126.   WM_SetCallback(WM_HBKWIN, _cbBk);//设置桌面窗口的回调函数
  127.   hEdit = EDIT_CreateEx(50, 110, 220, 25, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT0, TEXT_MAXLEN);//在指定位置创建指定尺寸的EDIT 小工具,父窗口句柄为WM_HBKWIN,编辑框ID为GUI_ID_EDIT0
  128.   WM_SetCallback(hEdit, _cbEdit);//设置编辑框的回调函数
  129.   EDIT_SetText(hEdit, "Press <ENTER> when done...");
  130.   EDIT_SetFont(hEdit, &GUI_Font8x16);
  131.   EDIT_SetTextColor(hEdit, 0, GUI_RED);
  132.   EDIT_EnableBlink(hEdit, 300, 1);//EDIT_EnaBleBlink() 启用/ 禁用闪烁光标,启用光标闪烁,闪烁周期为300
  133.   while (1) {
  134.     GUI_Delay(10);
  135.   }
  136. }
  137. /*************************** End of file ****************************/
复制代码
根据数据手册,WM_MESSAGE结构体如下:
WM_MESSAGE 的元素.png
那么在代码中134行设置桌面窗口的回调函数时将_cbBk设置为句柄为WM_HBKWIN的桌面窗口回调函数,再追踪到_chBk定义处,79行“hEdit = pMsg->hWinSrc”这行代码是将消息pMsg的源窗口句柄赋值为hEdit,那么我的问题就来了,这里的源窗口句柄hWinSrc到底是指的哪个,也就是问这个回调函数_chBk所接受到的消息由谁发财的?
同理136行设置编辑框的回调函数_cbEdit,追踪到_cbEdit定义处,111行“Msg.hWinSrc = pMsg->hWin”,pMsg的目标窗口pMsg->hWin又是指的哪个?是在主函数创建的编辑框句柄hEdit(135行“hEdit = EDIT_CreateEx(50, 110, 220, 25, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT0, TEXT_MAXLEN)”)吗?
急求各位解答,在线等!!!!

回复

使用道具 举报

4

主题

80

回帖

4

积分

初级会员

积分
4
发表于 2014-7-21 10:38:46 | 显示全部楼层
你可以这样理解,pMsg->hWin 这个目标窗口表示你创建的,pMsg->hWinSrc这个源窗口表示在目标窗口下的子窗口。通过这个pMsg消息通知父窗口,
下面的子窗口有什么动静。
且行且珍惜~
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 22:22 , Processed in 0.183160 second(s), 33 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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