React on messages (Sample)
WIDGET_ReactOnMessages.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | WIDGET_ReactOnMessages.c |
This sample demonstrates how the application can react on messages sent by widgets or windows.
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : WIDGET_ReactOnMessages.c
Purpose : Sample that shows how to react on different messages
from widgets.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define BUTTON_SIZE 50
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
WM_HWIN hButton;
int Id;
int NCode;
static int Clicked;
switch (pMsg->MsgId) {
case WM_CREATE:
Clicked = -1;
//
// Create a button
//
hButton = BUTTON_CreateEx(10, 10, BUTTON_SIZE, BUTTON_SIZE, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetColor(GUI_BLACK);
if (Clicked == 1) {
GUI_DispStringAt("The button has been clicked.", 10, 70);
} else if (Clicked == 0) {
GUI_DispStringAt("The button has been released.", 10, 70);
}
break;
case WM_NOTIFY_PARENT: // Catches notifications of all widgets within this window
Id = WM_GetId(pMsg->hWinSrc); // Get ID of source window that sent the message (button)
NCode = pMsg->Data.v; // Data.v contains the notification code
switch (Id) {
case GUI_ID_BUTTON0:
switch (NCode) {
case WM_NOTIFICATION_CLICKED: // When the widget has been touched
Clicked = 1;
WM_InvalidateWindow(pMsg->hWin);
break;
case WM_NOTIFICATION_RELEASED: // When the widget has been released
Clicked = 0;
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init emWin.
//
GUI_Init();
//
// Create parent window.
//
WM_CreateWindow(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/