📄 hello.c
字号:
/***************************************************************************** 文件名:Hello.C* 功能:MiniGUI应用例子。* 创建一个主窗口,并在窗口中显示字符串"Hello World! --ZLGMCU"。* 说明:使用MiniGUI for uC/OS-II,使用ADS 1.2编译器。****************************************************************************//* 包含MiniGUI的配置头文件(编译配置选项) */#include "MiniGUI_config.h"/* 包含MiniGUI头文件 */#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"/* 主窗口起始位置及大小 */#define MWINDOW_LX 10 /* 窗口左边框的x值 */#define MWINDOW_TY 50 /* 窗口上边框的y值 */#define MWINDOW_RX 230 /* 窗口右边框的x值 */#define MWINDOW_BY 180 /* 窗口下边框的y值 *//* 主窗口需要显示的字符串 */const char hello_str_time[] = {"TIME: %d : %d : %d.%d"};const char hello_str_date[] = {"DATE: 20%02d / %d / %d"};const char hello_str_lat[] = {"LAT: %s %d.%d%d"};const char hello_str_lon[] = {"LON: %s %d.%d%d"};const char hello_str_att[] = {"ATT: %d.%dm"};char hello_str1[30];char hello_str2[30];char hello_str3[50];char hello_str4[50];char hello_str5[30];HWND hMainWnd; // 主窗口句柄/***************************************************************************** 名称:WinProc()* 功能:主窗口过程函数。* 处理MSG_PAINT消息,在窗口中显示hello_str字符串。* 入口参数:hWnd 窗口句柄* message 消息* wParam 消息附加参数1(对于不同的消息,有不同的用途)* lParam 消息附加参数2(对于不同的消息,有不同的用途)* 出口参数:消息已处理则返回0。****************************************************************************/static int WinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; // 定义一个图形设备上下文对象,输出字符时需要。 RECT rc; // 定一个RECT对象(矩形) switch(message) { case MSG_PAINT: hdc = BeginPaint(hWnd); // 获得设备hdc //TextOut(hdc, 10, 50, hello_str);// 可以使用TextOut函数在指定位置上显示字符串 GetClientRect(hWnd, &rc); // 取得窗口客户区矩形 DrawText(hdc, hello_str1, -1, &rc, DT_LEFT); // 输出hello_str字符串 rc.top = rc.top + 16; DrawText(hdc, hello_str2, -1, &rc, DT_LEFT); // 输出hello_str字符串 rc.top = rc.top + 16; DrawText(hdc, hello_str3, -1, &rc, DT_LEFT); // 输出hello_str字符串 rc.top = rc.top + 16; DrawText(hdc, hello_str4, -1, &rc, DT_LEFT); // 输出hello_str字符串 rc.top = rc.top + 16; DrawText(hdc, hello_str5, -1, &rc, DT_LEFT); // 输出hello_str字符串 EndPaint(hWnd, hdc); // 释放设备hdc break; case MSG_CLOSE: DestroyMainWindow(hWnd); // 销毁主窗口 PostQuitMessage(hWnd); // 发送MSG_QUIT消息,通知"消息循环"结束 break; default: return(DefaultMainWinProc(hWnd, message, wParam, lParam)); } return(0);}/***************************************************************************** 名称:InitMainWindow()* 功能:建立主窗口。* 入口参数:无* 出口参数:建立成功返回1,否则返回0。****************************************************************************/int InitMainWindow(void){ MAINWINCREATE window_info; window_info.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION; // 窗口风格设置 window_info.dwExStyle = WS_EX_NONE; // 不使用窗口扩展风格 window_info.spCaption = "MiniGUI"; // 窗口标题 window_info.hMenu = 0; // 无菜单 window_info.hCursor = 0;//GetSystemCursor(0); // 设置窗口光标 window_info.hIcon = 0; // 无窗口图标 window_info.MainWindowProc = WinProc; // 窗口过程函数 window_info.lx = MWINDOW_LX; // 窗口的位置及大小设置 window_info.ty = MWINDOW_TY; window_info.rx = MWINDOW_RX; window_info.by = MWINDOW_BY; window_info.iBkColor = COLOR_lightwhite; // 窗口背景色 window_info.dwAddData = 0; window_info.hHosting = HWND_DESKTOP; // 托管窗口句柄 hMainWnd = CreateMainWindow(&window_info); // 建立主窗口 if(hMainWnd == HWND_INVALID) return(0); else return(1);}/***************************************************************************** 名称:MiniGUIMain()* 功能:MiniGUI程序入口点。* 入口参数:argc 参数个数* argv 参数字符串指针* 出口参数:返回0。****************************************************************************/int MiniGUIMain(int argc, const char *argv[]){ MSG Msg;/* 虽然MiniGUI for uC/OS-II不支持"MiniGUI-Lite模式", 但为了保持代码的移植性,此段不要删除 */#ifdef _LITE_VERSION SetDesktopRect(0,0, 800,600);#endif _sprintf(hello_str1,hello_str_date,0,0,0,0); _sprintf(hello_str2,hello_str_time,0,0,0); _sprintf(hello_str3,hello_str_lat,"N",0,0,0); _sprintf(hello_str4,hello_str_lon,"E",0,0,0); _sprintf(hello_str5,hello_str_att,0,0); InitMainWindow(); // 建立主窗口 ShowWindow(hMainWnd, SW_SHOWNORMAL); // 显示主窗口 /* 消息循环 */ while(GetMessage(&Msg, hMainWnd)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup(hMainWnd); return(0);}void POSTMSG(){ SendMessage(hMainWnd ,MSG_PAINT,0,0 );}/* 定义桌面接口函数 */#ifndef _LITE_VERSION #include "dti.c"#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -