We may have encountered such problems when we program: in a Label or Panel display path, when the path is too long, I hope to shorten the path like some installer copy files, some of which are replaced by omnasion , Such as: c: / program files / borland / delphi5 / source / RTL / WIN -> C: / Program files / borland /.../ WIN own programming implementation is not difficult, but I don't know why, I have not hands Done, I suddenly a day, I saw an article, so everything is solved, and it is an unexpected harvest. It is a Visual Basic program. However, I saw a function in the first place. Declaration: PathcompactPath:
Private declare function pathcompactpath _lib "shlwapi" Alias "pathcompactpatha" (Byval Lpszpath as string, _ byval dx as long) As long it requires three quotes, as follows: HDC: Device Context handle. LPSZPATH: The Address of the Pathname. Dx: The Width in Pixels of The Spot in Which You Want The Pathname To Fit. After several modifications, the trial in Delphi passed, and it was able to do the effect of the compressed path, but I am more interested in that there is still a lot of good stuff that can be used in shlwapi.dll? Open MSDN, knock in "shlwapi" search, and there is a bunch of "attention," a bunch ") is a function started with" path ", and is pleased. So I will see its function one by one, find that there is a corresponding function of almost all functions we need to call, such as PathaddBackslash, PathremoveBackslash: Adding or removing "/" behind the path; PathisDirectory, PathishTmlfile, Pathisprefix, Pathisroot, Pathisull ..., etc., just try a few, you can use, then I think how to find all the function declarations, I know that many dynamic link libraries have corresponding headers on the MSDN, this may not Will be exception. Sure enough, I am guess! SHLWAPI.H did exist. The next job is more annoying, spend some time, with "find, replace" Dafa as auxiliary, I have made the function declaration of the path operations into shlwapi.pas (SHLWAPI.h included a number of functions declarations) : String, path, registry, registry stream, palette, and a very useful function DllgetVIRSION, a complete statement can be downloaded here). Let's talk about Pathcomact, the PathCompactPath function requires the device's HDC to do parameters. It may be troublesome to use, so there is another function PathCompactPathex, parameter and devices are not related to the character and display width. Some places. I need to scrumblish, I made a simple Ellipsispanel control, which can be used as an example. The same function, you can also use the DrawText function, the parameter description is found in the Windows SDK Help of MSDN or Delphi, the function is stronger than the PathCompactPath, when the call is invoked, the path is omitted or omitted in the path tail (similar to The handling of the resource manager cannot display the full path name.) DFS DFSELLIPSISPANEL is doing it.