[emWin tutorial version 3] Chapter 42 callback message types of emWin6.x Window Manager

The tutorial is constantly updated: The third version of emWin tutorial and ThreadX GUIX tutorial started, with a two pronged approach. GUIX was updated to chapter 28 and emWin was updated to Chapter 48 (2021-09-13) - UCOS & ucGUI & emWin & embos & touchgfx & ThreadX - tough guy embedded Forum - Powered by Discuz!http://www.armbbs.cn/forum.php?mod=viewthread&tid=98429

chapter42        emWin6.x Window Manager callback message type

This chapter explains the message types of emWin window manager. If the window manager is the core of emWin, the message mechanism is the core of window management. This knowledge is very important. The controls and dialog boxes learned in the following chapters are based on messages, which must be mastered by beginners.

Before learning this chapter, you must give priority to learning the basic knowledge of window manager in Chapter 41.

catalogue

42.1 important tips for beginners

42.2 introduction to message mechanism

42.3 message structure

42.4 message type

42.5 system type message instance

42.6 pointer input device (PID) type message example

42.7 notification code type message instance

42.8 summary

42.1 important tips for beginners

1,   Although this chapter is very important, beginners don't have to worry. Through this chapter, they have a preliminary understanding of the message types of the window manager. With the study of the following chapters, they will gradually master it, because the message mechanism is basically used in each of the following chapters.

2,   The relevant knowledge of message types in the window manager is explained in the emWin manual. The following figure is the explanation position of the Chinese version

 

The following figure shows the explanation position of the English version of the manual:

 

42.2 introduction to message mechanism

The message mechanism is the core of emWin. The simple understanding is as follows: for example, operate a touch interface with buttons, scroll bars, edit boxes and other controls. When users touch a control, they will trigger the window manager to process these messages and jump to the corresponding messages of the window callback function. These messages are the functions to be added. For example, if we want to flip the LED after clicking the button, we can add the LED flip function to the button message of the callback function in the window where the button is located to achieve this effect. The user does not need to take care of how the specific message is transmitted. Just add a function to the corresponding message of the callback function. From this point of view, the message mechanism is relatively easy to master.

For beginners, it's OK to understand this and further strengthen their understanding through the following practical examples. In addition, to implement the message mechanism, there must be a message structure variable to indicate the message type and some other related functions. This part of knowledge is explained below.

42.3 message structure

When the callback function is called, it receives the message specified with its pMsg parameter. This message is actually a WM_MESSAGE data structure, whose elements are defined as follows.

 

42.4 message type

The message types supported by emWin are mainly divided into the following three categories (types supported by emWin5.x)

System defined message types:

 

Pointer input device (PID) message type:

 

Notification code type:

 

User defined message type:

 

42.5 system type message instance

Next, we will explain the system message type through a specific example. Here, we create the following dialog box through the GUIBuilder described in the previous chapter, and make simple modifications to it for illustration as an example (the content of the dialog box will be explained in detail in the later tutorial, with emphasis on the system message).

The display effect is as follows (resolution 480 * 272):

 

The code generated after the creation is as follows (focus on the system message part. You can directly copy the code to the simulator or development board for operation)

#include "DIALOG.h"


