WM create windows (Sample)

From SEGGER Wiki
Jump to: navigation, search
WM_CreateWindows.c
WM CreateWindows.png
File(s) required
  • WM_CreateWindows.c
Runs in simulation Yes
Runs on target Yes
Download WM_CreateWindows.c

This sample shows how windows can be created in emWin.

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        : WM_CreateWindows.c
Purpose     : Sample that demonstrates how to create windows in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

/*********************************************************************
*
*       _cbWin
*
* Function description
*   Callback routine for the window created in MainTask. All messages
*   sent to the sample window are handled in this routine.
*
* Parameters
*   pMsg   : Pointer to a message structure sent to the window.
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_CREATE:
    //
    // We land here right after the window has been created.
    //
    break;
  case WM_PAINT:
    //
    // This case is called everytime the window has to be redrawn
    //
    GUI_SetBkColor(GUI_WHITE);
    GUI_Clear();
    GUI_SetColor(GUI_BLACK);
    GUI_DispStringAt("Sample window", 10, 10);
    break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  GUI_Init();

  //
  // Create a window as a child of the background window
  //
  WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);

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

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