Launching Windows Explorer for Specified Drive, Folder or File

MSDN links:
Windows Explorer Command-Line Options
Run Method (Windows Script Host)
ShellExecute Function


* WSH Run Method

oShell = Createobject("")

* Open 'MyComputer' view with C: drive selected
oShell.Run("%SystemRoot%\explorer.exe /n, /select, c:")

Fit to Page in Excel and Word


WITH oSheet.PageSetup
* Fit to Page
.Zoom = .F.
.FitToPagesWide = 1
.FitToPagesTall = 1


* Word

File date and time

Code below shows how to retrieve file date and time using native VFP commands or WSH. For Windows API based solution that also allows to set file date and time, see George Tasker's Windows Time hosted on UT

MSDN links:

Excel - Finding the Last Row, Column or Cell


#DEFINE xlA1 1
#DEFINE xlR1C1 -4150
#DEFINE xlLastCell 11

* Last Row/Column
lnLastRow = oSheet.UsedRange.Rows.Count
lnLastCol = oSheet.UsedRange.Columns.Count

* Last Cell - Intersection of the last row and the last column
lcLastCell = oSheet.Cells.SpecialCells(xlLastCell).Address(,,xlR1C1)

Excel - Convert Column Number to Column Reference


#DEFINE xlA1 1
#DEFINE xlR1C1 -4150

lnCol = 123
* Using Excel
* oSheet - active sheet in a workbook
lcColRef = oSheet.Cells(1,lnCol).Address(.T.,.F.,xlA1)
*lcColLetter = LEFT(lcColRef, AT("$", lcColRef)-1)
lcColLetter = STREXTRACT(lcColRef, "", "$")

* VFP code only
lcColLetter = IIF(lnCol>26, CHR(Int((lnCol - 1) / 26) + 64), "") + CHR(((lnCol - 1) % 26) + 65)

Enumerating Windows on Taskbar


#define GW_HWNDFIRST 0
#define GW_HWNDLAST 1
#define GW_HWNDNEXT 2
#define GW_HWNDPREV 3
#define GW_OWNER 4
#define GW_CHILD 5

DECLARE Long GetWindow IN WIN32API Long hWnd, Long uCmd
DECLARE Long GetWindowText IN WIN32API Long hWnd, String @lpString, Long nMaxCount
DECLARE LONG GetWindowLong IN WIN32API Long hWnd, Long nIndex

Enumerating IE instances

The Windows Shell provides a powerful set of automation objects that enable you to access the file system, launch programs, and change system settings.

The Shell Windows Method creates and returns a ShellWindows object that represents a collection of all of the open windows that belong to the Shell, including Internet Explorer.


Enumerate Available Drives

The code below demonstrates the use of the DRIVETYPE() function.


Editable checkbox in a Grid with AllowCellSelection disabled

The GridHitTest method can be used to to determine where user clicked on the grid and update checkbox accordingly. Note that checkbox status can be changed by mouse only because there's no current cell when AllowCellSelection=.F.

Determine Printer Margins Programmatically

The GetDeviceCaps function can be used to retrieve printer-specific information as demonstrated below.


#DEFINE LOGPIXELSX    88    && Logical pixels/inch in X         
#DEFINE LOGPIXELSY    90    && Logical pixels/inch in Y         
#DEFINE PHYSICALWIDTH   110 && Physical Width in device units   
#DEFINE PHYSICALHEIGHT  111 && Physical Height in device units  
#DEFINE PHYSICALOFFSETX 112 && Physical Printable Area x margin 


Subscribe to RSS - code