window never gets the focus

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • window never gets the focus

    Hello to everybody,


    likely my question is a silly one but I have not been able to find out an answer looking at the documentation.

    I have one Window with one widget, an IMAGE one. My need is that of implementing a simple slide show
    application.

    So I wrote this main routine


    static void _Main(void)
    {
    U8 i = 0;
    WM_HWIN hWin_focussed;

    WM_SelectWindow(WM_HBKWIN);

    GUI_Clear();

    hWin_0 = CreateWindow_0();
    WM_ShowWindow(hWin_0);

    WM_SetFocus(hWin_0);
    hWin_focussed = WM_GetFocussedWindow();

    GUI_Exec();

    while (1)
    {
    for (i=0; i<NUM_OF_PICTURES; i++)
    {
    pData_slide_show = (void *) _GetImageById(Id_array, &FileSize_slide_show);
    IMAGE_SetDTA(hItem_slide_show, pData_slide_show, FileSize_slide_show);
    GUI_Delay(5000);
    }
    }

    //
    // Cleanup (to do some WM_DeleteWindow())
    //
    }

    And the slide show mechanism works displaying the images sequence with 5s interval between two consecutive images.

    Since I have some mechanical buttons on my board I would like to make the slide show interactive, with up and down actions,
    so I have written a routine that detects the key press events and sends the event information through the


    GUI_SendKeyMsg (Key, 1);

    function.

    The problem is that in the cbdialog callback function of window_0 the WM_KEY events are never detected, only the
    WM_INIT_DIALOG, WM_PRE_PAINT, WM_PAINT, and so on, are detected.


    As if window_0 had not received the focus.

    And actually the

    WM_SetFocus(hWin_0);


    returns 1 meaning that the window cannot get the focus
    and
    WM_GetFocussedWindow();


    returns 0 meaning that no window has the input focus.

    How can I change this behaviour?

    Thanks in advance,
    Ezio
  • ezio_noventa wrote:

    I (somehow) solved the issue by adding a 'button' widget to the window.
    In that way the window gets the focus.

    Is it a mandatory setting? I mean, does a window have to have a sort of 'input' widget in order to be focussable?

    Ezio
    Hi Ezio,

    From my limited experience, a Window widget cannot be focused, it has to contain a button ( as you did) or something to receive the focus.
  • Hello Ezio,

    The following sample should help you enable focussability in your dialog:

    C Source Code

    1. #include "DIALOG.h"
    2. #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
    3. #define MESSAGE_APP (WM_USER + 0x00)
    4. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    5. { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240, 0, 0x0, 0 },
    6. };
    7. static void _cbDialog(WM_MESSAGE * pMsg) {
    8. static WM_CALLBACK * pcbClient;
    9. static U8 Flag;
    10. if (Flag == 0) {
    11. Flag = 1;
    12. switch (pMsg->MsgId) {
    13. case WM_SET_FOCUS:
    14. //
    15. // Tell WM that focus is accepted
    16. //
    17. pMsg->Data.v = 0;
    18. break;
    19. case MESSAGE_APP:
    20. //
    21. // Remember default callback
    22. //
    23. pMsg->Data.v = 0;
    24. pcbClient = (WM_CALLBACK *)pMsg->Data.v;
    25. break;
    26. case WM_KEY:
    27. //
    28. // Do something...
    29. //
    30. break;
    31. default:
    32. //
    33. // Pass all other messages to default callback
    34. //
    35. if (pcbClient) {
    36. pcbClient(pMsg);
    37. }
    38. break;
    39. }
    40. Flag = 0;
    41. }
    42. }
    43. static void _CreateFramewin(void) {
    44. WM_HWIN hWin, hClient;
    45. WM_CALLBACK * pcbClient;
    46. WM_MESSAGE Msg = {0};
    47. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    48. //
    49. // Overwrite client callback of frame window...
    50. //
    51. hClient = WM_GetClientWindow(hWin);
    52. pcbClient = WM_SetCallback(hClient, _cbDialog);
    53. //
    54. // ...and pass default pointer to the application defined callback function
    55. //
    56. Msg.hWin = hClient;
    57. Msg.Data.v = (U32)pcbClient;
    58. Msg.MsgId = MESSAGE_APP;
    59. WM_SendMessage(hClient, &Msg);
    60. //
    61. // Set focus to dialog which does not have focussable child widgets
    62. //
    63. WM_SetFocus(hClient);
    64. return;
    65. }
    66. void MainTask(void) {
    67. GUI_Init();
    68. _CreateFramewin();
    69. while (1) {
    70. GUI_Delay(100);
    71. }
    72. }
    Display All

    Best regards,
    Adrian