Proposed changes and additions for version 1.04 of my headers

Started by José Roca, May 10, 2012, 03:51:20 PM

Previous topic - Next topic

José Roca

File: AfxWin.inc


' ========================================================================================
' Retrieves the Internet Explorer version (major.minor).
' ========================================================================================
FUNCTION AfxGetInternetExplorerVersion () AS CURRENCY

   LOCAL hKey     AS DWORD
   LOCAL wszBuff  AS WSTRINGZ * 1024

   IF RegOpenKeyExW(%HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Internet Explorer", 0, _
                    %KEY_QUERY_VALUE, hKey) <> %ERROR_SUCCESS THEN EXIT FUNCTION
   RegQueryValueExW hKey, "Version", 0, 0, wszBuff, SIZEOF(wszBuff)
   RegCloseKey hKey
   FUNCTION = VAL(wszBuff)

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


José Roca

File: AfxPath.inc


' ========================================================================================
' Retrieves the path of the default browser.
' ========================================================================================
FUNCTION AfxGetDefaultBrowserPath () AS WSTRING
   LOCAL wszPath AS WSTRINGZ * %MAX_PATH
   IF SUCCEEDED(AssocQueryStringW(0, %ASSOCSTR_EXECUTABLE, "http", "open", wszPath, SIZEOF(wszPath))) THEN FUNCTION = wszPath
END FUNCTION
' ========================================================================================


José Roca

File: AfxPath.inc


' ========================================================================================
' Retrieves the name of the default browser.
' ========================================================================================
FUNCTION AfxGetDefaultBrowserName () AS WSTRING
   LOCAL wszPath AS WSTRINGZ * %MAX_PATH
   IF SUCCEEDED(AssocQueryStringW(0, %ASSOCSTR_EXECUTABLE, "http", "open", wszPath, SIZEOF(wszPath))) THEN FUNCTION = PATHNAME$(NAMEX, wszPath)
END FUNCTION
' ========================================================================================


José Roca

File: AfxPath.inc


' ========================================================================================
' Retrieves the path of the default mail client.
' ========================================================================================
FUNCTION AfxGetDefaultMailClientPath () AS WSTRING
   LOCAL wszPath AS WSTRINGZ * %MAX_PATH
   IF SUCCEEDED(AssocQueryStringW(0, %ASSOCSTR_EXECUTABLE, "mailto", "open", wszPath, SIZEOF(wszPath))) THEN FUNCTION = wszPath
END FUNCTION
' ========================================================================================


José Roca

File: AfxPath.inc


' ========================================================================================
' Retrieves the name of the default mail client.
' ========================================================================================
FUNCTION AfxGetDefaultMailClientName () AS WSTRING
   LOCAL wszPath AS WSTRINGZ * %MAX_PATH
   IF SUCCEEDED(AssocQueryStringW(0, %ASSOCSTR_EXECUTABLE, "mailto", "open", wszPath, SIZEOF(wszPath))) THEN FUNCTION = PATHNAME$(NAMEX, wszPath)
END FUNCTION
' ========================================================================================


José Roca

File: AfxWin.inc.


' ========================================================================================
' Checks if simple MAPI is installed. Returns TRUE or FALSE.
' ========================================================================================
FUNCTION AfxIsSimpleMapiInstalled () AS LONG
   LOCAL dwChars AS DWORD, wszReturn AS WSTRINGZ * 260
   dwChars = GetPrivateProfileStringW("Mail", "MAPI", BYVAL %NULL, wszReturn, SIZEOF(wszReturn), "win.ini")
   IF dwChars THEN FUNCTION = VAL(wszReturn)
END FUNCTION
' ========================================================================================


José Roca

As there has been interest about using SMTP to send emails, I have taken a class posted by Pauk in the PB Forum and added it to my headers, with minimal changes.

Changed the name of the interfaqce from AfxSmtMail to IAfxSmtpMail for consistency.

José Roca

File: ButtonCtrl.inc


