I am trying to create a custom widget for use within a dialog that has child widgets. The child widgets do not seem to be working, I am rather new to using emwin - am I doing something completely wrong?
Widget C File:
Display All
Dialog that uses custom widget:
Display All
Thanks.
Widget C File:
C Source Code
- #include <stdlib.h>
- #include <string.h>
- #include "WIDGET.h"
- #include "dialog.h"
- #include "utility.h"
- #define ID_BUTTON_1 (GUI_ID_USER + 0x200)
- typedef WM_HMEM MYWIDGET_Handle;
- /*********************************************************************
- *
- * MYWIDGET_Obj
- */
- typedef struct {
- BUTTON_Handle hButton1;
- int NumExtraBytes;
- } MYWIDGET_Obj;
- const MYWIDGET_Obj MYWIDGET_Default = {
- 0,
- 0
- };
- static void MyWidget_Callback(WM_MESSAGE * pMsg)
- {
- switch (pMsg->MsgId) {
- default:
- WINDOW_Callback(pMsg);
- }
- }
- static void MyWidgetButton_Callback(WM_MESSAGE * pMsg)
- {
- switch (pMsg->MsgId) {
- default:
- BUTTON_Callback(pMsg);
- }
- }
- MYWIDGET_Handle MyWidget_CreateIndirect(const GUI_WIDGET_CREATE_INFO *pCreateInfo,
- WM_HWIN hParent, int x0, int y0, WM_CALLBACK *cb)
- {
- WM_HWIN hWin;
- MYWIDGET_Obj MyWidget;
- GUI_WIDGET_CREATE_INFO CreateInfo = *pCreateInfo;
- GUI_WIDGET_CREATE_INFO ButtonCreateInfo = {0};
- MyWidget = MYWIDGET_Default;
- MyWidget.NumExtraBytes = pCreateInfo->NumExtraBytes;
- CreateInfo.NumExtraBytes = pCreateInfo->NumExtraBytes + sizeof(MYWIDGET_Obj);
- hWin = WINDOW_CreateIndirect(&CreateInfo, hParent, 0, 0, 0);
- WINDOW_SetBkColor(hWin, 0x00d2b996);
- ButtonCreateInfo.pName = "Button 1";
- ButtonCreateInfo.Id = ID_BUTTON_1;
- ButtonCreateInfo.x0 = 0;
- ButtonCreateInfo.y0 = 0;
- ButtonCreateInfo.xSize = 30;
- ButtonCreateInfo.ySize = 30;
- MyWidget.hButton1 = BUTTON_CreateIndirect(&ButtonCreateInfo, hWin, 0, 0, 0);
- WM_SetCallback(hWin, MyWidget_Callback);
- WM_SetCallback(MyWidget.hButton1, MyWidgetButton_Callback);
- WM_SetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj));
- return hWin;
- }
Dialog that uses custom widget:
C Source Code
- #include "DIALOG.h"
- typedef WM_HMEM MYWIDGET_Handle;
- MYWIDGET_Handle MyWidget_CreateIndirect(const GUI_WIDGET_CREATE_INFO *pCreateInfo,
- WM_HWIN hParent, int x0, int y0, WM_CALLBACK *cb);
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_MY_WIDGET_0 (GUI_ID_USER + 0x30)
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Widget Test", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
- { MyWidget_CreateIndirect, "", ID_MY_WIDGET_0, 100, 100, 130, 37, 0, 0, 0 },
- };
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- switch (pMsg->MsgId) {
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * CreateTestDLG
- */
- WM_HWIN CreateTestDLG(void);
- WM_HWIN CreateTestDLG(void) {
- WM_HWIN hWin;
- hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- return hWin;
- }
- /*************************** End of file ****************************/
Thanks.