ucgui窗体框架的学习之后,基本上我们能够应用以前学到的各个知识点绘制一个简单的窗口界面,包含按钮,文本框,复选框,父子窗口等。按钮,窗口,窗体,复选框编写程序的基本步骤:
1. 定义控件句柄一般情况下都是经过以上七步,即可完成。但是有些控件比如在按钮使用过程中,它可能等待鼠标点击,点击完成后又需要删除,因此还要删除该控件。在一般使用过程中是不需要删除的,我们在日常学习使用中都可以观察得到,都是点击了按钮进行跳转等。
2. 创建控件
3. 设置控件的背景颜色
4. 设置控件的前景色
5. 设置控件的文本字体
6. 设置控件的文本对齐方式
7. 在控件中间书写名称(GUI_DispStringHCenterAt(参数序列))
if(winHObj!=WM_GetDesktopWindow())
WM_DeleteWindow(winHObj);
Curwin.Hwin=WM_CreateWindow(MMI_WINDOWS_X, MMI_WINDOWS_Y, MMI_WINDOWS_W, MMI_WINDOWS_H, WM_CF_MEMDEV|WM_CF_SHOW,cb, 0);
WM_SetCallback(Curwin.Hwin,cb);
WM_SetFocus(Curwin.Hwin);
****
以下是一个简单的例子,用以学习基本框架的生成,在此基础上还创建了以子窗口形式创建的窗口。现在的疑惑是以子窗口形似创建窗口是否只能在窗体中进行,两个窗体之间应该可以,在平常点击网页时可以行的通,但还是不会编写。
[code=cpp] #include "GUI.H" #include "FrameWin.h" #include "WM_Intern.h" #include <stddef.h> static WM_RESULT CallbackChild(WM_MESSAGE *pMsg) { WM_HWIN hWin= (FRAMEWIN_Handle)(pMsg->hWin); switch(pMsg->MsgId) { caseWM_PAINT: GUI_SetBkColor(GUI_BLUE); GUI_SetColor(GUI_WHITE); GUI_SetFont(&GUI_FontComic24B_ASCII); GUI_SetTextAlign(GUI_TA_HCENTER|GUI_TA_VCENTER); GUI_Clear(); GUI_DispStringHCenterAt("Childwindow",//来 自:S T_M8. CN WM_GetWindowSizeX(hWin)/2, WM_GetWindowSizeY(hWin)/2); break; } } static void DemoFramewin(void) { FRAMEWIN_Handle hFrame = FRAMEWIN_Create("Framewindow",NULL,WM_CF_SHOW,10,10,150,60); FRAMEWIN_SetFont(hFrame,&GUI_Font16B_ASCII); FRAMEWIN_SetTextColor(hFrame,GUI_RED); FRAMEWIN_SetBarColor(hFrame,0,GUI_GREEN); FRAMEWIN_SetTextAlign(hFrame,GUI_TA_HCENTER); WM_CreateWindowAsChild(0,0,0,0,hFrame,WM_CF_SHOW,CallbackChild,0); } void _MainTask(void)//应用程序开始 { DemoFramewin(); while(1) GUI_Delay(100); } //主函数 void main(void) { GUI_Init(); GUI_Clear(); _MainTask(); } [/code]
先建两个文件,第一个的代码如下: #include "GUI.H" #include <stddef.h> #include "FRAMEWIN.h" #include "text.h"// 来自: STM_8 .CN #include "button.h" BUTTON_Handle U2_hButton0; TEXT_Handle U2_hTEXT0; FRAMEWIN_Handle U2_hFRAMEWIN1; void MainTask1(void) { int r; GUI_Init(); GUI_SetBkColor(GUI_WHITE); GUI_ClearRect(0,0,320,240); GUI_SetColor(GUI_RED); WM_SetDesktopColor(GUI_WHITE); U2_hFRAMEWIN1=FRAMEWIN_Create("Gui_Form",NULL, WM_CF_SHOW,0,0,320,231); FRAMEWIN_AddCloseButton(U2_hFRAMEWIN1,1,0); FRAMEWIN_SetFont(U2_hFRAMEWIN1,&GUI_Font8x18); FRAMEWIN_SetMoveable(U2_hFRAMEWIN1,1); FRAMEWIN_SetText(U2_hFRAMEWIN1,"Gui_Form");// 来自: STM_8 .CN FRAMEWIN_SetTitleVis(U2_hFRAMEWIN1,0); U2_hTEXT0=TEXT_CreateEx(180,100,130,13,U2_hFRAMEWIN1,WM_CF_SHOW,0,20,"This is Form2"); TEXT_SetFont(U2_hTEXT0,&GUI_Font8x16); TEXT_SetText(U2_hTEXT0,"This is Form2"); TEXT_SetTextColor(U2_hTEXT0,GUI_RED); U2_hButton0=BUTTON_CreateEx(20,60,100,40,U2_hFRAMEWIN1,WM_CF_SHOW,0,30); BUTTON_SetText(U2_hButton0,"ShowWindows1"); GUI_SetFont(&GUI_Font8x18); GUI_DispStringAt("This is Form2",100,180); while(1) { r = GUI_GetKey(); if (r) { FRAMEWIN_Delete(U2_hFRAMEWIN1); BUTTON_Delete(U2_hButton0); GUI_ClearRect(0,0,320,240); MainTask(); } GUI_Exec(); GUI_Exec(); } } 然后再建一个,将上面的代码复制进去,将细节修改一下。代码如下: #include "GUI.H" #include <stddef.h> #include "FRAMEWIN.h" #include "text.h" #include "button.h" BUTTON_Handle U1_hButton0; TEXT_Handle U1_hTEXT0; FRAMEWIN_Handle U1_hFRAMEWIN1; void MainTask(void) { int r; GUI_Init(); GUI_SetBkColor(GUI_WHITE); GUI_ClearRect(0,0,320,240); GUI_SetColor(GUI_RED); WM_SetDesktopColor(GUI_WHITE); U1_hFRAMEWIN1=FRAMEWIN_Create("Gui_Form",NULL, WM_CF_SHOW,0,0,320,231); FRAMEWIN_AddCloseButton(U1_hFRAMEWIN1,1,0); FRAMEWIN_SetFont(U1_hFRAMEWIN1,&GUI_Font8x18); FRAMEWIN_SetMoveable(U1_hFRAMEWIN1,1);// 来自: STM_8 .CN FRAMEWIN_SetText(U1_hFRAMEWIN1,"Gui_Form"); FRAMEWIN_SetTitleVis(U1_hFRAMEWIN1,0); U1_hTEXT0=TEXT_CreateEx(47,41,130,13,U1_hFRAMEWIN1,WM_CF_SHOW,0,20,"This is Form1"); TEXT_SetFont(U1_hTEXT0,&GUI_Font8x16); TEXT_SetText(U1_hTEXT0,"This is Form1"); TEXT_SetTextColor(U1_hTEXT0,GUI_RED); U1_hButton0=BUTTON_CreateEx(150,150,100,40,U1_hFRAMEWIN1,WM_CF_SHOW,0,30); BUTTON_SetText(U1_hButton0,"ShowWindows2"); GUI_SetFont(&GUI_Font8x18); GUI_DispStringAt("This is Form1",41,47); while(1) { r = GUI_GetKey(); if (r) { FRAMEWIN_Delete(U1_hFRAMEWIN1); BUTTON_Delete(U1_hButton0); GUI_ClearRect(0,0,320,240); MainTask1(); } GUI_Exec(); GUI_Exec(); } }