WM child windows (Sample)

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

This sample demonstrates how child windows can be created using emWin's Window Manager.

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_ChildWindows.c
Purpose     : Sample that demonstrates how child windows work and how
              they are created in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

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

/*********************************************************************
*
*       _cbChildWin
*/
static void _cbChildWin(WM_MESSAGE * pMsg) {
  WM_HWIN hChild;

  switch (pMsg->MsgId) {
  case WM_PAINT:
    //
    // Draw something
    //
    GUI_SetBkColor(GUI_RED);
    GUI_Clear();
    GUI_SetColor(GUI_BLACK);
    GUI_DispStringAt("Child window", 10, 10);
    break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  WM_HWIN hChild;

  switch (pMsg->MsgId) {
  case WM_CREATE:
    //
    // Create child window
    // This window is set as the parent of the child window
    //
    hChild = WM_CreateWindowAsChild(25, 25, 100, 50, pMsg->hWin, WM_CF_SHOW, _cbChildWin, 0);
    break;
  case WM_PAINT:
    //
    // Draw something
    //
    GUI_SetBkColor(GUI_WHITE);
    GUI_Clear();
    GUI_SetColor(GUI_BLACK);
    GUI_DispStringAt("Parent window", 10, 10);
    break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

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

  //
  // Create a window
  //
  WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, _cbWin, 0);

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

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