Creating a context aware application for 2-in-1 devices

Applications running on 2-in-1 tablets can either be in laptop mode or desktop mode when running. Note that the laptop mode and desktop mode are different from landscape and portrait modes.Laptop mode refers to users interacting with the application via touch input and gestures whereas desktop mode refers to users interacting with application via the keyboard and mouse. Applications need to be contextually aware when the device mode has changed and switch between the modes accordingly.Making your application contextually aware will enable the user interface elements to be correctly sized as you switch between the modes and thus result in an adaptive UI
You can receive a message from Windows when the context changes through the WM_SETTINGCHANGE messagein your application.The mode status is accessed through the  “ConvertibleSlateMode” in the LPARAM parameter. as shown in the snippet below

...

//---------------------------------------------------------------------
// Process system setting update.
//---------------------------------------------------------------------
case WM_SETTINGCHANGE:

   //-----------------------------------------------------------------
   // Check slate status.
   //-----------------------------------------------------------------
   if(
      ((TCHAR *)lparam != NULL) &&
      (
         _tcsnccmp(
            (TCHAR *)lparam,
            CONVERTIBLE_SLATE_MODE_STRING,
            _tcslen(CONVERTIBLE_SLATE_MODE_STRING)
         ) == 0
       )
   ) {

      //-------------------------------------------------------------
      // Note:
      //    SM_CONVERTIBLESLATEMODE reflects the state of the 
      // laptop or slate mode. When this system metric changes,
      // the system sends a broadcast message via WM_SETTING...
      // CHANGE with "ConvertibleSlateMode" in the LPARAM.
      // Source: MSDN.
      //-------------------------------------------------------------
      ret = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);
      if(ret == 0) {
         data._2_in_1_data.device_configuration = 
            DEVICE_CONFIGURATION_TABLET
         ;
      } else {
         data._2_in_1_data.device_configuration = 
            DEVICE_CONFIGURATION_NON_TABLET
         ;
      }

A “0” returned means it is in tablet mode. A “1” returned means it is in non-tablet mode. With this information, we can now update the UI elements accordingly as shown below

...
ret = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);
   if(ret == 0) {
      data._2_in_1_data.device_configuration = 
      DEVICE_CONFIGURATION_TABLET
      ;
          //TODO
         //update UI elements accordingly

   } else {
         data._2_in_1_data.device_configuration = 
            DEVICE_CONFIGURATION_NON_TABLET
         ;
         //TODO
         //update UI elements accordingly
      }
...
Posted in win

Leave a Reply

Your email address will not be published. Required fields are marked *