September 26, 2022, 06:49:22 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


SystemAPI Subroutines

Started by ExMember001, September 02, 2006, 10:54:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

This is a little collection of subroutines to get system informations

Functions:

GetSysFonts(int hdc);
Get installed fonts names on the system

GetSysFontsCallback(LOGFONT lpNLF,NEWTEXTMETRIC lpNTM, int FontType, int LParam);
This is the GetSysFonts Callback where you tell what to do with the font name

GetSysUsername();
Return the current Windows Username in a string

GetWinOSName();
Return the Name of the Windows OS in a string

GetWinOSProductTypeNT();
Return the Windows NT Product Type in a string

GetWinOSServicePack();
Return the Service Pack Installed in a string


SysAPI.src

////////////////////////////////////////////////////////////////////////////////
// System API Subroutines by Krypt
////////////////////////////////////////////////////////////////////////////////
/*
extern void   GetSysFonts(int hdc);
extern int    GetSysFontsCallback(LOGFONT lpNLF,NEWTEXTMETRIC lpNTM, int FontType, int LParam);
extern string GetSysUsername();
extern string GetWinOSName();
extern string GetWinOSProductTypeNT();
extern string GetWinOSServicePack();
*/

#ifndef Advapi32
#define Advapi32
  #use "advapi32.lib"
#EndIf

#ifndef Gdi32
#define Gdi32
  #use "Gdi32.lib"
#EndIf

#ifndef SysAPI
#define SysAPI
struct OSVERSIONINFO
{
UNSIGNED INT dwOSVersionInfoSize;
UNSIGNED INT dwMajorVersion;
UNSIGNED INT dwMinorVersion;
UNSIGNED INT dwBuildNumber;
UNSIGNED INT dwPlatformId;
DSTRING szCSDVersion[128];
}

struct OSVERSIONINFOEX
{
UNSIGNED INT dwOSVersionInfoSize;
UNSIGNED INT dwMajorVersion;
UNSIGNED INT dwMinorVersion;
UNSIGNED INT dwBuildNumber;
UNSIGNED INT dwPlatformId;
DSTRING szCSDVersion[128];
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wSuiteMask;
BYTE wProductType;
BYTE wReserved;
}

struct LOGFONT
{
  INT lfHeight;
  INT lfWidth;
  INT lfEscapement;
  INT lfOrientation;
  BYTE lfWeight;
  BYTE lfItalic;
  BYTE lfUnderline;
  BYTE lfStrikeOut;
  BYTE lfCharSet;
  BYTE lfOutPrecision;
  BYTE lfClipPrecision;
  BYTE lfQuality;
  BYTE lfPitchAndFamily;
  unsigned word lfFaceName[LF_FACESIZE];
}

struct NEWTEXTMETRIC
{
    INT        tmHeight;
    INT        tmAscent;
    INT        tmDescent;
    INT        tmInternalLeading;
    INT        tmExternalLeading;
    INT        tmAveCharWidth;
    INT        tmMaxCharWidth;
    INT        tmWeight;
    INT        tmOverhang;
    INT        tmDigitizedAspectX;
    INT        tmDigitizedAspectY;
    UNSIGNED BYTE        tmFirstChar;
    UNSIGNED BYTE        tmLastChar;
UNSIGNED BYTE        tmDefaultChar;
    UNSIGNED BYTE        tmBreakChar;
    BYTE        tmItalic;
    BYTE        tmUnderlined;
    BYTE        tmStruckOut;
    BYTE        tmPitchAndFamily;
    BYTE        tmCharSet;
    UNSIGNED INT        ntmFlags;
    UNSIGNED INT        ntmSizeEM;
    UNSIGNED INT        ntmCellHeight;
    UNSIGNED INT        ntmAvgWidth;
}

import INT     EnumFontFamilies alias EnumFontFamiliesA(INT hdc, INT lpLogfont, POINTER lpProc, INT lParam);
import POINTER lstrcpyn alias lstrcpynA(POINTER lpString1,POINTER lpString2,INT iMaxLength);
import INT     GetUserNameA(POINTER lpBuffer,POINTER lpnSize);
import INT     GetVersionExA(OSVERSIONINFO lpVersionInformation);

#define TRUETYPE_FONTTYPE  0x0004

#define VER_PLATFORM_WIN32s          0
#define VER_PLATFORM_WIN32_WINDOWS   1
#define VER_PLATFORM_WIN32_NT        2
#define VER_NT_WORKSTATION         1
#define VER_NT_DOMAIN_CONTROLLER   2
#define VER_NT_SERVER              3
#define VER_SUITE_SMALLBUSINESS  1
#define VER_SUITE_ENTERPRISE     2
#define VER_SUITE_TERMINAL       16
#define VER_SUITE_DATACENTER     128
#define VER_SUITE_SINGLEUSERTS   256
#define VER_SUITE_PERSONAL       512
#define VER_SUITE_BLADE          1024

#EndIf

////////////////////////////////////////////////////////////////////////////////
// Find system fonts then write them to a tmp ascii file..
Global sub GetSysFonts(INT hdc)
{
//Call Api, Font is retrieve from the callback
EnumFontFamilies(hdc,null,&GetSysFontsCallback,0);

return true;
}

