⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wm_sample.c

📁 ucgui3.90a
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************                SEGGER MICROCONTROLLER SYSTEME GmbH                 **        Solutions for real time microcontroller applications        **                                                                    **                    emWin GSC sample code                           **                                                                    ***********************************************************************----------------------------------------------------------------------File        : WM_Sample.cPurpose     : Demonstrates the window manager----------------------------------------------------------------------*/#include <string.h>#include "GUI.h"#include "WM.h"/*********************************************************************       defines**********************************************************************/#define MSG_CHANGE_TEXT WM_USER+0#define SPEED 1250/*********************************************************************       static variables**********************************************************************/static char _acInfoText[40];static GUI_COLOR _WindowColor1 = GUI_GREEN;static GUI_COLOR _FrameColor1  = GUI_BLUE;static GUI_COLOR _WindowColor2 = GUI_RED;static GUI_COLOR _FrameColor2  = GUI_YELLOW;static GUI_COLOR _ChildColor   = GUI_YELLOW;static GUI_COLOR _ChildFrame   = GUI_BLACK;static WM_CALLBACK* _cbBkWindowOld;static WM_HWIN _hWindow1;static WM_HWIN _hWindow2;static WM_HWIN _hChild;/*********************************************************************       static code, helper functions**********************************************************************//*********************************************************************       _ChangeInfoText  Sends a message to the background window and invalidate it, so  the callback of the background window display the new text.*/static void _ChangeInfoText(char* pStr) {  WM_MESSAGE Message;  Message.MsgId  = MSG_CHANGE_TEXT;  Message.Data.p = pStr;  WM_SendMessage(WM_HBKWIN, &Message);  WM_InvalidateWindow(WM_HBKWIN);}/*********************************************************************       _DrawInfoText  Drawes the info text directly on the display. This function is for  the moments when no callback is set.*/static void _DrawInfoText(char* pStr) {  GUI_SetColor(GUI_WHITE);  GUI_SetFont(&GUI_Font24_ASCII);  GUI_DispStringHCenterAt("WindowManager - Sample", 160, 5);  GUI_SetFont(&GUI_Font8x16);  GUI_DispStringAtCEOL(pStr, 5, 40);}/*********************************************************************       _LiftUp*/static void _LiftUp(int dy) {  int i, tm;  for (i = 0; i < (dy/4); i++) {    tm = GUI_GetTime();    WM_MoveWindow(_hWindow1, 0, -4);    WM_MoveWindow(_hWindow2, 0, -4);    while ((GUI_GetTime() - tm) < 20) {      WM_Exec();    }  }}/*********************************************************************       _LiftDown*/static void _LiftDown(int dy) {  int i, tm;  for (i = 0; i < (dy/4); i++) {    tm = GUI_GetTime();    WM_MoveWindow(_hWindow1, 0, 4);    WM_MoveWindow(_hWindow2, 0, 4);    while ((GUI_GetTime() - tm) < 20) {      WM_Exec();    }  }}/*********************************************************************       static code, callbacks for windows**********************************************************************//*********************************************************************       _cbBkWindow*/static void _cbBkWindow(WM_MESSAGE* pMsg) {  switch (pMsg->MsgId) {  case MSG_CHANGE_TEXT:    strcpy(_acInfoText, pMsg->Data.p);  case WM_PAINT:    GUI_SetBkColor(GUI_BLACK);    GUI_Clear();    GUI_SetColor(GUI_WHITE);    GUI_SetFont(&GUI_Font24_ASCII);    GUI_DispStringHCenterAt("WindowManager - Sample", 160, 5);    GUI_SetFont(&GUI_Font8x16);    GUI_DispStringAt(_acInfoText, 5, 40);    break;  default:    WM_DefaultProc(pMsg);  }}/*********************************************************************       _cbWindow1*/static void _cbWindow1(WM_MESSAGE* pMsg) {  GUI_RECT Rect;  int x, y;  switch (pMsg->MsgId) {  case WM_PAINT:    WM_GetInsideRect(&Rect);    GUI_SetBkColor(_WindowColor1);    GUI_SetColor(_FrameColor1);    GUI_ClearRectEx(&Rect);    GUI_DrawRectEx(&Rect);    GUI_SetColor(GUI_WHITE);    GUI_SetFont(&GUI_Font24_ASCII);    x = WM_GetWindowSizeX(pMsg->hWin);    y = WM_GetWindowSizeY(pMsg->hWin);    GUI_DispStringHCenterAt("Window 1", x / 2, (y / 2) - 12);    break;  default:    WM_DefaultProc(pMsg);  }}/*********************************************************************       _cbWindow2*/static void _cbWindow2(WM_MESSAGE* pMsg) {  GUI_RECT Rect;  int x, y;  switch (pMsg->MsgId) {  case WM_PAINT:    WM_GetInsideRect(&Rect);    GUI_SetBkColor(_WindowColor2);    GUI_SetColor(_FrameColor2);    GUI_ClearRectEx(&Rect);    GUI_DrawRectEx(&Rect);    GUI_SetColor(GUI_WHITE);    GUI_SetFont(&GUI_Font24_ASCII);    x = WM_GetWindowSizeX(pMsg->hWin);    y = WM_GetWindowSizeY(pMsg->hWin);    GUI_DispStringHCenterAt("Window 2", x / 2, (y / 4) - 12);    break;  default:    WM_DefaultProc(pMsg);  }}/*********************************************************************       _cbChild*/static void _cbChild(WM_MESSAGE* pMsg) {  GUI_RECT Rect;  int x, y;  switch (pMsg->MsgId) {  case WM_PAINT:    WM_GetInsideRect(&Rect);    GUI_SetBkColor(_ChildColor);    GUI_SetColor(_ChildFrame);    GUI_ClearRectEx(&Rect);    GUI_DrawRectEx(&Rect);    GUI_SetColor(GUI_RED);    GUI_SetFont(&GUI_Font24_ASCII);    x = WM_GetWindowSizeX(pMsg->hWin);    y = WM_GetWindowSizeY(pMsg->hWin);    GUI_DispStringHCenterAt("Child window", x / 2, (y / 2) - 12);    break;  default:    WM_DefaultProc(pMsg);  }}/*********************************************************************       _cbDemoCallback1*/static void _cbDemoCallback1(WM_MESSAGE* pMsg) {  int x, y;  switch (pMsg->MsgId) {  case WM_PAINT:    GUI_SetBkColor(GUI_GREEN);    GUI_Clear();    GUI_SetColor(GUI_RED);    GUI_SetFont(&GUI_FontComic18B_1);    x = WM_GetWindowSizeX(pMsg->hWin);    y = WM_GetWindowSizeY(pMsg->hWin);    GUI_DispStringHCenterAt("Window 1\nanother Callback", x / 2, (y / 2) - 18);    break;  default:    WM_DefaultProc(pMsg);  }}/*********************************************************************       _cbDemoCallback2*/static void _cbDemoCallback2(WM_MESSAGE* pMsg) {  int x, y;  switch (pMsg->MsgId) {  case WM_PAINT:    GUI_SetBkColor(GUI_MAGENTA);    GUI_Clear();    GUI_SetColor(GUI_YELLOW);    GUI_SetFont(&GUI_FontComic18B_1);    x = WM_GetWindowSizeX(pMsg->hWin);    y = WM_GetWindowSizeY(pMsg->hWin);    GUI_DispStringHCenterAt("Window 2\nanother Callback", x / 2, (y / 4) - 18);    break;  default:    WM_DefaultProc(pMsg);  }}/*********************************************************************       static code, functions for demo**********************************************************************//*********************************************************************       _DemoSetDesktopColor  Demonstrates the use of WM_SetDesktopColor*/static void _DemoSetDesktopColor(void) {  GUI_SetBkColor(GUI_BLUE);  GUI_Clear();  _DrawInfoText("WM_SetDesktopColor()");  GUI_Delay(SPEED*3/2);  WM_SetDesktopColor(GUI_BLACK);  GUI_Delay(SPEED/2);  /* Set background color and invalidate desktop color.     This is needed for the later redrawing demo. */  GUI_SetBkColor(GUI_BLACK);  WM_SetDesktopColor(GUI_INVALID_COLOR);}/*********************************************************************       _DemoCreateWindow  Demonstrates the use of WM_CreateWindow*/static void _DemoCreateWindow(void) {  /* Set callback for background window */  _cbBkWindowOld = WM_SetCallback(WM_HBKWIN, _cbBkWindow);  /* Create windows */  _ChangeInfoText("WM_CreateWindow()");  GUI_Delay(SPEED);  _hWindow1 = WM_CreateWindow( 50,  70, 165, 100, WM_CF_SHOW | WM_CF_MEMDEV, _cbWindow1, 0);  GUI_Delay(SPEED/3);  _hWindow2 = WM_CreateWindow(105, 125, 165, 100, WM_CF_SHOW | WM_CF_MEMDEV, _cbWindow2, 0);  GUI_Delay(SPEED);}/*********************************************************************       _DemoCreateWindowAsChild  Demonstrates the use of WM_CreateWindowAsChild*/static void _DemoCreateWindowAsChild(void) {  /* Create windows */  _ChangeInfoText("WM_CreateWindowAsChild()");  GUI_Delay(SPEED);  _hChild = WM_CreateWindowAsChild(10, 50, 145, 40, _hWindow2, WM_CF_SHOW | WM_CF_MEMDEV, _cbChild, 0);  GUI_Delay(SPEED);}/*********************************************************************       _DemoInvalidateWindow  Demonstrates the use of WM_InvalidateWindow*/static void _DemoInvalidateWindow(void) {  _ChangeInfoText("WM_InvalidateWindow()");  _WindowColor1 = GUI_BLUE;  _FrameColor1  = GUI_GREEN;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -