I am able to create different dialog boxes but what I am trying to do is that I need to create 2 windows and when I press the button in window 1 then window 2 should be displayed and vice-versa. I went through example codes but could not find anything that does what I want. Any help would be appreciated.
Multiple windows handling on button click event
This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.
-
-
Hi,
Something like this (attached)?
I create one window with a button. On button release I create a second window and delete the first. The second window has also a button. On press I create the first one again and delete the second one.
Regards,
SvenPlease read the forum rules before posting.
Keep in mind, this is *not* a support forum.
Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
Should you be entitled to support you can contact us via our support system: segger.com/ticket/
Or you can contact us via e-mail. -
This works fine but what I am trying to do is following:
1. My display is 640x480 and I want to create first page (GUI_BLUE) with full display size. A button on this page, when pressed, would take me to another page (GUI_RED).
2. Button on second page, when pressed, takes me back to the BLUE page.
Can this be achieved by WM_SetFocus() when button is pressed?
Since the display size is 640x480, I think I would have to create a display of XSize 640*2. I am not sure about this though. -
I have attached my code as well as output after making some changes to your code.
When I debug this code, I get the following result:
1. The code starts with the display showing a small red window with the button named "Select Win2".
2. When I press "Select Win2" button, I get a green window (fully covers the display since I have passed LCD_GetXSize() and LCD_GetYSize() as arguments) with a button named "Select Win1".
3. When I press "Select Win1" button, I get a red window which again fully covers the display due to the above mentioned reason.
4. The display then toggles between these red and green windows on button press.
This is not what I want.
I want the code to display a window with "Select Win2" button as my starting point. Then the windows should change on button press. I hope I am clear with my end result. -
C Source Code
- #include "DIALOG.h"
- /*********************************************************************
- *
- * Externals
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * Types
- *
- **********************************************************************
- */
- static void _cbWinB(WM_MESSAGE * pMsg);
- static void _cbWinC(WM_MESSAGE * pMsg);
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _cbWinA
- */
- static void _cbWinA(WM_MESSAGE * pMsg) {
- int NCode;
- int Id;
- BUTTON_Handle hButton;
- GUI_RECT Rect;
- switch (pMsg->MsgId) {
- case WM_CREATE:
- hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
- BUTTON_SetText(hButton, "Go To Page 2");
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch(Id) {
- case GUI_ID_BUTTON0:
- switch(NCode) {
- case WM_NOTIFICATION_RELEASED:
- WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinB, 0);
- WM_DeleteWindow(pMsg->hWin);
- break;
- }
- break;
- }
- break;
- case WM_PAINT:
- GUI_SetBkColor(GUI_RED);
- GUI_SetColor(GUI_BLACK);
- GUI_Clear();
- GUI_SetFont(GUI_FONT_32B_ASCII);
- GUI_GetClientRect(&Rect);
- GUI_DispStringInRect("Page 1", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * _cbWinB
- */
- static void _cbWinB(WM_MESSAGE * pMsg) {
- int NCode;
- int Id;
- BUTTON_Handle hButton;
- GUI_RECT Rect;
- switch (pMsg->MsgId) {
- case WM_CREATE:
- hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
- BUTTON_SetText(hButton, "Go To Page 3");
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch(Id) {
- case GUI_ID_BUTTON0:
- switch(NCode) {
- case WM_NOTIFICATION_RELEASED:
- WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinC, 0);
- WM_DeleteWindow(pMsg->hWin);
- break;
- }
- break;
- }
- break;
- case WM_PAINT:
- GUI_SetBkColor(GUI_GREEN);
- GUI_SetColor(GUI_BLACK);
- GUI_Clear();
- GUI_SetFont(GUI_FONT_32B_ASCII);
- GUI_GetClientRect(&Rect);
- GUI_DispStringInRect("Page 2", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * _cbWinC
- */
- static void _cbWinC(WM_MESSAGE * pMsg) {
- int NCode;
- int Id;
- BUTTON_Handle hButton;
- GUI_RECT Rect;
- switch (pMsg->MsgId) {
- case WM_CREATE:
- hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
- BUTTON_SetText(hButton, "Go To Page 1");
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch(Id) {
- case GUI_ID_BUTTON0:
- switch(NCode) {
- case WM_NOTIFICATION_RELEASED:
- WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinA, 0);
- WM_DeleteWindow(pMsg->hWin);
- break;
- }
- break;
- }
- break;
- case WM_PAINT:
- GUI_SetBkColor(GUI_BLUE);
- GUI_SetColor(GUI_BLACK);
- GUI_Clear();
- GUI_SetFont(GUI_FONT_32B_ASCII);
- GUI_GetClientRect(&Rect);
- GUI_DispStringInRect("Page 3", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * _cbBk
- */
- static void _cbBk(WM_MESSAGE * pMsg) {
- switch (pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(GUI_BLACK);
- GUI_Clear();
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- // GUI_Init();
- // WM_MULTIBUF_Enable(1);
- WM_SetCallback(WM_HBKWIN, _cbBk); //Makes sure the window will be redrawn
- WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinA, 0);
- while (1) {
- GUI_Delay(100);
- }
- }
- /*************************** End of file ****************************/
Thank you Shoenen!The post was edited 2 times, last by hrm2519 ().
-
I do it differently. Is it legal?
tskGUI
...
// Screen numbering
//enum {W_SETTINGS, W_WPRIMCH1, W_WPRIMCH2, W_WTIME, W_MAX};
// Current screen number. Declaring the function of creating a dialog.
int16_t NScreen = W_SETTINGS;
WM_HWIN (*pCreateWin[W_MAX])() =
{
CreateWSettings, CreateWPrimCh1, CreateWPrimCh2, CreateWTime,
};
WM_HWIN hCurWin = NULL;
...
// Declare a callback routine on a blank screen
WM_SetCallback(WM_GetDesktopWindowEx(0), _cbBk);
// start GUI
//hCurWin = CreateWSettings();
hCurWin = pCreateWin[NScreen]();
WM_ShowWindow(hCurWin);
// Show the main menu
WM_Exec();
CleanDisplay(0xC0000000);
// Gui background Task
while(1)
{
GUI_Exec(); // Do the background work ... Update windows etc.)
osDelay(10);
}
....
static void _cbBk(WM_MESSAGE * pMsg)
{
uint32_t NCode/*, Id*/;
switch (pMsg->MsgId)
{
case WM_PAINT:
break;
case WM_NOTIFY_PARENT:
//Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (NCode)
{
case WM_NOTIFICATION_CHILD_DELETED:
if(NScreen < 0) NScreen = 0;
if(NScreen > W_MAX) NScreen = 0;
hCurWin = pCreateWin[NScreen]();
WM_ShowWindow(hCurWin);
break;
default:
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
......
The screen is rendered as a dialog. Like that...
WM_HWIN CreateWPrimCh1(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
....
The transition by the button is carried out as follows.
case ID_BUTTON_BACK: // Notifications sent by 'Back'
switch(NCode) {
case WM_NOTIFICATION_RELEASED:
NScreen = W_SETTINGS;
GUI_EndDialog(pMsg->hWin, 0);
WM_HideWindow(hCurWin);
WM_Exec();
break;
}
break;
....