CHECKBOX - Usage (Sample)

From SEGGER Wiki
Jump to: navigation, search
CHECKBOX_Usage.c
CHECKBOX Usage.gif
File(s) required
  • CHECKBOX_Usage.c
Runs in simulation Yes
Runs on target Yes
Download CHECKBOX_Usage.c

This sample demonstrates the usage of a CHECKBOX 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        : CHECKBOX_Usage.c
Purpose     : Sample that demonstrates the usage of CHECKBOX widgets
              in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  static WM_HWIN hBox;
  int            NCode, Id;
  char           acBuffer[32];
  int            State;

  switch(pMsg->MsgId) {
  case WM_CREATE:
    //
    // Create CHECKBOX widget.
    //
    hBox = CHECKBOX_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_CHECK0);
    //
    // Edit widget properties.
    //
    CHECKBOX_SetText(hBox, "Check");
    CHECKBOX_SetTextColor(hBox, GUI_BLACK);
    CHECKBOX_SetFont(hBox, &GUI_Font16_1);
    //
    // Set number of possible states to 3 (if needed)
    // The minimum number of states is 2 and the maximum is 3.
    //
    CHECKBOX_SetNumStates(hBox, 3);
    //
    // Manually set the state
    //
    CHECKBOX_SetState(hBox, 1);
    break;
  case WM_PAINT:
    GUI_SetBkColor(GUI_WHITE);
    GUI_Clear();
    //
    // Display current CHECKBOX state.
    //
    GUI_SetFont(&GUI_Font16_1);
    GUI_SetColor(GUI_BLACK);
    State = CHECKBOX_GetState(hBox);
    sprintf(acBuffer, "State of checkbox: %d", State);
    GUI_DispStringAt(acBuffer, 10, 50);
    break;
  case WM_NOTIFY_PARENT:
    //
    // Get Id of sender window and notification code.
    //
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch (Id) {
    case GUI_ID_CHECK0:
      switch(NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
        //
        // When the value of the checkbox changed, redraw parent window to update the display of the state.
        //
        WM_InvalidateWindow(pMsg->hWin);
        break;
      }
      break;
    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  //
  // Init GUI.
  //
  GUI_Init();
  //
  // Create parent window.
  //
  WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);

  while (1) {
    GUI_Delay(100);
  }
}

/*************************** End of file ****************************/