Hello.
Very usual conditions:
There is a FrameWindow with some widgets, one of them is DROPDOWN (in attached sample there is only a single DROPDOWN - for simplify).
And there is a dedicated key (in attached sample it is SHIFT-key) for calling another window (for example MessageBox).
If this window being closed then the control and focus should return to the widget, from which this window was called.
So, if press a key while a DROPDOWN-widget is in opened state (opened by SPACE-key), then after return from called window there is a run-tume error, because DROPDOWN-widget was closed, and already there is no object (derived listbox-item), from which this window was opened.
Display All
How to resolve this issue?
Very usual conditions:
There is a FrameWindow with some widgets, one of them is DROPDOWN (in attached sample there is only a single DROPDOWN - for simplify).
And there is a dedicated key (in attached sample it is SHIFT-key) for calling another window (for example MessageBox).
If this window being closed then the control and focus should return to the widget, from which this window was called.
So, if press a key while a DROPDOWN-widget is in opened state (opened by SPACE-key), then after return from called window there is a run-tume error, because DROPDOWN-widget was closed, and already there is no object (derived listbox-item), from which this window was opened.
C Source Code
- #include "DIALOG.h"
- #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
- #define ID_DROPDOWN_0 (GUI_ID_USER + 0x01)
- #define RECOMMENDED_MEMORY (1024L * 5)
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240, 0, 0x0, 0 },
- { DROPDOWN_CreateIndirect, "Dropdown", ID_DROPDOWN_0, 100, 40, 80, 80, 0, 0x0, 0 },
- };
- void messageBox(const char * pText, const char * pCaption) {
- WM_HWIN focusedWindow = WM_GetFocussedWindow();
- GUI_MessageBox(pText, pCaption, GUI_MESSAGEBOX_CF_MODAL | GUI_MESSAGEBOX_CF_MOVEABLE);
- WM_SetFocus(focusedWindow);
- }
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- int NCode;
- int Id;
- WM_KEY_INFO * pInfo = (WM_KEY_INFO *)pMsg->Data.p;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_DROPDOWN_0);
- DROPDOWN_AddString(hItem, "Item 1");
- DROPDOWN_AddString(hItem, "Item 2");
- DROPDOWN_AddString(hItem, "Item 3");
- break;
- case WM_KEY:
- if (pInfo->PressedCnt == 0) {
- switch (pInfo->Key) {
- case GUI_KEY_SHIFT:
- messageBox("Message", "Title");
- break;
- }
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- static WM_HWIN CreateFramewin(void) {
- WM_HWIN hWin;
- hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- return hWin;
- }
- void MainTask(void) {
- GUI_Init();
- if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
- GUI_ErrorOut("Not enough memory available.");
- return;
- }
- CreateFramewin();
- while (1) {
- GUI_Delay(100);
- };
- }
How to resolve this issue?
Best regards,
Volodymyr.
Volodymyr.
The post was edited 1 time, last by volodymyr ().