Stemwin软键盘,小项目,控件,回调函数

窗口回调函数很重要

下面是我做的一个简单的快递收发系统框架,也可以算个计算器吧,有些功能不太全哦,再改进一下就可以了

Stemwin软键盘,小项目,控件,回调函数_第1张图片
Stemwin软键盘,小项目,控件,回调函数_第2张图片
Stemwin软键盘,小项目,控件,回调函数_第3张图片

下面是源码,图片流太大了,没有添加进来,自己可以用软件做一个图片

#include "GUI.h"
static void _cbMaster(WM_MESSAGE * pMsg);
static void _OKcbDialog(WM_MESSAGE * pMsg) ;
static void _cbDialog(WM_MESSAGE * pMsg);
#ifndef GUI_CONST_STORAGE
  #define GUI_CONST_STORAGE const
#endif
extern GUI_CONST_STORAGE GUI_BITMAP bmtimg;

GUI_CONST_STORAGE GUI_BITMAP bmtimg = {
  320, // xSize
  239, // ySize
  640, // BytesPerLine
  16, // BitsPerPixel
  (unsigned char *)_actimg,  // Pointer to picture data
  NULL,  // Pointer to palette
  GUI_DRAW_BMP444_12
};
#define ID_FRAMEWIN_0     (GUI_ID_USER + 0x14)
#define ID_BUTTON_0     (GUI_ID_USER + 0x00)
#define ID_BUTTON_1     (GUI_ID_USER + 0x01)
#define ID_BUTTON_2     (GUI_ID_USER + 0x02)
#define ID_BUTTON_3     (GUI_ID_USER + 0x03)
#define ID_BUTTON_4     (GUI_ID_USER + 0x04)
#define ID_BUTTON_5     (GUI_ID_USER + 0x05)
#define ID_BUTTON_6     (GUI_ID_USER + 0x06)
#define ID_BUTTON_7     (GUI_ID_USER + 0x07)
#define ID_BUTTON_8     (GUI_ID_USER + 0x08)
#define ID_BUTTON_9     (GUI_ID_USER + 0x09)
#define ID_EQL_10     (GUI_ID_USER + 0x0A)
#define ID_ADD_11     (GUI_ID_USER + 0x0B)
#define ID_SUB_12     (GUI_ID_USER + 0x0C)
#define ID_MUL_13     (GUI_ID_USER + 0x0E)
#define ID_DIV_14     (GUI_ID_USER + 0x0D)
#define ID_POINT_15     (GUI_ID_USER + 0x0F)
#define ID_OK_16     (GUI_ID_USER + 0x10)
#define ID_CEL_17     (GUI_ID_USER + 0x11)
#define ID_DEL_18     (GUI_ID_USER + 0x12)
#define ID_EDIT_0     (GUI_ID_USER + 0x13)
//关于结构体GUI_WIDGET_CREATE_INFO的解释
//typedef struct {
//GUI_WIDGET_CREATE_FUNC * pfCreateIndirect; // Create function
//const char * pName; // Text (not used for all widgets)
//I16 Id; // Window ID of the widget
//I16 x0, y0, xSize, ySize; // Size and position of the widget
//I16 Flags; // Widget-specific flags (or 0)
//I32 Para; // Widget-specific parameter (or 0)
//U32 NumExtraBytes; // Number of extra bytes usable
 with _SetUserData &
 _GetUserData
//} GUI_WIDGET_CREATE_INFO;
#define ID_MFRAMEWIN_01     (GUI_ID_USER + 0x15)
#define ID_QUJIAN_0    (GUI_ID_USER + 0x16)
//主界面排版
static const GUI_WIDGET_CREATE_INFO _MaDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_MFRAMEWIN_01, 0, 0, 320, 240, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "Pick", ID_QUJIAN_0, 83, 150, 137, 56, 0, 0x0, 0 },
  
};
// USER START (Optionally insert additional defines)
// USER END
#define ID_FRAMEWIN_02     (GUI_ID_USER + 0x17)
#define ID_EDIT_OK     (GUI_ID_USER + 0x18)
#define ID_BUTTON_OK     (GUI_ID_USER + 0x19)
//提示信息排版
static const GUI_WIDGET_CREATE_INFO _OKaDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_02, 0, 1, 210, 140, 0, 0x0, 0 },
  { EDIT_CreateIndirect, 0, ID_EDIT_OK, 0, 0, 199, 35, 0, 0x64, 0 },
  { BUTTON_CreateIndirect, "OK", ID_BUTTON_OK, 55, 65, 80, 28, 0, 0x0, 0 },
  
};

//密码用户名的排版
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, 0, ID_FRAMEWIN_0, 79, 0, 148, 238, 0, 0x00, 0 },
  { BUTTON_CreateIndirect, "0", ID_BUTTON_0, 35, 155, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "1", ID_BUTTON_1, 0, 120, 30, 30, 0, 0x0, 0 },  //位置是相对面板的位置
  { BUTTON_CreateIndirect, "2", ID_BUTTON_2, 35, 120, 30, 30, 0, 0x0, 0},
  { BUTTON_CreateIndirect, "3", ID_BUTTON_3, 70, 120, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "4", ID_BUTTON_4, 0, 85, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "5", ID_BUTTON_5, 35, 85, 30, 30, 0, 0x0, 0  },
  { BUTTON_CreateIndirect, "6", ID_BUTTON_6, 69, 85, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "7", ID_BUTTON_7, 0, 50, 30, 30, 0, 0x0, 0},
  { BUTTON_CreateIndirect, "8", ID_BUTTON_8, 35, 50, 30, 30, 0, 0x0, 0  },
  { BUTTON_CreateIndirect, "9", ID_BUTTON_9, 70, 50, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "=", ID_EQL_10, 70, 155, 65, 30, 0, 0x0, 0},
  { BUTTON_CreateIndirect, "+", ID_ADD_11, 105, 190, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "-", ID_SUB_12, 105, 120, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "*", ID_MUL_13, 105, 85, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "/", ID_DIV_14, 105, 50, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, ".", ID_POINT_15, 0, 155, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "ok", ID_OK_16, 0, 190, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "cel", ID_CEL_17, 35, 190, 30, 30, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "dele", ID_DEL_18, 70, 190, 30, 30, 0, 0x0, 0 },
   { EDIT_CreateIndirect, 0, ID_EDIT_0, 0, 0, 136, 45, 0, 0x64, 0 },
};


//提示窗口回调函数
static void _OKcbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int     NCode;
  int     Id;
  WM_HWIN  hDlg;
  hDlg = pMsg->hWin;

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_OK);
    EDIT_SetText(hItem, "ERRO");   //提示错误
    EDIT_SetFont(hItem, GUI_FONT_20_ASCII);
    EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_BUTTON_OK: // Notifications sent by 'OK'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:  //按下
       
        break;
      case WM_NOTIFICATION_RELEASED:   //释放
			GUI_EndDialog(hDlg, 1);		//隐藏窗口
			 GUI_CreateDialogBox(_MaDialogCreate, 
                                GUI_COUNTOF(_MaDialogCreate), 
                                _cbMaster, WM_HBKWIN, 0, 0);//创建窗口
      
        break;
     }
      break;
   }
    break;
 default:
    WM_DefaultProc(pMsg);
    break;
  }
}
//输入用户名密码界面回调函数
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  WM_HWIN OKSTERWIN;
  int     NCode;
  int      Pressed=0;
  int     Id;
  int i;
  WM_HWIN  hDlg;
  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {
	case WM_PAINT:
		break;
	case WM_INIT_DIALOG:
		/*设置皮肤 这个设置要在WM_INIT_DIALOG:信息后面*/
        FRAMEWIN_SetSkin(pMsg->hWin, FRAMEWIN_SKIN_FLEX);
		hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
		WM_SetFocus(hItem);   //聚焦 很重要,要不然编辑窗口接收不到按键发来的信息
		EDIT_SetText(hItem, "USER:");
		EDIT_SetFont(hItem, GUI_FONT_20_ASCII);
		EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);//对齐方式	
	 for (i = 0; i < GUI_COUNTOF(_aDialogCreate)-1; i++) 
	{
      hItem = WM_GetDialogItem(hDlg,GUI_ID_USER + i);
	   /*一定要加,要不然信息发送不到编辑窗口,所以编辑窗口就不会有显示*/
      BUTTON_SetFocussable(hItem, 0);      
    }
  break; 
  case WM_NOTIFY_PARENT:
	   Id = WM_GetId(pMsg->hWinSrc);  /* Id of widget */
	   NCode = pMsg->Data.v;          /* Notification code */
    switch (NCode) {
		   case WM_NOTIFICATION_CLICKED://点击窗口后通知消息
				Pressed=1;
			/*	break;*/       //不能加break  
      case WM_NOTIFICATION_RELEASED:      /* 释放的时候 */
			if (Id == ID_OK_16) 
			{            
			  GUI_EndDialog(hDlg, 0);        //隐藏窗口
			 OKSTERWIN = GUI_CreateDialogBox(_OKaDialogCreate, 
                                GUI_COUNTOF(_OKaDialogCreate), 
                                _OKcbDialog, WM_HBKWIN, 0, 0);	//重新创建陈窗口							//给程序发送消息验证密码和用户名
			}
			else if(Id ==ID_CEL_17) 
			{                       
			  GUI_EndDialog(hDlg, 1);		//也是隐藏窗口
			OKSTERWIN = GUI_CreateDialogBox(_OKaDialogCreate, 
                                GUI_COUNTOF(_OKaDialogCreate), 
                                _OKcbDialog, WM_HBKWIN, 0, 0);	//创建窗口						
			}
			else if(Id<=ID_BUTTON_9) //按下了数字按钮
			{
				char acBuffer[10];
				int Key;
			  BUTTON_GetText(pMsg->hWinSrc, acBuffer, sizeof(acBuffer)); //得到’0’到‘9’的字符文本
			  Key = acBuffer[0];
			  /*给目标编辑窗口发送信息  前面必须加上BUTTON_SetFocussable(hItem, 0);*/
			  GUI_SendKeyMsg(Key, Pressed); 
			}
     break;
    }
    break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}
