[ucgui] 对话框8——Framewin小工具

 

>_<" 这里主要是窗口小工具Framewin的用法介绍,包括创建背景窗口及其消息回调函数,创建Frame窗口并设置其回调函数,这里一些其他的功能被我注释掉了,有向状态栏添加最大最小按钮的操作,改变标题文本相关设置,设置标题可见性等~注意这里GUI_Delay();很重要,否则会黑屏~

  1 #include <stddef.h>
  2 #include <string.h>
  3 #include "GUI.h"
  4 #include "FRAMEWIN.h"
  5 
  6 #define SPEED   1200
  7 #define MSG_CHANGE_MAIN_TEXT (WM_USER + 0)
  8 
  9 static FRAMEWIN_Handle  _hFrame;
 10 static WM_CALLBACK*     _pcbOldFrame;
 11 static char             _acMainText[100];
 12 static int              _LockClose = 1;
 13 
 14 
 15 //Frame窗口消息回调函数
 16 static void _cbFrame(WM_MESSAGE * pMsg) {
 17   switch (pMsg->MsgId) {
 18   case WM_NOTIFY_PARENT:
 19     if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
 20       int Id = WM_GetId(pMsg->hWinSrc);      /* Id of widget */
 21       if (Id == GUI_ID_CLOSE) {
 22         if (_LockClose) {
 23           return;
 24         }
 25         _hFrame = 0;
 26       }
 27     }
 28     break;
 29   }
 30   if (_pcbOldFrame) {
 31     (*_pcbOldFrame)(pMsg);
 32   }
 33 }
 34 
 35 //背景窗口回调函数
 36 static void _cbBkWindow(WM_MESSAGE * pMsg) {
 37   switch (pMsg->MsgId) {
 38     case MSG_CHANGE_MAIN_TEXT:
 39       strcpy(_acMainText, pMsg->Data.p);
 40       WM_InvalidateWindow(pMsg->hWin);
 41       break;
 42     case WM_PAINT:
 43       GUI_SetBkColor(GUI_BLACK);
 44       GUI_Clear();
 45       GUI_SetColor(GUI_WHITE);
 46       GUI_SetFont(&GUI_Font24_ASCII);
 47       GUI_DispStringHCenterAt("WIDGET_FrameWin - Sample", 160, 5);
 48       GUI_SetFont(&GUI_Font8x16);
 49       GUI_DispStringHCenterAt(_acMainText, 160, 40);
 50       GUI_SetFont(&GUI_Font6x8);
 51       GUI_DispStringHCenterAt("The function FRAMEWIN_Create creates both the\n"
 52                               "frame window and the client window.", 160, 190);
 53       break;
 54     default:
 55       WM_DefaultProc(pMsg);
 56   }
 57 }
 58 
 59 static void _DemoFramewin(void) {
 60   int i;
 61   WM_HWIN hChild;
 62   /* Set callback for background window */
 63   WM_SetCallback(WM_HBKWIN, _cbBkWindow);  //背景窗口消息回调函数
 64   _hFrame = FRAMEWIN_Create("Frame window", 0, WM_CF_SHOW, 50, 75, 220, 100);
 65   /* Set callback for frame window */
 66   _pcbOldFrame = WM_SetCallback(_hFrame, _cbFrame);
 67 //  /* Set moveable */
 68   FRAMEWIN_SetMoveable(_hFrame, 1);
 69 //  /*给窗口加入几个最大最小化按钮 */
 70 //  FRAMEWIN_AddCloseButton(_hFrame, 0, 0);
 71 //  FRAMEWIN_AddMaxButton(_hFrame, FRAMEWIN_BUTTON_RIGHT, 0);
 72 //  FRAMEWIN_AddMinButton(_hFrame, FRAMEWIN_BUTTON_RIGHT, 2);
 73   /* Modify frame window attributes */
 74   FRAMEWIN_SetActive(_hFrame, 1);
 75 //  FRAMEWIN_SetFont(_hFrame, &GUI_Font16B_ASCII);
 76 //  FRAMEWIN_SetTitleHeight(_hFrame, 20);
 77 //
 78 //  FRAMEWIN_SetTextColor(_hFrame, GUI_YELLOW);
 79 //  FRAMEWIN_SetTextAlign(_hFrame, GUI_TA_HCENTER);
 80 //  FRAMEWIN_Minimize(_hFrame);
 81 //  FRAMEWIN_Maximize(_hFrame);
 82 //  FRAMEWIN_Restore(_hFrame);
 83 //  for (i = 0; i < 5; i++) {
 84 //    FRAMEWIN_SetTitleVis(_hFrame, 0);
 85 //    GUI_Delay(200);
 86 //    FRAMEWIN_SetTitleVis(_hFrame, 1);
 87 //    GUI_Delay(200);
 88 //  }
 89 //  /* Time to play with frame window */
 90     while(1){
 91         GUI_Delay(200000000);
 92     }
 93 //  _LockClose = 0;
 94 //  if (_hFrame) {
 95 //    FRAMEWIN_Delete(_hFrame);
 96 //  }
 97 }
 98 
 99 void test(void) {
100   GUI_Init();
101   WM_EnableMemdev(WM_HBKWIN);
102   _DemoFramewin();
103 }

 

posted @ 2014-08-25 15:18  beautifulzzzz  阅读(1882)  评论(0编辑  收藏  举报