/*
*********************************************************************************************************
*	                                     Macro definition
*********************************************************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_SCROLLBAR_0 (GUI_ID_USER + 0x02)
#define ID_SLIDER_0 (GUI_ID_USER + 0x03)


/*
*********************************************************************************************************
*	                       GUI_WIDGET_CREATE_INFO Type array
*********************************************************************************************************
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 480, 272, 0, 0x64, 0 },
  { BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 130, 28, 147, 35, 0, 0x0, 0 },
  { SCROLLBAR_CreateIndirect, "Scrollbar", ID_SCROLLBAR_0, 129, 74, 147, 28, 0, 0x0, 0 },
  { SLIDER_CreateIndirect, "Slider", ID_SLIDER_0, 133, 118, 137, 25, 0, 0x0, 0 },
};

/*
*********************************************************************************************************
*	Function name:_ cbDialog
*	Function Description: dialog box callback function		
*	Formal parameter: pMsg callback parameter 
*	Return value: None
*********************************************************************************************************
*/
static void _cbDialog(WM_MESSAGE * pMsg) 
{
	WM_HWIN hItem;
	int     NCode;
	int     Id;


	switch (pMsg->MsgId)    //--------------(1)
	{
		case WM_INIT_DIALOG:  //--------------(2)
			
			//
			// Initialize 'Framewin'
			//
			hItem = pMsg->hWin;
			FRAMEWIN_SetFont(hItem, GUI_FONT_32B_ASCII);
			FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
			FRAMEWIN_SetText(hItem, "armfly");
		
			//
			// Initialize 'Button'
			//
			hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
			BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
			BUTTON_SetText(hItem, "armfly");
			break;

		case WM_PAINT:  //--------------(3)
             GUI_SetBkColor(GUI_BLUE);
		    GUI_Clear();
             break;

        case WM_KEY:    //--------------(4)
            switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) 
            {
                case GUI_KEY_ESCAPE:
                    GUI_EndDialog(pMsg->hWin, 1);
                    break;

                case GUI_KEY_ENTER:
                    GUI_EndDialog(pMsg->hWin, 0);
                    break;
            }
			break;

		case WM_NOTIFY_PARENT:  //--------------(5)
			Id    = WM_GetId(pMsg->hWinSrc);
			NCode = pMsg->Data.v;
			switch(Id) 
			{
				case ID_BUTTON_0:
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:  
							break;
						
						case WM_NOTIFICATION_RELEASED:  
							break;
					}
					break;
				
				case ID_SCROLLBAR_0: 
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
						
						case WM_NOTIFICATION_VALUE_CHANGED:
							break;
					}
					break;
				
				case ID_SLIDER_0:
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
						
						case WM_NOTIFICATION_VALUE_CHANGED:
							break;
					}
					break;
			}
			break;
			
		default:
			WM_DefaultProc(pMsg);
			break;
	}
}

/*
*********************************************************************************************************
*	Function name: CreateFramewin
*	Function Description: create dialog box		
*	Formal parameters: None
*	Return value: returns the dialog handle
*********************************************************************************************************
*/
WM_HWIN CreateFramewin(void) 
{
	WM_HWIN hWin;

	hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);

	return hWin;
}

/*
*********************************************************************************************************
*	Function name: MainTask
*	Function Description: GUI main function
*	Formal parameters: None
*	Return value: None
*********************************************************************************************************
*/
void MainTask(void) 
{
	/* Initial emWin */
	GUI_Init();

	/* create a dialog box */
    CreateFramewin();

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

Focus on the dialog callback function_ Contents in cbDialog:

1. Various system message types are distinguished by switch (PMSG - > msgid).

2,WM_INIT_DIALOG message:

Dialog box initialization message, which mainly initializes the title and button controls of the frame Window. Generally, the initialization of controls on the dialog box, Window or FrameWin is completed in this message. At the same time, users can also create new windows and controls in this message.

3,WM_PAINT message:

Redraw message, where the background color is redrawn, and the background color is set to blue. Text display API functions, numerical display API functions and 2D graphics related API functions can be called in this message.

4,WM_KEY message:

Press the key to receive this message. Only the currently focused window can receive this message. This message is mainly sent through external entity keys. Later chapters of this tutorial will specifically explain this application. In addition, the Data.p pointer in the above code points to WM_ KEY_ Message of info structure, WM_KEY_INFO is defined as follows:

 

5,WM_NOTIFY_PARENT:

   Inform the parent window that some changes have occurred in its child windows. These messages are usually sent by the control to the parent window so that the parent window can respond to events. The Data.v value of the message contains the notification code of the message. The buttons, scroll bars and sliding bars created on the above dialog box are operated through this message.

Through this example, first have a perceptual understanding, and gradually strengthen the understanding with the study of the following chapters.

42.6 pointer input device (PID) type message example

Based on the example in section 42.5 above, the PID type message WM is implemented_ Mouseover, the code is as follows (you can directly copy the code to the simulator or development board to run):

#include "DIALOG.h"



/*
*********************************************************************************************************
*	                                     variable
*********************************************************************************************************
*/
static GUI_COLOR _acColor[3] = {GUI_BLUE,GUI_RED,GUI_YELLOW};   //--------------(1)
static unsigned char ucBackColor; 

/*
*********************************************************************************************************
*	                                     Macro definition
*********************************************************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_SCROLLBAR_0 (GUI_ID_USER + 0x02)
#define ID_SLIDER_0 (GUI_ID_USER + 0x03)


/*
*********************************************************************************************************
*	                       GUI_WIDGET_CREATE_INFO Type array
*********************************************************************************************************
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 480, 272, 0, 0x64, 0 },
  { BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 130, 28, 147, 35, 0, 0x0, 0 },
  { SCROLLBAR_CreateIndirect, "Scrollbar", ID_SCROLLBAR_0, 129, 74, 147, 28, 0, 0x0, 0 },
  { SLIDER_CreateIndirect, "Slider", ID_SLIDER_0, 133, 118, 137, 25, 0, 0x0, 0 },
};

/*
*********************************************************************************************************
*	Function name:_ cbDialog
*	Function Description: dialog box callback function		
*	Formal parameter: pMsg callback parameter 
*	Return value: None
*********************************************************************************************************
*/
static void _cbDialog(WM_MESSAGE * pMsg) 
{
	WM_HWIN hItem;
	int     NCode;
	int     Id;


	switch (pMsg->MsgId) 
	{
		case WM_INIT_DIALOG:
			
			//
			// Initialize 'Framewin'
			//
			hItem = pMsg->hWin;
			FRAMEWIN_SetFont(hItem, GUI_FONT_32B_ASCII);
			FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
			FRAMEWIN_SetText(hItem, "armfly");
		
			//
			// Initialize 'Button'
			//
			hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
			BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
			BUTTON_SetText(hItem, "armfly");

			/* The default background color is GUI_BLUE, i.e. blue */
			ucBackColor = 0;  
			break;

		case WM_PAINT:
              GUI_SetBkColor(_acColor[ucBackColor]); //--------------(2)
			GUI_Clear();
              break;

        case WM_MOUSEOVER:       //--------------(3)
			ucBackColor++;
			if (ucBackColor == 3)
			{
				ucBackColor = 0;
			}
              WM_InvalidateWindow(pMsg->hWin);
			break;

        case WM_KEY:  
            switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) 
            {
                case GUI_KEY_ESCAPE:
                    GUI_EndDialog(pMsg->hWin, 1);
                    break;

                case GUI_KEY_ENTER:
                    GUI_EndDialog(pMsg->hWin, 0);
                    break;
            }
			break;

		case WM_NOTIFY_PARENT:
			Id    = WM_GetId(pMsg->hWinSrc);
			NCode = pMsg->Data.v;
			switch(Id) 
			{
				case ID_BUTTON_0:
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
					}
					break;
				
				case ID_SCROLLBAR_0: 
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
						
						case WM_NOTIFICATION_VALUE_CHANGED:
							break;
					}
					break;
				
				case ID_SLIDER_0:
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
						
						case WM_NOTIFICATION_VALUE_CHANGED:
							break;
					}
					break;
			}
			break;
			
		default:
			WM_DefaultProc(pMsg);
			break;
	}
}

