🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9861

Re: Compressing a long path

#9861
From: Andrue Cope [TeamB]
Date: Fri, 11 Jun 2004 16:00
39 lines
1906 bytes
JD wrote:

> 
> Is there an API which will compress a long path to something
> like:
> 
>     "C:\Program Files\...\LastFolderName"

Yes.

This is VCL code but I'm sure you can 'port' it :)

AnsiString General_FitPathToWidth( AnsiString PathToFit,
                                   TLabel *   Label )
{
  AnsiString result=PathToFit;
  char *tmp=new char[ 2*PathToFit.Length() ];
  strcpy( tmp, PathToFit.c_str() );

  // To use this function you must add $BCB$\lib\psdk\shlwapi.lib to 
  //   your project  
  PathCompactPathA( Label->Canvas->Handle,
                    tmp,
                    Label->ClientWidth );

  result=tmp;                                          

  delete tmp;

  return result;
}

Note that this does not attempt to find a mid-point or maximum the path
to the right of '..\'. It just chops the directory and re-appends the
name. OTOH this is what Explorer does so is probably good enough.
-- 
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <40c9d70b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40c9aa76$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,69f761a2b482ea47
X-Google-Attributes: gid10cc67,public
From: "Andrue Cope [TeamB]" <no.spam@spammy.com>
Subject: Re: Compressing a long path
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40c9aa76$1@newsgroups.borland.com>
User-Agent: XanaNews/1.16.3.1
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
NNTP-Posting-Host: 217.207.223.34
Message-ID: <40c9d70b@newsgroups.borland.com>
Date: 11 Jun 2004 09:00:11 -0700
X-Trace: newsgroups.borland.com 1086969611 217.207.223.34 (11 Jun 2004 09:00:11 -0700)
Lines: 39
X-Authenticated-User: acope
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail