Proposed changes and additions for version 1.05 of my headers

Started by José Roca, August 29, 2012, 05:06:53 PM

Previous topic - Next topic

José Roca

Changed the RPC_STATUS return value in the Rpc functions from DWORD to LONG, since the C++ headers define STATUS as LONG.

Removed a couple of conditions in the file esent.inc.
See: http://www.jose.it-berater.org/smfforum/index.php?topic=4562.msg17116#msg17116

New macro:



' ========================================================================================
' Returns the largest integral value that is not greater than x.
' Can be used to emulate the C floor function.
' ========================================================================================
MACRO AfxFloor(x) = INT(x)
' ========================================================================================


In AfxWin.inc.

José Roca

File: AfxWin.inc.


' ========================================================================================
' Rounds a numeric value to a specified number of decimal places. Uses the "round up at
' five" approach instead of "banker's rounding".
' numDigits n is an  expression specifying the number of decimal places required in the result.
' AfxRound is especially useful in cases where you have a variable in Single, Double, or
' Extended-precision, and you want to put it into a Currency variable or display it, rounded
' to a specific number of decimal places.
' Note: PowerBASIC uses the IIEE standard for rounding. It is  is implemented by the "banker's
' rounding" principle: if the fractional digit being rounded off is exactly five, with no
' trailing digits, the number is rounded to the nearest even number.
' Unfortunately, in the business world nobody uses banker's rounding, not even the bankers.
' In the EU, the "round up at five" approach is mandatory by law. This makes all the
' functions/statements and numeric types that use banker's rounding useless for business
' applications in the EU.
' ========================================================================================
FUNCTION AfxRound (BYVAL extValue AS EXT, BYVAL numDigits AS LONG) AS EXT
   LOCAL nMult AS LONG
   nMult = 10 ^ numDigits
   FUNCTION = FIX((nMult * extValue + (SGN(extValue)) * .5##)) / nMult
END FUNCTION
' ========================================================================================


José Roca

File: AfxFile.inc.


' ========================================================================================
' Get file content type from file extension looking at the registry.
' ========================================================================================
FUNCTION AfxGetContentTypeFromFileExt (BYVAL bstrExt AS WSTRING) AS WSTRING

   LOCAL hr       AS LONG
   LOCAL hKey     AS DWORD
   LOCAL wszBuff  AS WSTRINGZ * 1024

   IF LEFT$(bstrExt, 1) <> "." THEN bstrExt += "."
   IF RegOpenKeyExW(%HKEY_CLASSES_ROOT, BYCOPY bstrExt, 0, %KEY_QUERY_VALUE, hKey) = %ERROR_SUCCESS THEN
      IF hKey THEN
         ' // First look at the content type
         hr = RegQueryValueExW(hKey, "Content Type", 0, 0, wszBuff, SIZEOF(wszBuff))
         ' // If it fails, look at the default value
         IF hr <> %ERROR_SUCCESS THEN RegQueryValueExW(hKey, "", 0, 0, wszBuff, SIZEOF(wszBuff))
         RegCloseKey hKey
         wszBuff = EXTRACT$(wszBuff, CHR$(0))
      END IF
   END IF

   IF LEN(wszBuff) = 0 THEN wszBuff = "Unknown"
   FUNCTION = wszBuff

END FUNCTION
' ========================================================================================


José Roca

File: ListViewCtrl.inc.


' ========================================================================================
' Retrieves the font used by the ToolTip control that the list-view control uses to display ToolTips.
' ========================================================================================
FUNCTION LietView_GetTooltipsFont (BYVAL hwndLV AS DWORD) AS DWORD
   LOCAL hwndTooltips AS DWORD
   hwndTooltips = SendMessage(hwndLV, %LVM_GETTOOLTIPS, 0, 0)
   FUNCTION = SendMessage(hwndTooltips, %WM_GETFONT, 0, 0)
END FUNCTION
' ========================================================================================


José Roca

File: ListViewCtrl.inc.


' ========================================================================================
' Sets the font used by the ToolTip control that the list-view control uses to display ToolTips.
' Parameters:
' - hwndLV  = Handle to the ListView control.
' - hFont   = Handle to the font. If this parameter is NULL, the control uses the default system font to draw text.
' - fRedraw = Specifies whether the control should be redrawn immediately upon setting the font.
'             If this parameter is TRUE, the control redraws itself.
' ========================================================================================
SUB ListView_SetTooltipsFont (BYVAL hwndLV AS DWORD, OPTIONAL BYVAL hFont AS DWORD, OPTIONAL BYVAL fRedraw AS LONG)
   LOCAL hwndTooltips AS DWORD
   hwndTooltips = SendMessage(hwndLV, %LVM_GETTOOLTIPS, 0, 0)
   SendMessage hwndTooltips, %WM_SETFONT, hFont, fRedraw
END SUB
' ========================================================================================


José Roca

File: TooltipCtrl.inc


' ========================================================================================
' Retrieves the handle of the font used by the ToolTip control.
' ========================================================================================
FUNCTION Tooltip_GetFont (BYVAL hTooltip AS DWORD) AS DWORD
   FUNCTION = SendMessage(hTooltip, %WM_GETFONT, 0, 0)
END FUNCTION
' ========================================================================================


José Roca

File: TooltipCtrl.inc


' ========================================================================================
' Sets the font used by the ToolTip control.
' Parameters:
' - hTooltip  = Handle to the ToolTip control.
' - hFont   = Handle to the font. If this parameter is NULL, the control uses the default system font to draw text.
' - fRedraw = Specifies whether the control should be redrawn immediately upon setting the font.
'             If this parameter is TRUE, the control redraws itself.
' ========================================================================================
SUB Tooltip_SetFont (BYVAL hTooltip AS DWORD, OPTIONAL BYVAL hFont AS DWORD, OPTIONAL BYVAL fRedraw AS LONG)
   SendMessage hTooltip, %WM_SETFONT, hFont, fRedraw
END SUB
' ========================================================================================