' ========================================================================================
' Assigns an image list to a button control. Requires Windows XP or superior.
' Parameters:
' - hButon     = The handle of the button.
' - hImageList =
' - nLeft      = The x-coordinate of the upper-left corner of the rectangle for the image.
' - nTop       = The y-coordinate of the upper-left corner of the rectangle for the image.
' - nRight     = The x-coordinate of the lower-right corner of the rectangle for the image.
' - nBottom    = The y-coordinate of the lower-right corner of the rectangle for the image.
' - uAlign     = The alignment to use. This parameter can be one of the following values:
'                BUTTON_IMAGELIST_ALIGN_LEFT   Align the image with the left margin.
'                BUTTON_IMAGELIST_ALIGN_RIGHT  Align the image with the right margin
'                BUTTON_IMAGELIST_ALIGN_TOP    Align the image with the top margin
'                BUTTON_IMAGELIST_ALIGN_BOTTOM Align the image with the bottom margin
'                BUTTON_IMAGELIST_ALIGN_CENTER Center the image.
'                The default value is BUTTON_IMAGELIST_ALIGN_LEFT.
' Return value:  If the function succeeds, it returns TRUE. Otherwise it returns FALSE.
' Note:  To use this application programming interface (API), you must provide a manifest
' specifying Comclt32.dll version 6.0.
' ========================================================================================
FUNCTION Button_SetImageListXY (BYVAL hButton AS DWORD, BYVAL hImageList AS DWORD, BYVAL nLeft AS LONG, BYVAL nTop AS LONG, BYVAL nRight AS LONG, BYVAL nBottom AS LONG, OPTIONAL BYVAL uALign AS DWORD) AS LONG
   LOCAL bi AS BUTTON_IMAGELIST
   bi.himl = hImageList : bi.margin.nLeft = nLeft : bi.margin.nTop = nTop
   bi.margin.nRight = nRight : bi.margin.nBottom = nBottom : bi.uAlign = uAlign
   FUNCTION = SendMessage(hButton, %BCM_SETIMAGELIST, 0, VARPTR(bi))
END FUNCTION
' ========================================================================================


José Roca

File: AfxFile.inc


' ========================================================================================
' Loads a file and returns its content as a string.
' Parameter:
' - bstrFileSpec = Path of the file to be loaded. By default, the name is limited to MAX_PATH
'   characters. To extend this limit to 32,767 wide characters, prepend "\\?\" to the path.
' Return value: A string with the contents of the file.
' ========================================================================================
FUNCTION AfxLoadFileToString (BYVAL bstrFileSpec AS WSTRING) AS STRING

   LOCAL hFile AS DWORD
   LOCAL dwFileSize AS DWORD
   LOCAL dwHighSize AS DWORD
   LOCAL bSuccess AS LONG
   LOCAL buffer AS STRING
   LOCAL dwBytesRead AS DWORD

   hFile = CreateFileW(BYCOPY bstrFileSpec, %GENERIC_READ, %FILE_SHARE_READ, _
           BYVAL %NULL, %OPEN_EXISTING, %FILE_FLAG_SEQUENTIAL_SCAN, %NULL)
   IF BITSE(hFile, %INVALID_HANDLE_VALUE, 32) THEN EXIT FUNCTION

   dwFileSize = GetFileSize(hFile, dwHighSize)
   IF dwHighSize THEN
      CloseHandle hFile
      EXIT FUNCTION
   END IF

   buffer = SPACE$(dwFileSize)
   bSuccess = ReadFile(hFile, BYVAL STRPTR(buffer), dwFileSize, dwBytesRead, BYVAL %NULL)
   IF dwBytesRead < dwFileSize THEN buffer = LEFT$(buffer, dwBytesRead)
   FUNCTION = buffer

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


José Roca

File: AfxMisc.inc

Retrieves the address width of the processor. On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64. This function can be used to determine if the processor is 32 or 64 bit.


' ========================================================================================
' Retrieves the address width of the processor. On a 32-bit operating system, the value is
' 32 and on a 64-bit operating system it is 64. This function can be used to determine if
' the processor is 32 or 64 bit.
' ========================================================================================
FUNCTION AfxGetAddressWidth () AS WORD

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL wAddressWidth AS WORD                       ' // uint16

   ' // Connect to WMI using a moniker
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT FUNCTION

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT AddressWidth FROM Win32_Processor"
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT FUNCTION

   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT FUNCTION
   hr = pEnum.Next(1, vItem, BYVAL %NULL)
   IF hr <> %S_OK THEN EXIT FUNCTION
   oItem = vItem
   vItem = EMPTY
   IF ISNOTHING(oItem) THEN EXIT FUNCTION

   ' // Retrieve the value of the property
   OBJECT GET oItem.AddressWidth TO wAddressWidth
   FUNCTION = wAddressWidth

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


José Roca

File: AfxMisc.inc


' ========================================================================================
' Retrieves the system running on the Windows-based computer. The following list identifies
' the returned value: "X86-based PC", "MIPS-based PC", "Alpha-based PC", "Power PC",
' "SH-x PC", "StrongARM PC", "64-bit Intel PC", "64-bit Alpha PC", "Unknown", "X86-Nec98 PC".
' ========================================================================================
FUNCTION AfxGetSystemType () AS WSTRING

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL bstrSystemType AS WSTRING                   ' // System type

   ' // Connect to WMI using a moniker
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT FUNCTION

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT SystemType FROM Win32_ComputerSystem"
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT FUNCTION

   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT FUNCTION
   hr = pEnum.Next(1, vItem, BYVAL %NULL)
   IF hr <> %S_OK THEN EXIT FUNCTION
   oItem = vItem
   vItem = EMPTY
   IF ISNOTHING(oItem) THEN EXIT FUNCTION

   ' // Retrieve the value of the property
   OBJECT GET oItem.SystemType TO bstrSystemType
   FUNCTION = bstrSystemType

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


