|
各位好!
参考V6教程 STemwin多个窗口切换方法,实现一个窗口包含 LISTVIEW控件
遇到一个问题:窗口大小设置成128*64 因为实际使用的是黑白色的LCD液晶屏,但是现实的LISTVIEW 不是从坐标0,0开始的,而是存在一个偏移量。
请教一下这样的问题需要怎么解决? 先谢过给位了;
实际显示应该是这样的的:
static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] =
{
{ FRAMEWIN_CreateIndirect, "AR", 0, 0, 0, 128, 64, 0},
{ LISTVIEW_CreateIndirect, NULL, GUI_ID_LISTVIEW0, 0, 0, 128, 64, 0, 0},
};
创建窗口代码:
static WM_HWIN CreateFramewin1(void)
{
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), _cbDialog1, WM_HBKWIN, 0, 0);
return hWin;
}
代码是参考硬汉V6里面音乐播放器的代码创建的:
完整的代码:
- /*********************************************************************
- * 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.32 - 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 : WIDGET_ListView.c
- Purpose : Demonstrates the use of header widgets
- Requirements: WindowManager - (x)
- MemoryDevices - (x)
- AntiAliasing - ( )
- VNC-Server - ( )
- PNG-Library - ( )
- TrueTypeFonts - ( )
- ---------------------------END-OF-HEADER------------------------------
- */
- #include <stddef.h>
- #include <string.h>
- #include "GUI.h"
- #include "LISTVIEW.h"
- #include "FRAMEWIN.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define SPEED 500
- //
- // Recommended memory to run the sample with adequate performance
- //
- #define RECOMMENDED_MEMORY (1024L * 10)
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- static const char * _aTable_1[][2] =
- {
- { "1", "Item 1" },
- { "2", "Item 2" },
- { "3", "Item 3" },
- { "4", "Item 4" },
- { "5", "Item 5" },
- { "6", "Item 6" },
- { "7", "Item 7" },
- { "7", "Item 8" },
- { "9", "Item 9" },
- { "10", "Item 10" },
- { "11", "Item 11" }
- };
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] =
- {
- { FRAMEWIN_CreateIndirect, "AR", 0, 0, 0, 128, 64, 0},
- { LISTVIEW_CreateIndirect, NULL, GUI_ID_LISTVIEW0, 0, 0, 128, 64, 0, 0},
- };
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * Prototypes
- *
- **********************************************************************
- */
- static void _cbDialog1(WM_MESSAGE * pMsg);
- /*
- *********************************************************************************************************
- * 函 数 名: InitDialog
- * 功能说明: 初始化函数
- * 形 参: pMsg
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void InitDialogTask(WM_MESSAGE * pMsg)
- {
- WM_HWIN hWin = pMsg->hWin;
- HEADER_Handle hHeader;
-
-
- char buf[100];
- char searchbuf[100];
- int i = 0;
- SCROLLBAR_Handle hScrollbar;
-
- int uiTotalTime;
- /* 设置框架窗口的Title 直接隐藏即可 */
- FRAMEWIN_SetTitleHeight(hWin,12);
- FRAMEWIN_SetTitleVis(hWin,0);
-
- /* 设置listview控件上的header */
- hHeader = LISTVIEW_GetHeader(WM_GetDialogItem(hWin, GUI_ID_LISTVIEW0));
- HEADER_SetFont(hHeader, &GUI_Font8x8);
- HEADER_SetHeight(hHeader, 12);
-
- /* 设置输入焦点 */
- WM_SetFocus(WM_GetDialogItem(hWin, GUI_ID_LISTVIEW0));
- /* 设置listview控件上的SCROLLBAR */
- hScrollbar = SCROLLBAR_CreateAttached(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), SCROLLBAR_CF_VERTICAL);
- SCROLLBAR_SetWidth(hScrollbar, 20);
- //SCROLLBAR_SetDefaultWidth(35);
- /* 设置LISTVIEW控件 */
- LISTVIEW_SetFont(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), &GUI_Font8x8);
- LISTVIEW_SetRowHeight(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 12);
- LISTVIEW_AddColumn(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 40, "A1", GUI_TA_VCENTER|GUI_TA_LEFT);
- LISTVIEW_AddColumn(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 55, "A2", GUI_TA_VCENTER|GUI_TA_LEFT);
- //LISTVIEW_AddColumn(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 30, "A3", GUI_TA_VCENTER|GUI_TA_LEFT);
-
- LISTVIEW_SetColumnWidth(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 0, 40);
- LISTVIEW_SetColumnWidth(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 1, 55);
- //LISTVIEW_SetColumnWidth(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 2, 35);
- for (i = 0; i < GUI_COUNTOF(_aTable_1); i++)
- {
- LISTVIEW_AddRow(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), _aTable_1[i]);
- }
-
- ////////////////////////////////////////////////////////////////////
- /* 演示功能 自动上移和下移 */
- for (i = 0; i < LISTVIEW_GetNumRows(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0)); i++)
- {
- LISTVIEW_IncSel(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0));
- GUI_Delay(SPEED / 4);
- }
-
- GUI_Delay(SPEED / 4);
-
- for (i = 0; i < LISTVIEW_GetNumRows(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0)); i++)
- {
- LISTVIEW_DecSel(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0));
- GUI_Delay(SPEED / 4);
- }
-
- GUI_Delay(SPEED * 4);
-
- ////////////////////////////////////////////////////////////////////
- }
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _cbDialog1
- */
- static void _cbDialog1(WM_MESSAGE * pMsg)
- {
- WM_HWIN hItem;
- int NCode;
- int Id;
- switch (pMsg->MsgId)
- {
- case WM_INIT_DIALOG:
- //初始化
- InitDialogTask(pMsg);
-
- break;
-
- case WM_NOTIFY_PARENT:
-
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
-
- switch(Id)
- {
- //case ID_BUTTON_0: // Notifications sent by 'Button'
- // switch(NCode)
- // {
- // case WM_NOTIFICATION_CLICKED:
- // // USER START (Optionally insert code for reacting on notification message)
- // // USER END
- // break;
- //
- // case WM_NOTIFICATION_RELEASED:
- // GUI_EndDialog(pMsg->hWin, 0);
- // //GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), _cbDialog2, WM_HBKWIN, 0, 0);
- // break;
- // }
- //break;
- //
- //case ID_BUTTON_1: // Notifications sent by 'Button'
- // switch(NCode)
- // {
- // case WM_NOTIFICATION_CLICKED:
- // // USER START (Optionally insert code for reacting on notification message)
- // // USER END
- // break;
- // case WM_NOTIFICATION_RELEASED:
- // GUI_EndDialog(pMsg->hWin, 0);
- // //GUI_CreateDialogBox(_aDialogCreate3, GUI_COUNTOF(_aDialogCreate3), _cbDialog3, WM_HBKWIN, 0, 0);
- // break;
- // }
- //break;
-
- }
- break;
-
- default:
- WM_DefaultProc(pMsg);
- break;
- }
-
- }
- /*********************************************************************
- *
- * CreateFramewin1
- */
- static WM_HWIN CreateFramewin1(void)
- {
- WM_HWIN hWin;
- hWin = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), _cbDialog1, WM_HBKWIN, 0, 0);
- return hWin;
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void)
- {
- GUI_Init();
-
- //
- // Check if recommended memory for the sample is available
- //
-
- if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY)
- {
- GUI_ErrorOut("Not enough memory available.");
- return;
- }
-
- CreateFramewin1();
-
- while (1)
- {
- GUI_Delay(100);
- }
- }
- /*************************** End of file ****************************/
复制代码 |
|