//everytime a font is found these callback occur.
Global sub GetSysFontsCallback(LOGFONT lpNLF,NEWTEXTMETRIC lpNTM, INT FontType, INT LParam),INT
{

    STRING fontname;

// get fontname into a string

lstrcpyn(fontname,lpNLF.lfFaceName,32);
fontname = rtrim$(fontname);

////////write what you do with the fontname here

//return true type fonts only
If (FontType = TRUETYPE_FONTTYPE)
{
              //Do something with the fontname here
}

// return true to continue
return true;
}

////////////////////////////////////////////////////////////////////////////////
// return the current user name 
Global Sub GetSysUsername(),STRING
{
    DSTRING name[250];
    INT buffer;

    buffer = 251;
    GetUserNameA(name, buffer);
return name;
}

////////////////////////////////////////////////////////////////////////////////
// return current window version name
Global sub GetWinOSName(),STRING
{
    OSVERSIONINFO OsV;
    OSVERSIONINFOEX OsVnfo;

    STRING Os_vs;

    OsV.dwOSVersionInfoSize = Len(OsV);
    GetVersionExA(OsV);

    SELECT OsV.dwPlatformId
    {

        CASE VER_PLATFORM_WIN32s:

            Os_vs  = "Win32s";

    CASE VER_PLATFORM_WIN32_WINDOWS:

    if (OsV.dwMajorVersion = 4) & (OsV.dwMinorVersion = 0)
    {
              Os_vs = "Windows 95";
    }

            if (OsV.dwMajorVersion = 4) & (OsV.dwMinorVersion = 10)
        {
                Os_vs = "Windows 98 ";

                if (OSV.szCSDVersion = "A") | (OSV.szCSDVersion = "B")
        {
        Os_vs = "Windows 98 Second Edition";
        }
        }

            if (OsV.dwMajorVersion = 4) & (OsV.dwMinorVersion = 90)
        {
        Os_vs = "Windows Millennium Edition";
            }


        CASE VER_PLATFORM_WIN32_NT:
               
            if OsV.dwMajorVersion = 3
    {
        Os_vs = "Windows NT 3.51";
    }

            if OsV.dwMajorVersion = 4
    {
        Os_vs = "Windows NT 4.0";
    }

            if OsV.dwMajorVersion = 5
    {
    select OsV.dwMinorVersion
    {
        case 0:
    Os_vs = "Windows 2000";
    case 1:
        Os_vs = "Windows XP";
    case 2:
        Os_vs = "Windows 2003 Server";
    }
    }

            if OsV.dwMajorVersion = 6 & OsVnfo.dwMinorVersion = 0
    {
    Os_vs = "Windows Vista";
    }
    }
return Os_vs;
}

////////////////////////////////////////////////////////////////////////////////
// return current windows version type
Global sub GetWinOSProductTypeNT(),STRING
{
    OSVERSIONINFOEX OsVnfo;

    STRING Os_Type;

    OsVnfo.dwOSVersionInfoSize = Len(OsVnfo);
    GetVersionExA(OsVnfo);

select OsVnfo.dwMajorVersion
{
case 4:
    select OsVnfo.wProductType
{
// Windows NT 4.0 Workstation
case VER_NT_WORKSTATION:
    Os_Type = "Workstation";
// Windows NT 4.0 Server
case VER_NT_SERVER:
    Os_Type = "Server";
}

case 5:
    select OsVnfo.wProductType
{
case VER_NT_WORKSTATION:
    if OsVnfo.wSuiteMask = VER_SUITE_PERSONAL
{
// Windows XP Home Edition
Os_Type = "Home Edition";
}
else
{
// Windows XP / Windows 2000 Professional
                        Os_Type = "Professional";
}

case VER_NT_SERVER:
    select OsVnfo.dwMinorVersion
        {
            case 0: // Windows 2000
    if OsVnfo.wSuiteMask = VER_SUITE_DATACENTER
        {
        // Windows 2000 Datacenter Server
        Os_Type = "Datacenter Server";
        }
else if OsVnfo.wSuiteMask = VER_SUITE_ENTERPRISE
{
/// Windows 2000 Advanced Server
        Os_Type = "Advanced Server";
}
else
{
/// Windows 2000 Server
        Os_Type = "Server";
}

        case 2: // Windows Server 2003
    if OsVnfo.wSuiteMask = VER_SUITE_DATACENTER
        {
        // Windows Server 2003 Datacenter Edition
        Os_Type = "Datacenter Server";
        }
else if OsVnfo.wSuiteMask = VER_SUITE_ENTERPRISE
{
// Windows Server 2003 Enterprise Edition
        Os_Type = "Enterprise Edition";
}
else if OsVnfo.wSuiteMask = VER_SUITE_BLADE
{
// Windows Server 2003 Web Edition
        Os_Type = "Web Edition";
}
else
{
// Windows Server 2003 Standard Edition
        Os_Type = "Standard Edition";
}
        }
}
}
return Os_Type;
}

////////////////////////////////////////////////////////////////////////////////
// return the current Service Pack into a string
global Sub GetWinOSServicePack(),STRING
{
OSVERSIONINFOEX OsVnfo;

    OsVnfo.dwOSVersionInfoSize = Len(OsVnfo);
    GetVersionExA(OsVnfo);

if len(OsVnfo.szCSDVersion) <> 0
{
return OsVnfo.szCSDVersion;
}
else
{
return "";
}
}


I'll add more when the need will come ;)

J B Wood (Zumwalt)