Difference between revisions of "BUTTON - Usage (Sample)"
Line 20: | Line 20: | ||
This sample demonstrates how to use a BUTTON widget. |
This sample demonstrates how to use a BUTTON widget. |
||
+ | |||
+ | == Demo == |
||
+ | |||
+ | <html><iframe src="https://wiki.segger.com/demo/emwin/BUTTON_Usage/BUTTON_Usage.html" width="480" height="272" style="border: 1px #c0c0c0 solid;" marginwidth="0" marginheight="0" hspace="0" vspace="0" scrolling="no"> </iframe></html> |
||
== Code == |
== Code == |
Latest revision as of 16:07, 7 March 2022
BUTTON_Usage.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | BUTTON_Usage.c |
This sample demonstrates how to use a BUTTON widget.
Demo
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 : BUTTON_Usage.c
Purpose : Sample that demonstrates the usage of a BUTTON widget.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_BUTTON 1
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
static void _cbWin(WM_MESSAGE * pMsg) {
int Id, NCode;
static int Clicked, Released;
BUTTON_Handle hButton;
char acBuffer[64];
switch(pMsg->MsgId) {
case WM_CREATE:
//
// Create a button as child of this window.
//
hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, ID_BUTTON);
BUTTON_SetText(hButton, "Click me");
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetColor(GUI_BLACK);
if(Clicked) {
sprintf(acBuffer, "Button was clicked at: %d.", Clicked);
GUI_DispStringAt(acBuffer, 10, 40);
}
if(Released) {
sprintf(acBuffer, "Button was released at: %d.", Released);
GUI_DispStringAt(acBuffer, 10, 60);
}
break;
case WM_NOTIFY_PARENT:
//
// Since the button is a child of this window, reacts on the button
// are sent to its parent window.
//
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
//
// Check if notification was sent from the button.
//
switch(Id) {
case ID_BUTTON:
//
// Check for the correct notification code.
//
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
Clicked = GUI_GetTime();
WM_InvalidateWindow(pMsg->hWin);
break;
case WM_NOTIFICATION_RELEASED:
Released = GUI_GetTime();
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init emWin.
//
GUI_Init();
//
// Create window.
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/