50.2 官方WIDGET_Multiedit实例 官方的这个实例很好的演示了Multiedit的使用,这个例子在模拟器中的位置:
源码如下(程序中进行了详细的注释,代码有点长,这里只贴出了主代码):
- /*********************************************************************
- *
- * _DemoMultiedit
- */
- static void _DemoMultiedit(void) {
- GUI_RECT Rect;
- int WinFlags;
-
- _hFrame = 1;
- _Overwrite = 0;
- _ReadOnly = 0;
- _Password = 0;
-
- /* 下面的几个函数主要实现框架窗口的创建 */
- _ChangeInfoText("Create framewin", SPEED);
- /* 创建框架窗口 */
- _hFrame = FRAMEWIN_CreateEx(60, 80, 200, 120, WM_HBKWIN, WM_CF_SHOW, 0, 0, "Notepad", 0);
- /* 获得框架窗口的客户端窗口 */
- _hClient = WM_GetClientWindow(_hFrame);
- /* 设置框架窗口的回调函数 */
- _pcbFrameWin = WM_SetCallback(_hFrame, _cbFrameWin);
- /* 设置框架窗口中客户端窗口的回调函数 */
- _pcbFrameWinClient = WM_SetCallback(_hClient, _cbFrameWinClient);
-
- /* 设置框架窗口的属性 */
- FRAMEWIN_SetMoveable(_hFrame, 1);
- FRAMEWIN_SetActive(_hFrame, 1);
- FRAMEWIN_SetTextAlign(_hFrame, GUI_TA_HCENTER | GUI_TA_VCENTER);
- FRAMEWIN_SetFont(_hFrame, &GUI_Font8x12_ASCII);
- FRAMEWIN_SetTitleHeight(_hFrame, 16);
-
- /* 增加框架窗口按钮,主要是关闭,最小化,最大化按钮 */
- if (_ChangeInfoText("Add framewin buttons", SPEED)) return;
- FRAMEWIN_AddCloseButton(_hFrame, FRAMEWIN_BUTTON_LEFT, 0);
- FRAMEWIN_AddMaxButton(_hFrame, FRAMEWIN_BUTTON_RIGHT, 0);
- FRAMEWIN_AddMinButton(_hFrame, FRAMEWIN_BUTTON_RIGHT, 1);
- WM_InvalidateWindow(_hFrame);
-
- /* 创建按钮 */
- if (_ChangeInfoText("Add option buttons", SPEED)) return;
- _hWrapButton = _CreateLButton("None", 0, 36, 16, _hClient, ID_NONEWRAP);
- _CreateLButton("Word", 37, 36, 16, _hClient, ID_WORDWRAP);
- _CreateLButton("Char", 74, 36, 16, _hClient, ID_CHARWRAP);
- _CreateRButton("PSW", 52, 25, 16, _hClient, ID_PASSWORD);
- _CreateRButton("OVR", 26, 25, 16, _hClient, ID_OVERWRITE);
- _CreateRButton("R/O", 0, 25, 16, _hClient, ID_READONLY);
- _SetButtonState(_hWrapButton, 1);
-
- /* 创建框架窗口 */
- if (_ChangeInfoText("usingnMULTIEDIT_CreateEx", SPEED)) return;
- WinFlags = WM_CF_SHOW | WM_CF_ANCHOR_RIGHT | WM_CF_ANCHOR_LEFT | WM_CF_ANCHOR_TOP | WM_CF_ANCHOR_BOTTOM;
- WM_GetClientRectEx(_hClient, &Rect);
- /* 在框架窗口的客户端窗口中创建多行文本控件 */
- _hMEdit = MULTIEDIT_CreateEx(0, 0, 0, Rect.y1 - 16 + 1, _hClient, WinFlags, MULTIEDIT_CF_INSERT, 0, 0, "");
- /* 设置多行文本控件的回调函数 */
- _pcbMultiEdit = WM_SetCallback(_hMEdit, _cbMultiEdit);
- /* 激活自动使用水平滚动条 */
- MULTIEDIT_SetAutoScrollH(_hMEdit, 1);
- /* 激活自动使用垂直滚动条 */
- MULTIEDIT_SetAutoScrollV(_hMEdit, 1);
- /* 设置聚焦 */
- WM_SetFocus(_hMEdit);
-
- /* 下面主要是演示一下多行文本控件支持的几个API函数 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetText", SPEED)) return;
- /* 设置文本 */
- MULTIEDIT_SetText(_hMEdit, "This sample demonstrates the use of a multiedit widget!");
-
- /* 设置字体 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetFont", SPEED)) return;
- MULTIEDIT_SetFont(_hMEdit, &GUI_Font16_1);
-
- /* 设置文本颜色 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetTextColor", SPEED)) return;
- MULTIEDIT_SetTextColor(_hMEdit, 0, 0xE00000);
-
- /* 设置背景色 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetBkColor", SPEED)) return;
- MULTIEDIT_SetBkColor(_hMEdit, 0, 0xD0FFFF);
-
- /* 启用字词换行 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetWrapWord", SPEED)) return;
- MULTIEDIT_SetWrapWord(_hMEdit);
-
- /* 设置字词换行按钮的状态 */
- _SetButtonState(_hWrapButton, 0);
- _hWrapButton = WM_GetDialogItem(_hClient, ID_WORDWRAP);
- _SetButtonState(_hWrapButton, 1);
-
- /* 用于设置边界 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetHBorder", SPEED)) return;
- MULTIEDIT_SetHBorder(_hMEdit, 3);
-
- /* 设置提示文本 */
- if (_ChangeInfoText("usingnMULTIEDIT_SetPrompt", SPEED)) return;
- MULTIEDIT_SetPrompt(_hMEdit, "Type: ");
-
- if (_ChangeInfoText("Play with multiedit...", SPEED)) return;
-
- while (_hFrame)
- {
- GUI_Delay(100);
- }
- }
-
- /*********************************************************************
- *
- * public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- GUI_Init();
- #if GUI_SUPPORT_MEMDEV
- WM_SetCreateFlags(WM_CF_MEMDEV);
- #endif
- GUI_CURSOR_Show();
- WM_SetCallback(WM_HBKWIN, _cbBkWin);
- while(1) {
- /* 演示多行文本 */
- _DemoMultiedit();
- *_acInfoText = 0;
- WM_InvalidateWindow(WM_HBKWIN);
- GUI_Delay(SPEED);
- }
- }
复制代码
实际显示效果如下: |