📄 input.c
字号:
/***************************************************************************** 文件名:Input.C* 功能:MiniGUI应用例子。* 创建对话框,实现长度"毫米"-"英寸"的转换。* 说明:使用MiniGUI for uC/OS-II,使用ADS 1.2编译器。****************************************************************************/#include <stdlib.h>/* 包含MiniGUI的配置头文件(编译配置选项) */#include "MiniGUI_config.h"/* 包含MiniGUI头文件 */#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#define IDC_STATIC1 1000#define IDC_STATIC2 1001#define IDC_EDIT1 1010/* 对话框属性设置 */static DLGTEMPLATE MyDlgTEMP ={ WS_BORDER | WS_CAPTION, WS_EX_NONE, 10, 10, 220, 160, "请输入长度", 0, 0, 5, NULL, 0};/* 对话框内的控件定义 */static CTRLDATA MyCtrlData[] ={ { "static", WS_VISIBLE | SS_SIMPLE, 10, 10, 220, 16, IDC_STATIC1, "请输入长度(单位:mm)", 0 }, { "static", WS_VISIBLE | SS_SIMPLE, 10, 70, 180, 16, IDC_STATIC2, "相当于0.000英寸.", 0 }, { "edit", WS_VISIBLE | WS_BORDER | WS_TABSTOP, 10, 40, 160, 24, IDC_EDIT1, NULL, 0 }, { "button", WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 30, 100, 60, 25, IDOK, "确定", 0 }, { "button", WS_VISIBLE | WS_TABSTOP, 130, 100, 60, 25, IDCANCEL, "取消", 0 },};/***************************************************************************** 名称:MyNotifProc()* 功能:编辑框控件IDC_EDIT1的回调函数。* 当编辑框接收到数据输入时(EN_CHANGE消息),就进行单位转换,然后在静* 态文本框IDC_STATIC2中显示转换结果。* 入口参数:hWnd 窗口句柄* id 控件ID* nc 通知码* add_data 附加参数* 出口参数:无****************************************************************************/static void MyNotifProc(HWND hwnd, int id, int nc, DWORD add_data){ static char disp[50]; double len; int d, f; if((id==IDC_EDIT1) && (nc==EN_CHANGE)) { GetWindowText(hwnd, disp, 32); // 取得字符 len = atof(disp); // 转换为浮点数 len = len / 25.4; d = (int)len; f = (int)(len * 1000) % 1000; sprintf(disp, "相当于%d.%03d英寸", d, f); SetDlgItemText(GetParent(hwnd), IDC_STATIC2, disp); // GetParent(hwnd)是取得父窗口句柄,即hDlg } if(nc == EN_ENTER) { PostMessage(GetParent(hwnd), MSG_COMMAND, IDOK, 0); }}/***************************************************************************** 名称:DialogBoxProc()* 功能:对话框过程函数。* 在MSG_INITDIALOG消息中保存启动对话框时传递过来的lParam参数。* 在MSG_COMMAND消息中处理IDOK命令,将处理后的数据返回主程序(length变量)。* 入口参数:hWnd 窗口句柄* message 消息* wParam 消息附加参数1* lParam 消息附加参数2* 出口参数:返回消息处理结果。****************************************************************************/static int DialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ char disp[50]; double *length; switch (message) { case MSG_INITDIALOG: SetWindowAdditionalData(hDlg, lParam); // 保存lParam参数(到窗口附加参数中) // 即保存rcvdat指针 SetNotificationCallback(GetDlgItem(hDlg, IDC_EDIT1), MyNotifProc); // 设计控件回调函数 return(1); case MSG_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog (hDlg, wParam); break; case IDOK: length = (double*) GetWindowAdditionalData(hDlg); GetWindowText(GetDlgItem(hDlg, IDC_EDIT1), disp, 32); *length = atof(disp); // 保存转换结果到主程序的变量 EndDialog (hDlg, wParam); break; default: break; } break; case MSG_CLOSE: EndDialog (hDlg, IDCANCEL); break; default: break; } return DefaultDialogProc (hDlg, message, wParam, lParam);}/***************************************************************************** 名称:InitDialogBox()* 功能:初始化对话框,然后启动对话框。 * 入口参数:hWnd 父窗口句柄* 出口参数:无****************************************************************************/static void InitDialogBox(HWND hWnd, double *rcvdat){ MyDlgTEMP.controls = MyCtrlData; DialogBoxIndirectParam(&MyDlgTEMP, hWnd, DialogBoxProc, (LPARAM)rcvdat);}/***************************************************************************** 名称:MiniGUIMain()* 功能:MiniGUI程序入口点。* 入口参数:argc 参数个数* argv 参数字符串指针* 出口参数:返回0。****************************************************************************/int MiniGUIMain(int argc, const char *argv[]){ double length = 0.0;/* 虽然MiniGUI for uC/OS-II不支持"MiniGUI-Lite模式", 但为了保持代码的移植性,此段不要删除 */#ifdef _LITE_VERSION SetDesktopRect(0,0, 800,600);#endif InitDialogBox(HWND_DESKTOP, &length); return(0);}/* 定义桌面接口函数 */#ifndef _LITE_VERSION #include "dti.c"#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -