Using Win32 functions in Visual FoxPro Image Gallery
Shell Functions
..msdn
AssocQueryString
DllGetVersion
DragAcceptFiles
DragFinish
DragQueryFile
DragQueryPoint
FileIconInit
FindExecutable
GetFileNameFromBrowse
GetMenuContextHelpId
GetWindowContextHelpId
InetIsOffline
IsUserAnAdmin
LoadUserProfile
PathMakeUniqueName
PathYetAnotherMakeUniqueName
RealDriveType
RestartDialog
SHAddToRecentDocs
SHBrowseForFolder
SHCreateDirectory
ShellAbout
ShellExecute
ShellExecuteEx
Shell_GetImageLists
Shell_NotifyIcon
SHEmptyRecycleBin
SHFileOperation
SHFormatDrive
SHGetFileInfo
SHGetFolderPath
SHGetPathFromIDList
SHGetSpecialFolderLocation
SHGetStockIconInfo
SHParseDisplayName
SHQueryRecycleBin
SHSimpleIDListFromPath
UnloadUserProfile
WinHelp
Code examples:
Creating a unique filename based on existing filename
Creating a unique filename based on existing filename

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
#DEFINE CP_ACP         0
#DEFINE CP_OEMCP       1
#DEFINE MB_PRECOMPOSED 1
#DEFINE MAX_PATH       260
DO decl

LOCAL cPath, cFile, cUnique, cTpl

* retrieving FoxPro executable name
cPath = Repli(Chr(0),MAX_PATH)
= GetModuleFileName(0, @cPath, Len(cPath))
cPath = SUBSTR(cPath, 1, AT(Chr(0),cPath)-1)
cFile = SUBSTR(cPath, RAT("\",cPath)+1)
? "Base name:", cPath

cUnique = Repli(Chr(0),MAX_PATH*2)
= PathYetAnotherMakeUniqueName(@cUnique, a2u(cPath), Null, a2u(cFile))
cUnique = u2a(cUnique)
? "Unique filename:", cUnique
?

cUnique = Repli(Chr(0),MAX_PATH*2)
cTpl = "MyFile.Dat"
cPath = GetLongTempPath()
? "Base name:", cPath + cTpl

= PathMakeUniqueName(@cUnique, MAX_PATH, a2u(cTpl), a2u(cTpl), a2u(cPath))
cUnique = u2a(cUnique)
? "Unique filename:", cUnique
* end of main

FUNCTION GetLongTempPath
    LOCAL cPath, cLongPath, nBufsize
    cPath = Repli(Chr(0),MAX_PATH)
    cLongPath = Repli(Chr(0),MAX_PATH*2)
    nBufsize = GetTempPath(Len(cPath), @cPath)
    cPath = LEFT(cPath, nBufsize)
    = GetLongPathName(cPath, @cLongPath, Len(cLongPath))
RETURN SUBSTR(cLongPath, 1,AT(Chr(0),cLongPath)-1)

FUNCTION u2a(cText)
* converting a Unicode string to an ANSI string
    LOCAL lcBuffer, lnBufsize
    cText = SUBSTR(cText, 1, AT(Chr(0)+Chr(0),cText))

    * first calling to define required buffer size
    lcBuffer = ""
    lnBufsize = WideCharToMultiByte(CP_ACP, 0,;
        cText, Len(cText), @lcBuffer, 0, Chr(0), 0)

    lcBuffer = Repli(Chr(0), lnBufsize)
    = WideCharToMultiByte(CP_ACP, 0,;
        cText, Len(cText), @lcBuffer, lnBufsize, Chr(0), 0)
RETURN SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)

FUNCTION a2u(cText)
* converting an ANSI string to a Unicode string
    LOCAL lcBuffer, lnBufsize

    * first calling to define required buffer size
    lcBuffer = ""
    lnBufsize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,;
        cText, Len(cText), @lcBuffer, 0)

    lcBuffer = Repli(Chr(0), lnBufsize*2)  && in wide chars
    = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,;
        cText, Len(cText), @lcBuffer, lnBufsize)
RETURN lcBuffer

PROCEDURE decl
    DECLARE INTEGER PathMakeUniqueName IN shell32;
        STRING @pszUniqueName, INTEGER cchMax, STRING pszTemplate,;
        STRING pszLongPlate, STRING pszDir

    DECLARE INTEGER PathYetAnotherMakeUniqueName IN shell32;
        STRING @pszUniqueName, STRING pszPath,;
        STRING pszShort, STRING pszFileSpec

    DECLARE INTEGER GetTempPath IN kernel32;
        INTEGER nBufferLength, STRING @lpBuffer

    DECLARE INTEGER GetLongPathName IN kernel32;
        STRING lpszShortPath, STRING @lpszLongPath,;
        INTEGER cchBuffer

    DECLARE INTEGER GetModuleFileName IN kernel32; 
        INTEGER hModule, STRING @lpFilename, INTEGER nSize

    DECLARE INTEGER WideCharToMultiByte IN kernel32;
        INTEGER CodePg, INTEGER dwFlags,;
        STRING lpWideCharStr, INTEGER cchWideChar,;
        STRING @lpMultiByteStr, INTEGER cbMultiByte,;
        STRING lpDefaultChar, INTEGER lpUsedDefaultChar

    DECLARE INTEGER MultiByteToWideChar IN kernel32;
        INTEGER CodePage, LONG dwFlags, STRING lpMultiByteStr,;
        INTEGER cbMultiByte, STRING @lpWCharStr, INTEGER cchWChar



User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3092 bytes  
Created: 2001-07-12 12:00:00  
Modified: 2005-12-12 11:26:21  
Visits in 7 days: 78  
Listed functions:
GetLongPathName
GetModuleFileName
GetTempPath
MultiByteToWideChar
PathMakeUniqueName
PathYetAnotherMakeUniqueName
WideCharToMultiByte
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-2018 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.6.39), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (50.19.34.255)
12 sec.
Function group: 'Cursor'
23 sec.Function: 'CeRegQueryInfoKey'
Function group: 'Remote Application Programming (RAPI)'
45 sec.Function: 'PrinterProperties'
Function group: 'Printing and Print Spooler'
56 sec.Function: 'FreeLibrary'
1.07 min.Example: 'GDI+: Implementing image scrolling with inertia'
1.3 min.Function: 'CeGetTempPath'
Function group: 'Remote Application Programming (RAPI)'
1.47 min.Example: 'Storing registration key in the resources of an executable file'
1.63 min.Function: 'WSAConnect'
Function group: 'Windows Sockets 2 (Winsock)'
1.85 min.Function: 'WSACleanup'
Function group: 'Windows Sockets 2 (Winsock)'
2.02 min.Function: 'GdipCreateBitmapFromHICON'
Function group: 'GDI+ Bitmap'
Google
Advertise here!