Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to display Windows On-Screen Keyboard
How to print a bitmap file
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Winsock: sending email messages (SMTP, port 25)
System Image List Viewer
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Custom HttpRequest class (WinHTTP)
Printing Image File, programmatically set print page orientation to landscape
How to convert a bitmap file to monochrome format (1 bpp)
The window and its ancestors
Mapping and disconnecting network drives
How to download a file from the FTP server using FtpGetFile
Using EnumPrinters function to enumerate locally installed printers
Custom FTP Class for Visual FoxPro application
Displaying the associated icons and descriptions for files and folders
Displaying icons in the system tray (VFP9)
How to activate Windows Calculator
Drawing Windows predefined bitmaps using the LoadBitmap functions
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Sending email messages with Simple MAPI
Retrieving local computer and user names

User rating: 5/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
See also:
  • How to Start a Process as Another User (NT/XP/2K)
  • How to obtain network parameters for the local computer (host, domain, DNS)
  •  
    DO declare
     
    DO GetNames
    DO GetNameEx
    DO GetNameObj
    * end of main
     
    PROCEDURE GetNames
        LOCAL nSize, cBuffer
     
        nSize = 250
        cBuffer = Repli(Chr(0), nSize)
        IF GetComputerName (@cBuffer, @nSize) > 0
            cBuffer = STRTRAN(SUBSTR(cBuffer, 1, nSize), Chr(0),"")
            ? "Computer:", cBuffer
        ENDIF
     
        nSize = 250
        cBuffer = Repli(Chr(0), nSize)
        IF GetUserName (@cBuffer, @nSize) > 0
            cBuffer = STRTRAN(ALLTRIM(SUBSTR (cBuffer, 1, nSize)), Chr(0),"")
            ? "User:", cBuffer
            DO GetSid WITH cBuffer
        ENDIF
     
    PROCEDURE GetNameEx
        LOCAL cBuffer, nBufsize, nIndex
        FOR nIndex=0 TO 7
            nBufsize = 250
            cBuffer = Repli(Chr(0), nBufsize)
            IF GetComputerNameEx(nIndex, @cBuffer, @nBufsize) <> 0
                ? nIndex, LEFT(cBuffer, nBufsize)
            ENDIF
        ENDFOR
     
    PROCEDURE GetNameObj
        LOCAL cBuffer, nBufsize, nIndex
        nBufsize = 250
        cBuffer = Repli(Chr(0), nBufsize)
     
        IF GetComputerObjectName(12, @cBuffer, @nBufsize) = 0
        * 1351 = ERROR_CANT_ACCESS_DOMAIN_INFO
            ? "Error code:", GetLastError()
        ELSE
            ? nBufsize, "Object name: [" +;
                ALLTRIM(LEFT(cBuffer, nBufsize)) + "]"
        ENDIF
     
    PROCEDURE GetSID(cAccount)
        LOCAL hSid, nSidsize, cDomain, nDomainsize, peUse
     
        nSidsize=128
        hSid=LocalAlloc(0, nSidsize)
     
        nDomainsize=250
        cDomain=REPLICATE(CHR(0), nDomainsize)
     
        peUse=0
     
        * retrieve security identifier (SID) for the account name
        = LookupAccountName(NULL, m.cAccount,;
            hSid, @nSidSize, @cDomain, @nDomainSize, @peUse)
     
        * convert the SID to string format
        LOCAL nBuffer, nBufsize, cSid
        nBuffer=0
        = ConvertSidToStringSid(hSid, @nBuffer)
     
        nBufsize = LocalSize(nBuffer)
        cSid = REPLICATE(CHR(0), nBufsize)
        = MemToStr(@cSid, nBuffer, nBufsize)
     
        = LocalFree(nBuffer)
        = LocalFree(hSid)
     
        ? "Domain:", SUBSTR(cDomain, 1, AT(CHR(0),cDomain)-1)
        ? "SID:", cSid
     
    PROCEDURE declare
        DECLARE INTEGER GetLastError IN kernel32
        DECLARE INTEGER LocalFree IN kernel32 INTEGER hMem
        DECLARE LONG LocalSize IN kernel32 INTEGER hMem
     
        DECLARE INTEGER LocalAlloc IN kernel32;
            INTEGER uFlags, INTEGER uBytes
     
        DECLARE INTEGER GetComputerName IN kernel32;
            STRING @lpBuffer, INTEGER @nSize
     
        DECLARE INTEGER GetComputerNameEx IN kernel32;
            INTEGER NameType, STRING @lpBuffer, INTEGER @lpnSize
     
        DECLARE INTEGER GetUserName IN advapi32;
            STRING @lpBuffer, INTEGER @nSize
     
        DECLARE INTEGER GetComputerObjectName IN secur32;
            INTEGER NameFormat, STRING @lpNameBuffer, INTEGER @nSize
     
        DECLARE INTEGER LookupAccountName IN advapi32;
            STRING lpSystemName, STRING lpAccountName,;
            INTEGER Sid, INTEGER @cbSid,;
            STRING @RefDomainName, INTEGER @cchRefDomainName,;
            INTEGER @peUse
     
        DECLARE INTEGER ConvertSidToStringSid IN advapi32;
            INTEGER Sid, INTEGER @StringSid
     
        DECLARE RtlMoveMemory IN kernel32 As MemToStr;
            STRING @dst, INTEGER src, INTEGER nLength
     
     
     

    User rating: 5/10 (2 votes)
    Rate this code sample:
    • ~
    2838 bytes  
    Created: 2001-07-14 12:00:00  
    Modified: 2010-07-31 08:42:48  
    Visits in 7 days: 101  
    Listed functions:
    ConvertSidToStringSid
    GetComputerName
    GetComputerNameEx
    GetComputerObjectName
    GetLastError
    GetUserName
    LocalAlloc
    LocalFree
    LocalSize
    LookupAccountName
    Printer friendly API declarations
    My comment:
    SYS(0) returns current computer and user names.

    Same information can be retrieved with either GETENV() function with "COMPUTERNAME" and "USERNAME" parameters, or with the GetEnvironmentStrings function -- a sample code.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (50.16.132.180)
    6 sec.Example: 'Sending email messages with Simple MAPI'
    9 sec.Function: 'CreateWindow'
    58.45 min.Example: 'Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window'
    58.5 min.Example: 'Creating the Save dialog box to specify the drive, directory, and name of a file to save'
    58.58 min.Example: 'Class library providing access to the System Registry'
    Language: 'Visual Basic'
    1.2 hrs.Example: 'Terminating all running applications from a VFP program'
     Function: 'SetMenu'
    Function group: 'Menu'
     Example: 'Using LoadLibrary'
    1.86 hrs.Example: 'Displaying the color palette stored in an image file'
     Example: 'How to obtain Content-Type value for a file type from the System Registry'
    Google
    Advertise here!