KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Return Windows Border and Title Bar Thickness
PRODUCT: 4D | VERSION: 16 | PLATFORM: Win
Published On: November 28, 2017

Below is a utility method to return the current Windows Border and Title Bar Thickness for the current user in pixels.

// Method: Util_Get_Win_BorderWidth
//
// Details: Windows Only, Gets the current Window's session BorderWidth
//
// Input:
// $1 - Pointer to Longint to contain resulting title height
// $2 - Pointer to Longint to contain resulting frame size


C_POINTER($1)
C_POINTER($2)

C_LONGINT($result_l)

C_TEXT($in;$out;$err)
C_TEXT($regSearch_t)
C_TEXT($regexPat_t)
C_LONGINT($pos_l)
C_LONGINT($foundPos_l)
C_LONGINT($length_l)
C_BOOLEAN($found_b)
C_LONGINT($borderWidth_l)
C_LONGINT($borderPadding_l)
C_LONGINT($titleHeight_l)
ARRAY TEXT($resultLines_at;0)
ARRAY TEXT($locations_at;0)

$result_l:=0

$in:=""
SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"True")
$regSearch_t:="REG QUERY \"HKCU\\Control Panel\\Desktop\\WindowMetrics\" /v BorderWidth"
LAUNCH EXTERNAL PROCESS($regSearch_t;$in;$out;$err)

$found_b:=Match regex("ERROR";$out;1)=False
If ($found_b=True)
  $regexPat_t:=" BorderWidth REG_SZ "
  $pos_l:=1
  $found_b:=Match regex($regexPat_t;$out;1;$foundPos_l;$length_l)

  If ($found_b=True)
    $regexPat_t:="-\\d+"
    $found_b:=Match regex($regexPat_t;$out;1;$foundPos_l;$length_l)
    $borderWidth_l:=Num(Substring($out;$foundPos_l;$length_l))/-15

    $in:=""
    SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"True")
    $regSearch_t:="REG QUERY \"HKCU\\Control Panel\\Desktop\\WindowMetrics\" /v PaddedBorderWidth"
    LAUNCH EXTERNAL PROCESS($regSearch_t;$in;$out;$err)

    $found_b:=Match regex("ERROR";$out;1)=False
    If ($found_b=True)
      $regexPat_t:=" PaddedBorderWidth REG_SZ "
      $pos_l:=1
      $found_b:=Match regex($regexPat_t;$out;1;$foundPos_l;$length_l)

      If ($found_b=True)
        $regexPat_t:="-\\d+"
        $found_b:=Match regex($regexPat_t;$out;1;$foundPos_l;$length_l)
        $borderPadding_l:=Num(Substring($out;$foundPos_l;$length_l))/-15

        $in:=""
        SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"True")
        $regSearch_t:="REG QUERY \"HKCU\\Control Panel\\Desktop\\WindowMetrics\" /v CaptionHeight"
        LAUNCH EXTERNAL PROCESS($regSearch_t;$in;$out;$err)

        $found_b:=Match regex("ERROR";$out;1)=False
        If ($found_b=True)
          $regexPat_t:=" CaptionHeight REG_SZ "
          $pos_l:=1
          $found_b:=Match regex($regexPat_t;$out;1;$foundPos_l;$length_l)

          If ($found_b=True)
            $regexPat_t:="-\\d+"
            $found_b:=Match regex($regexPat_t;$out;1;$foundPos_l;$length_l)
            $titleHeight_l:=Num(Substring($out;$foundPos_l;$length_l))/-15
          End if
        End if
      End if
    End if
  End if
End if

If ($found_b=True)
   $1->:=$borderWidth_l+$borderPadding_l
   $2->:=$borderWidth_l+$borderPadding_l+$titleHeight_l
Else
   $1->:=-1
   $2->:=-1
End if