/*
*********************************************************************************************************
*	Function name: CreateFramewin
*	Function Description: create dialog box		
*	Formal parameters: None
*	Return value: returns the dialog handle
*********************************************************************************************************
*/
WM_HWIN CreateFramewin(void) 
{
	WM_HWIN hWin;

	hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);

	return hWin;
}

/*
*********************************************************************************************************
*	Function name: MainTask
*	Function Description: GUI main function
*	Formal parameters: None
*	Return value: None
*********************************************************************************************************
*/
void MainTask(void) 
{
	/* Initial emWin */
	GUI_Init();

	/* Display cursor */
	GUI_CURSOR_Show();

	/* create a dialog box */
    CreateFramewin();

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

Focus on the dialog callback function_ Pointer input device type message WM in cbDialog_ Mouseover implementation:

  1. Define an array with three colors, and define a variable for switching between the three colors.
  2. In WM_ Redrawing is implemented in paint message, which is mainly used to redraw the color of the client area of the dialog box. Initial value of background color_ acColor[ucBackColor], variable ucBackColor is already in WM_ INIT_ The dialog message is initialized and displayed in blue for the first time.
  3. Message WM is added here_ Mouseover, if the mouse function is enabled, this message in the window callback function will be triggered when the mouse arrow touches the window. In this message, change the background color variables of the dialog box, and then call the function WM_. Invalidewindow invalidates the dialog box, which triggers the window manager to execute WM_PAINT message, which changes the background color of the dialog box.

The display effect of the example is as follows (resolution 480 * 272):

 

Other messages of PID type will be explained to you when used in later chapters.

42.7 notification code type message instance

Based on the example in section 42.5 above, the notification code type message is realized, and the background color of the dialog box is changed by operating the button. The code is as follows (you can directly copy the code to the simulator or development board to run):

#include "DIALOG.h"



/*
*********************************************************************************************************
*	                                     variable
*********************************************************************************************************
*/
static GUI_COLOR _acColor[3] = {GUI_BLUE,GUI_RED,GUI_YELLOW};    //--------------(1)
static unsigned char ucBackColor; 

/*
*********************************************************************************************************
*	                                     Macro definition
*********************************************************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_SCROLLBAR_0 (GUI_ID_USER + 0x02)
#define ID_SLIDER_0 (GUI_ID_USER + 0x03)


/*
*********************************************************************************************************
*	                       GUI_WIDGET_CREATE_INFO Type array
*********************************************************************************************************
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 480, 272, 0, 0x64, 0 },
  { BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 130, 28, 147, 35, 0, 0x0, 0 },
  { SCROLLBAR_CreateIndirect, "Scrollbar", ID_SCROLLBAR_0, 129, 74, 147, 28, 0, 0x0, 0 },
  { SLIDER_CreateIndirect, "Slider", ID_SLIDER_0, 133, 118, 137, 25, 0, 0x0, 0 },
};

/*
*********************************************************************************************************
*	Function name:_ cbDialog
*	Function Description: dialog box callback function		
*	Formal parameter: pMsg callback parameter 
*	Return value: None
*********************************************************************************************************
*/
static void _cbDialog(WM_MESSAGE * pMsg) 
{
	WM_HWIN hItem;
	int     NCode;
	int     Id;


	switch (pMsg->MsgId) 
	{
		case WM_INIT_DIALOG:
			
			//
			// Initialize 'Framewin'
			//
			hItem = pMsg->hWin;
			FRAMEWIN_SetFont(hItem, GUI_FONT_32B_ASCII);
			FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
			FRAMEWIN_SetText(hItem, "armfly");
		
			//
			// Initialize 'Button'
			//
			hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
			BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
			BUTTON_SetText(hItem, "armfly");

		    /* The default background color is GUI_BLUE, i.e. blue */
			ucBackColor = 0;
			break;

		case WM_PAINT:    //--------------(2)
             GUI_SetBkColor(_acColor[ucBackColor]);
		    GUI_Clear();
             break;

        case WM_KEY:  
            switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) 
            {
                case GUI_KEY_ESCAPE:
                    GUI_EndDialog(pMsg->hWin, 1);
                    break;

                case GUI_KEY_ENTER:
                    GUI_EndDialog(pMsg->hWin, 0);
                    break;
            }
			break;

		case WM_NOTIFY_PARENT:
			Id    = WM_GetId(pMsg->hWinSrc);
			NCode = pMsg->Data.v;
			switch(Id) 
			{
				case ID_BUTTON_0:
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:     //--------------(3)
							ucBackColor++;
							if (ucBackColor == 3)
							{
								ucBackColor = 0;
							}
							WM_InvalidateWindow(pMsg->hWin);
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
					}
					break;
				
				case ID_SCROLLBAR_0: 
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
						
						case WM_NOTIFICATION_VALUE_CHANGED:
							break;
					}
					break;
				
				case ID_SLIDER_0:
					switch(NCode) 
					{
						case WM_NOTIFICATION_CLICKED:
							break;
						
						case WM_NOTIFICATION_RELEASED:
							break;
						
						case WM_NOTIFICATION_VALUE_CHANGED:
							break;
					}
					break;
			}
			break;
			
		default:
			WM_DefaultProc(pMsg);
			break;
	}
}

