|This is a great API call which you can use to shorten a
long path and file name which needs to be displayed in a small field
within your application. It makes an attempt to shorten the path to fit
the size but still provide enough of the original path to be meaningful
to the user. To get this API working you will need to define the
following API Calls as external functions:
Function long GetDC( long hWnd ) Library "user32"
function long PathCompactPathA( long lhDC, &
ref string as_Text, long al_Len ) library 'shlwapi'
Function long ReleaseDC( long hWnd, uint hDC ) Library "user32"
The Get/Release DC are just used to get a handle to the device context but
the middle API call is the one that performs the real magic, it takes a handle
to the device context (in our case the current window) and the text to be
shorten by reference followed by the number of pixels to fit the text into.
The following example script is in a command button on a window and should
be easy to follow:
String ls_Text = "c:\Program Files\PBDR\PBDelta\PBDelta3.exe"
Long ll_Pixels = 150
ll_HDC = GetDC( Handle( parent ) )
PathCompactPathA( ll_HDC, ls_Text, ll_Pixels )
ReleaseDC( Handle( parent ), ll_HDC )
MessageBox( 'text', ls_Text )