//主界面:中国邮政回调函数
static void _cbMaster(WM_MESSAGE * pMsg) {
  int NCode;
  int Id;
  WM_HWIN hItem;
  WM_HWIN  hDlg;
  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {

  case WM_INIT_DIALOG:
	   hItem = WM_GetDialogItem(pMsg->hWin, ID_QUJIAN_0);
	   BUTTON_SetFont(hItem,GUI_FONT_24_ASCII);   //按钮字体大小
	   BUTTON_SetTextColor(hItem,0,GUI_YELLOW);  //设置文本颜色
	   BUTTON_SetBkColor (hItem, 1,GUI_BLUE);   //按下时使用的颜色
	   BUTTON_SetBkColor (hItem, 0,GUI_GREEN);   //没有按下的颜色
	   FRAMEWIN_SetTitleVis(hDlg, 0);          //隐藏标题栏
  case WM_PAINT:                               //重绘制
		GUI_SetBkColor(GUI_WHITE);
        GUI_Clear();                           //先填充
		GUI_DrawBitmap(&bmtimg,0,0);         //给窗口添加图片背景:中国邮政
						break;      //注意添加位图作为背景一定要在重绘制消息后面添加
 
  case WM_NOTIFY_PARENT:
    
	Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
	switch(Id) {
    case ID_QUJIAN_0: 
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
		
        break;
      case WM_NOTIFICATION_RELEASED:
        if (Id == ID_QUJIAN_0) {           
          GUI_EndDialog(hDlg, 0);
		GUI_ExecDialogBox(_aDialogCreate, 
                      GUI_COUNTOF(_aDialogCreate), 
                      _cbDialog, WM_HBKWIN, 0, 0);   
        }
        break;
      }
      break;
    
    }
    break;
  
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

static char _aTitle[] = {"PICK"};     
/* 桌面设计函数 */
static void _cbDesktop(WM_MESSAGE * pMsg) {
  unsigned i;

  switch (pMsg->MsgId) {
  case WM_PAINT:
    GUI_SetBkColor(GUI_GREEN);
    GUI_Clear();
    GUI_SetFont(&GUI_Font24_ASCII);
    GUI_DispStringHCenterAt(_aTitle, 140, 5);
    break;
  }
}
/*
*       MainTask
*/
void MainTask(void) {
  
	WM_HWIN MASTERWIN;
	GUI_Init();
    WM_SetCallback(WM_HBKWIN, _cbDesktop);  //桌面回调函数
    MASTERWIN = GUI_CreateDialogBox(_MaDialogCreate, 
                                GUI_COUNTOF(_MaDialogCreate), 
                                _cbMaster, WM_HBKWIN, 0, 0); //创建主窗口 取件
 
  while (1) {
    GUI_Delay(1000);
  }
}

你可能感兴趣的:(stm32和ARM)