|
发表于 2015-4-20 22:35:04
|
显示全部楼层
简单给你改了下,子窗口删除自己是可以的,删除父窗口不可以,代码可以在模拟器上面跑。
- /*********************************************************************
- * SEGGER Microcontroller GmbH & Co. KG *
- * Solutions for real time microcontroller applications *
- **********************************************************************
- * *
- * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- ** emWin V5.28 - 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 : GUIDEMO_Start.c
- Purpose : GUIDEMO initialization
- ----------------------------------------------------------------------
- */
- #include "GUI.h"
- #include "gui.h"
- #include "BUTTON.h"
- #include "TEXT.h"
- #include "EDIT.h"
- #include <stdio.h>
- #define Button1 0x821
- #define Button2 0x822
- #define Edit1 0x823
- #define Edit2 0x824
- #define DltMess 0x880
- #define ChangeColor 0x830
- WM_HWIN hParent,hChild;
- BUTTON_Handle hPButton,hCButton;
- EDIT_Handle hEdit,hEditC;
- unsigned char pCnt = 0, cCnt = 0;
- unsigned int BkColor = GUI_WHITE;
- void _cbCall( WM_MESSAGE *pMsg ) // 父窗体回调函数
- {
- int id,Ncod;
- switch(pMsg->MsgId)
- {
- case WM_DELETE:
- break;
- case ChangeColor:
- BkColor = GUI_GREEN;
- WM_DeleteWindow(hChild);
- WM_InvalidateWindow(hParent);
- break;
- case WM_PAINT :
- GUI_SetBkColor(BkColor);
- GUI_SetColor(GUI_RED);
- GUI_Clear();
- break;
- case WM_NOTIFY_PARENT:
- id = WM_GetId(pMsg->hWinSrc);
-
- Ncod = pMsg->Data.v;
- switch( id )
- {
- case Button1:
- if( Ncod==WM_NOTIFICATION_RELEASED)
- { pCnt++;
- printf("%d",pCnt);
- EDIT_SetValue(hEdit,pCnt);
- GUI_DispDecAt(pCnt,70,20,3);
- WM_InvalidateWindow(hParent);
- };
- break;
- } ;
- break;
- default:
- WM_DefaultProc(pMsg); break;
- }
- }
- void SendMessage( int hWin , int hSrc ,int msg ) // 发送消息函数
- {
- WM_MESSAGE pMsg; //WM_MESSAGE
- pMsg.MsgId = msg;
-
- pMsg.hWin = hWin;
- pMsg.hWinSrc = hSrc;
- WM_SendToParent(hSrc,&pMsg);
- }
- void _cbChild( WM_MESSAGE *pMsg ) // 子窗体回调函数
- {
- WM_HWIN hWin ;
- int id,Ncod;
- switch(pMsg->MsgId)
- {
- case WM_DELETE:
- break;
- case WM_PAINT:
- GUI_SetBkColor(GUI_BLACK);
- GUI_SetColor(GUI_WHITE);
- GUI_Clear();
- break;
-
- case WM_NOTIFY_PARENT:
- id = WM_GetId(pMsg->hWinSrc); // 源窗口
- Ncod = pMsg->Data.v;
- switch( id )
- {
- case Button2:
- if( Ncod==WM_NOTIFICATION_RELEASED)
- {
- SendMessage(hParent,hChild,ChangeColor);
- // WM_DeleteWindow(pMsg->hWin);
- }
-
- // cCnt++;
- // EDIT_SetValue(hEditC,cCnt);
- // GUI_DispDecAt(cCnt,90,90,3);
- //
- // WM_InvalidateWindow(hChild);
- break;
- };
- break;
- default:
- WM_DefaultProc(pMsg); break;
- }
- }
- void Show(void) // 窗体的初始化
- {
- hParent = WM_CreateWindow(0,0,240,320,WM_CF_SHOW, _cbCall,0);
- hChild = WM_CreateWindowAsChild(120,120,180,180,hParent,WM_CF_SHOW,_cbChild,0);
- hPButton = BUTTON_CreateEx(10,10,40,40,hParent,WM_CF_SHOW,0,Button1);
- hCButton = BUTTON_CreateEx(10,10,40,40,hChild,WM_CF_SHOW,0,Button2);
-
- BUTTON_SetFocussable(hPButton,0); // 设置按钮不捕获焦点
- BUTTON_SetFocussable(hCButton,0); // 设置按钮不捕获焦点
- hEdit = EDIT_CreateEx(60,60,80,30,hParent,WM_CF_SHOW,0,Edit1,2);
- EDIT_SetDecMode(hEdit,0,0,10000,0,0);
-
- hEditC = EDIT_CreateEx(60,60,50,30,hChild,WM_CF_SHOW,0,Edit2,2);
- EDIT_SetDecMode(hEditC,0,0,10000,0,0);
-
- }
- // USER START (Optionally insert additional public code)
- // USER END
- void MainTask(void)
- {
- GUI_Init();
- Show();
- while(1)
- {
- GUI_Delay(20);
- }
- }
- /*************************** End of file ****************************/
复制代码 |
|