35.2 官方WM_LateClipping.c实例 这个Demo中涉及到了BOTTON和FrameWin的创建及其使用,如果初学的同学不理解这部分内容没有关系,后面的教程中会跟大家详细的讲解这部分知识。这里大家重点是看回调函数。Demo所在位置:
源代码如下:
- #include "GUI.h"
- #include "WM.h"
- #include "FRAMEWIN.h"
- #include "BUTTON.h"
-
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- static WM_HWIN _hWin1;
- static WM_HWIN _hWin2;
- static WM_HWIN _hBut1;
- static WM_HWIN _hBut2;
- static int _PaintCount1;
- static int _PaintCount2;
-
- static GUI_COLOR _aColors[] = {
- 0x0000FF, 0x00FF00, 0xFF0000, 0x00FFFF, 0xA000A0, 0xFFFF00
- };
-
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _cbBkWin
- */
- static void _cbBkWin(WM_MESSAGE* pMsg) {(1)
- switch(pMsg->MsgId) {
- case WM_PAINT:(2)
- GUI_SetBkColor(GUI_BLACK);
- GUI_Clear();
- GUI_SetColor(0x0060FF);
- GUI_DispStringAt("PaintCount (Early):", 0, 0);
- GUI_DispDecAt(_PaintCount1, 120, 0, 5);
- GUI_SetColor(0x00FFC0);
- GUI_DispStringAt("PaintCount (Late):", 0, 12);
- GUI_DispDecAt(_PaintCount2, 120, 12, 5);
- break;
- case WM_NOTIFY_PARENT:
- if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
- if (pMsg->hWinSrc == _hBut1) {(3)
- WM_InvalidateWindow(_hWin1);
- WM_InvalidateWindow(_hWin2);
- } else if (pMsg->hWinSrc == _hBut2) {(4)
- _PaintCount1 = 0;
- _PaintCount2 = 0;
- WM_InvalidateWindow(pMsg->hWin);
- }
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*********************************************************************
- *
- * _cbTop
- */
- static void _cbTop(WM_MESSAGE* pMsg) {(5)
- switch(pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(GUI_MAGENTA);
- GUI_Clear();
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*********************************************************************
- *
- * _cbFrameWin1
- */
- static void _cbFrameWin1(WM_MESSAGE* pMsg) { (6)
- switch(pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(_aColors[_PaintCount1 % 6]);
- GUI_Clear();
- GUI_SetColor(0x0060FF);
- GUI_FillCircle(25, 25, 15);
- GUI_SetColor(GUI_BLACK);
- GUI_DrawCircle(25, 25, 15);
- _PaintCount1++;
- WM_InvalidateWindow(WM_HBKWIN);
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*********************************************************************
- *
- * _cbFrameWin2
- */
- static void _cbFrameWin2(WM_MESSAGE* pMsg) {(7)
- switch(pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(_aColors[_PaintCount2 % 6]);
- GUI_Clear();
- GUI_SetColor(0x00FFC0);
- GUI_FillCircle(25, 25, 15);
- GUI_SetColor(GUI_BLACK);
- GUI_DrawCircle(25, 25, 15);
- _PaintCount2++;
- WM_InvalidateWindow(WM_HBKWIN);
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*********************************************************************
- *
- * _ShowDemo
- */
- static void _ShowDemo(void) {
- WM_HWIN hWin0;
- WM_HWIN hWin1;
- WM_HWIN hWin2;
- WM_HWIN hFrame1;
- WM_HWIN hFrame2;
- WM_HWIN hClient1;
- WM_HWIN hClient2;
-
- WM_SetCallback(WM_HBKWIN, _cbBkWin);(8)
- hFrame1 = FRAMEWIN_CreateEx( 10, 30, 140, 140, 0, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "Early Clipping", _cbFrameWin1);
- hFrame2 = FRAMEWIN_CreateEx(170, 30, 140, 140, 0, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "Late Clipping", _cbFrameWin2);
- hClient1 = WM_GetClientWindow(hFrame1);
- hClient2 = WM_GetClientWindow(hFrame2);
- _hWin1 = WM_CreateWindowAsChild(0, 0, WM_GetWindowSizeX(hClient1), WM_GetWindowSizeY(hClient1), hClient1, WM_CF_SHOW, _cbFrameWin1, 0);
- _hWin2 = WM_CreateWindowAsChild(0, 0, WM_GetWindowSizeX(hClient2), WM_GetWindowSizeY(hClient2), hClient2, WM_CF_SHOW | WM_CF_LATE_CLIP, _cbFrameWin2, 0);
- _hBut1 = BUTTON_CreateEx( 10, 210, 140, 20, 0, WM_CF_SHOW, 0, 1);
- _hBut2 = BUTTON_CreateEx(170, 210, 140, 20, 0, WM_CF_SHOW, 0, 2);
- hWin0 = FRAMEWIN_CreateEx( 60, 80, 40, 40, 0, WM_CF_SHOW | WM_CF_STAYONTOP, FRAMEWIN_CF_MOVEABLE, 0, "Top 0", _cbTop);
- hWin1 = FRAMEWIN_CreateEx(220, 80, 40, 40, 0, WM_CF_SHOW | WM_CF_STAYONTOP, FRAMEWIN_CF_MOVEABLE, 0, "Top 1", _cbTop);
- hWin2 = FRAMEWIN_CreateEx(140, 170, 40, 40, 0, WM_CF_SHOW | WM_CF_STAYONTOP, FRAMEWIN_CF_MOVEABLE, 0, "Top 2", _cbTop);
- FRAMEWIN_SetResizeable(hWin0, 1);
- FRAMEWIN_SetResizeable(hWin1, 1);
- FRAMEWIN_SetResizeable(hWin2, 1);
- BUTTON_SetText(_hBut1, "Invalidate");
- BUTTON_SetText(_hBut2, "Reset counters");
- while(1) {
- GUI_Delay(50);
- }
- }
-
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- GUI_Init();
- while(1) {
- _ShowDemo();
- }
- }
复制代码
1. 桌面窗口回调函数。 2. 回调函数中重绘部分的代码。 3. 由于两个按钮是创建在桌面窗口上面的,所以按钮的WM_NOTIFICATION_RELEASED(通知代码消息类型)是在桌面窗口的回调函数中。这个按钮按下后将_hWin1和_hWin2无效。从而会执行这两个窗口的背景重绘功能。 4. 同上,只不过这里实现的功能是将两个计数值清零,并使桌面窗口无效,从而执行桌面窗口的重绘消息。 5. 这个是hWin0,hWin1,hWin2的回调函数。 6. 这个是hFrame1的回调函数。回调函数中主要实现了重绘消息。重绘消息中记录了重绘的次数,并根据重绘次数修改背景颜色。 7. 这个是hFrame2的回调函数。回调函数中主要实现了重绘消息。重绘消息中记录了重绘的次数,并根据重绘次数修改背景颜色。 8. (1) 先创建两个FrameWin (2) 分别在这两个FrameWin中创建两个子窗口。 (3) 创建两个按钮。 (4) 创建三个FrameWin。 9. 这个Demo还有一个控件剪切问题,后面会专门抽一期教程专门跟大家讲解这个。 这个例子对于研究回调函数函数还是非常好的,大家可以在这个例子的基础上做一些修改,实现一些功能,这个Demo的显示效果如下: |