José Roca

File: AfxMisc.inc


' ========================================================================================
' Retrieves the architecture of the operating system, as opposed to the processor.
' Example: 32-bit. Windows Server 2003, Windows 2000, Windows NT 4.0, Windows XP, and
' Windows Me/98/95: This property is not available.
' ========================================================================================
FUNCTION AfxGetOSArchitecture () AS WSTRING

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL bstrArchitecture AS WSTRING                 ' // Architecture

   ' // Connect to WMI using a moniker
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT FUNCTION

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT OSArchitecture FROM Win32_OperatingSystem"
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT FUNCTION

   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT FUNCTION
   hr = pEnum.Next(1, vItem, BYVAL %NULL)
   IF hr <> %S_OK THEN EXIT FUNCTION
   oItem = vItem
   vItem = EMPTY
   IF ISNOTHING(oItem) THEN EXIT FUNCTION

   ' // Retrieve the value of the property
   OBJECT GET oItem.OSArchitecture TO bstrArchitecture
   FUNCTION = bstrArchitecture

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


José Roca


' ========================================================================================
' Retrieves the type of the computer in use, such as laptop, desktop, or Tablet.
' Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0, and Windows Me/98/95:
' This property is not available.
' Value   Meaning
' ------- --------------------------------------------¡
' 0 (&H0) Unspecified
' 1 (&H1) Desktop
' 2 (&H2) Mobile
' 3 (&H3) Workstation
' 4 (&H4) Enterprise Server
' 5 (&H5) Small Office and Home Office (SOHO) Server
' 6 (&H6) Appliance PC
' 7 (&H7) Performance Server
' 8 (&H8) Maximum
' ========================================================================================
FUNCTION AfxGetPCSystemType () AS WORD

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL wPCSystemType AS WORD                       ' // uint16

   ' // Connect to WMI using a moniker
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT FUNCTION

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT PCSystemType FROM Win32_ComputerSystem"
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT FUNCTION

   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT FUNCTION
   hr = pEnum.Next(1, vItem, BYVAL %NULL)
   IF hr <> %S_OK THEN EXIT FUNCTION
   oItem = vItem
   vItem = EMPTY
   IF ISNOTHING(oItem) THEN EXIT FUNCTION

   ' // Retrieve the value of the property
   OBJECT GET oItem.PCSystemType TO wPCSystemType
   FUNCTION = wPCSystemType

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


José Roca

File: AfxMisc.inc


' ========================================================================================
' Checks if the computer is part of a domain.
' Return value: If TRUE, the computer is part of a domain. If FALSE, the computer is not
' in a domain or the status is unknown. If you unjoin the computer from a domain, the
' value becomes false.
' ========================================================================================
FUNCTION AfxIsPartOfDomain () AS BYTE

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL bPartOfDomain AS BYTE                       ' // boolean

   ' // Connect to WMI using a moniker
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT FUNCTION

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT PartOfDomain FROM Win32_ComputerSystem"
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT FUNCTION

   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT FUNCTION
   hr = pEnum.Next(1, vItem, BYVAL %NULL)
   IF hr <> %S_OK THEN EXIT FUNCTION
   oItem = vItem
   vItem = EMPTY
   IF ISNOTHING(oItem) THEN EXIT FUNCTION

   ' // Retrieve the value of the property
   OBJECT GET oItem.PartOfDomain TO bPartOfDomain
   FUNCTION = bPartOfDomain

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


José Roca

File: AfxMisc.inc


' ========================================================================================
' Name of the domain or workgroup to which a computer belongs.
' If the computer is not part of a domain, then the name of the workgroup is returned.
' If you need to run in both domain-based and workgroup-based environments, you might
' encounter problems using the %USERDOMAIN% environment variable because if the computer
' is not part of a domain, it returns the name of the local computer instead of the
' name of the workgroup.
' ========================================================================================
FUNCTION AfxGetDomainOrWorkGroup () AS WSTRING

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL bstrDomainOrWorkGroup AS WSTRING            ' // Domain or workgroup name

   ' // Connect to WMI using a moniker
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT FUNCTION

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT Domain FROM Win32_ComputerSystem"
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT FUNCTION

   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT FUNCTION
   hr = pEnum.Next(1, vItem, BYVAL %NULL)
   IF hr <> %S_OK THEN EXIT FUNCTION
   oItem = vItem
   vItem = EMPTY
   IF ISNOTHING(oItem) THEN EXIT FUNCTION

   ' // Retrieve the value of the property
   OBJECT GET oItem.Domain TO bstrDomainOrWorkGroup
   FUNCTION = bstrDomainOrWorkGroup

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