Restart timer when a Window become visible

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

    • Restart timer when a Window become visible

      Hi all,

      I have an application where, in the main window, after 5 seconds of inactivity, display controller and backlight are switched off, then, touching the screen, they are activated again.
      I create a timer:

      C Source Code

      1. case WM_INIT_DIALOG:
      2. hTimer = WM_CreateTimer(pMsg->hWin, 0, 5000, 0);


      In the timer expired messages I switch off the screen (excuse me for the crude and not readable method, it will be changed after)...

      C Source Code

      1. case WM_TIMER:
      2. *(__IO uint16_t *) ((uint32_t)0x60000000) = 0x0010; // put display controller in sleep mode (see SSD1963 datasheet)
      3. __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); // disable display backlight
      4. break;


      Then, when the screen is touched, the LCD is enabled again and the timer restarted:

      C Source Code

      1. case WM_TOUCH:
      2. *(__IO uint16_t *) ((uint32_t)0x60000000) = 0x0011; // put display controller out sleep mode (see SSD1963 datasheet)
      3. __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 50); //enable display backlight
      4. WM_RestartTimer(hTimer, 5000); //restart display sleep timer
      5. break;


      Then, pressing a button on the main screen I create a new window with a setting menu and delete the timer because, leaving the main screen, display must not be switched off.

      C Source Code

      1. case WM_NOTIFICATION_RELEASED:
      2. // USER START (Optionally insert code for reacting on notification message)
      3. inSettings = 1;
      4. WM_DeleteTimer(hTimer);
      5. CreateSettings();
      6. // USER END
      7. break;


      The background window is not deleted but when I leave the setting menu only the new window is deleted and the background window gets visibility.
      How do I activate the timer again when the background windows become visible again?

      Thanks
    • Hi,

      You can react on WM_DELETE of the setting menu and create a timer attached to the main window.

      Like this:

      C Source Code

      1. case WM_DELETE:
      2. hParent = WM_GetParent(pMsg->hWin);
      3. WM_CreateTimer(hParent, ID_TIMER, 5000, 0);
      4. break;


      If the main window is not the parent you can also save its handle in a global variable.

      You can also try to react on WM_NOTIFY_VIS_CHANGED in the callback of the main window.

      Regards
      Sven