/*
*********************************************************************************************************
*	Function name: CreateFramewin
*	Function Description: create dialog box		
*	Formal parameters: None
*	Return value: returns the dialog handle
*********************************************************************************************************
*/
WM_HWIN CreateFramewin(void) 
{
	WM_HWIN hWin;

	hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);

	return hWin;
}

/*
*********************************************************************************************************
*	Function name: MainTask
*	Function Description: GUI main function
*	Formal parameters: None
*	Return value: None
*********************************************************************************************************
*/
void MainTask(void) 
{
	/* Initial emWin */
	GUI_Init();

	/* create a dialog box */
    CreateFramewin();

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

Focus on the dialog callback function_ WM of buttons in cbDialog_ NOTIFICATION_ Implementation of clicked message:

  1. Define an array with three colors, and define a variable for switching between the three colors.
  2. In WM_ Redrawing is implemented in paint message, which is mainly used to redraw the color of the client area of the dialog box. Initial value of background color_ acColor[ucBackColor], variable ucBackColor is already in WM_ INIT_ The dialog message is initialized and displayed in blue for the first time.
  3. After clicking the button, the user switches the background color variable of the dialog box, and then calls the function WM_. Invalidewindow invalidates the dialog box, which triggers the window manager to execute WM_PAINT message, which changes the background color of the dialog box.

The display effect of the example is as follows (the resolution is 480 * 272):

 

More notification messages will be explained in the control class chapter later.

42.8 summary

This chapter will tell you so much. Only some communication examples of message types are given. More examples will be used later to strengthen your understanding of this knowledge.

Tags: stm32

Posted on Mon, 27 Sep 2021 04:42:08 -0400 by MikeyNoedel