Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Using custom Simple MapiSendMail class
Using Extended MessageBox() Class
Using FillMemory
Obtaining list of tables stored in an ODBC Data Source
Retrieving names for the registered clipboard formats
Simple Window Viewer
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
Displaying OS Memory Status
Extended OS Version info
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
Retrieving Window Class information for the VFP window
Enumerating print jobs and retrieving information for default printer (JOB_INFO_1 structures)
How to position the GETPRINTER() dialog
How to retrieve network parameters for the local computer (including Host name, Domain name, and DNS Server)
How to retrieve the number of print jobs queued for the printer
Simple printer queue monitor: deletes, pauses, resumes print jobs for local printer
Winsock: how to retrieve a service information corresponding to a port
Winsock: reading email messages (POP3, port 110)
Writing to INI file
Retrieving local computer and user names
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
How to ping a remote site using IP Helper API calls
Pocket PC: custom RAPI class for operating with files and folders on mobile device
Printf-style formatted text output in VFP
Finding out if the current user is the Guest account

User rating: 0/10 (0 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:
In the code sample below, the CurrentUser class wraps call to the NetUserGetInfo that populates USER_INFO_1 structure for the current user.

The usri1_priv member of this struture indicates if the user account is Guest or Admin.
 
LOCAL oUser As CurrentUser
oUser = CREATEOBJECT("CurrentUser")
WITH oUser
    ? .GetUserName()
    ? .IsUserAdmin()
    ? .IsUserGuest()
ENDWITH
* end of main
 
DEFINE CLASS CurrentUser As Session
#DEFINE USER_PRIV_GUEST 0
#DEFINE USER_PRIV_USER 1
#DEFINE USER_PRIV_ADMIN 2
 
    PROTECTED UserName, UserPrivLevel
    UserName=""
    UserPrivLevel=0
 
PROCEDURE Init
    THIS.declare
    THIS.GetUserInfo
 
FUNCTION IsUserAdmin() As Boolean
RETURN (BITAND(THIS.UserPrivLevel,;
    USER_PRIV_ADMIN) <> 0)
 
FUNCTION IsUserGuest() As Boolean
RETURN (BITAND(THIS.UserPrivLevel,;
    USER_PRIV_GUEST) <> 0)
 
FUNCTION GetUserName() As String
RETURN THIS.UserName
 
PROCEDURE GetUserInfo
    LOCAL nUserInfo, nBufSize, cUserInfo
    STORE 0 TO nUserInfo, nBufSize
 
    WITH THIS
        .UserName=.GetCurrentUserName()
 
        * USER_INFO_1
        = NetUserGetInfo(NULL, .ToUnicode(.UserName),;
            1, @nUserInfo)
 
        NetApiBufferSize(nUserInfo, @nBufSize)
 
        cUserInfo = REPLICATE(CHR(0), nBufSize)
        MemToStr(@cUserInfo, nUserInfo, nBufSize)
 
        * 13=offset to usri1_priv member; 4=DWORD
        .UserPrivLevel = .buf2dword(;
            SUBSTR(m.cUserInfo, 13, 4))
    ENDWITH
 
PROTECTED FUNCTION GetCurrentUserName() As String
* just an example; parsing SYS(0) would suffice
    LOCAL nBufSize, cUserName
    nBufSize=0
    = GetUserName(NULL, @nBufSize)
    cUserName = REPLICATE(CHR(0), nBufSize)
    = GetUserName(@cUserName, @nBufSize)
RETURN STRTRAN(cUserName, CHR(0), "")
 
PROTECTED PROCEDURE declare
 
    DECLARE INTEGER NetUserGetInfo IN netapi32;
        STRING servername, STRING username,;
        INTEGER lvl, INTEGER @bufptr
 
    DECLARE INTEGER GetUserName IN advapi32;
        STRING @lpBuffer, INTEGER @nSize
 
    DECLARE INTEGER NetApiBufferFree IN netapi32;
        INTEGER Buffer
 
    DECLARE INTEGER NetApiBufferSize IN netapi32;
        INTEGER Buffer, INTEGER @ByteCount
 
    DECLARE RtlMoveMemory IN kernel32 As MemToStr;
        STRING @dst, INTEGER src, INTEGER nLen
 
PROTECTED FUNCTION ToUnicode(cStr As String) As String
RETURN STRCONV(m.cStr, 5)
 
PROTECTED FUNCTION buf2dword(cBuffer)
RETURN Asc(SUBSTR(cBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(cBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(cBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(cBuffer, 4,1)), 24)
 
ENDDEFINE
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2235 bytes  
Created: 2010-07-06 09:03:19  
Modified: 2010-07-06 09:39:24  
Visits in 7 days: 88  
Listed functions:
GetUserName
NetApiBufferFree
NetApiBufferSize
NetUserGetInfo
Printer friendly API declarations
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 (67.202.9.192)
4 sec.Function: 'Escape'
1.03 hrs.Example: 'Drawing Windows frame controls using the DrawFrameControl function'
 Function: 'GetWindowDC'
Function group: 'Painting and Drawing'
1.89 hrs.Example: 'How to build UDP responder'
1.9 hrs.Function: 'sndPlaySound'
2.32 hrs.Example: 'Displaying icons in the system tray (VFP9)'
2.57 hrs.Example: 'Printing text with the Escape function'
 Function: 'GetDlgItem'
Function group: 'Dialog Box'
3.52 hrs.Example: 'Starting an external application in VFP using WinExec'
 
Function group: 'Brush'
Google
Advertise here!