Results 1 to 3 of 3

Thread: Compact Path [Resolved]

  1. #1

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Compact Path [Resolved]

    I want to use the CompactPathEx API to compact a selected filepath
    to fit into my label control. No problem doing it, but how can I get
    the path to fit exactly into the label and not have to do a trial and
    error for the length parameter? If you select a different path after
    trial and error, the different widths of the letters will change the
    length. So it must be limited by the internal width of the label that
    can be visibly displayable.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function PathCompactPathEx Lib "shlwapi.dll" Alias "PathCompactPathExA" (ByVal pszOut As String, _
    4. ByVal pszSrc As String, ByVal cchMax As Long, ByVal dwFlags As Long) As Long
    5.  
    6. Private Sub Command1_Click()
    7.  
    8.     Dim sPath As String
    9.     Dim sSave As String
    10.    
    11.     sPath = ShowOpen(frmMain.hWnd, "Text Files Only (*.txt)" & vbNullChar & "*.txt" & vbNullChar, "Browse for file", _
    12.     OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST)
    13.     If Len(sPath) > 0 Then
    14.         sSave = String(255, 0)
    15.         PathCompactPathEx sSave, sPath, [b][color=red]55[/color][/b], 0
    16.         lblPath.Caption = sSave
    17.     End If
    18.  
    19. End Sub
    Thanks in advance for any help.
    Last edited by RobDog888; Sep 2nd, 2004 at 11:06 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    Ok, trying PathCompactPath API instead because it supports a
    parameter of pixels and not characters. So now I need to
    determine the innerwidth of my textbox or label.

    VB Code:
    1. Private Declare Function PathCompactPath Lib "shlwapi.dll" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal pszPath As String, _
    2. ByVal dx As Long) As Long
    3.  
    4. PathCompactPath Me.hDC, sPath, lblPath.Width 'lblPath.Width Not correct for pixel width
    Any ideas?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    I was looking way to close on this one! Just needed to convert
    the twips to pixels and subtract for border width to get the inner
    displayable width. Works perfectly now matter the resolution,
    font size, or font style.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function PathCompactPath Lib "shlwapi.dll" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal pszPath As String, _
    4. ByVal dx As Long) As Long
    5.  
    6. Dim sSave As String
    7.  
    8. Private Sub cmdBrowse_Click()
    9.    
    10.     Dim sPath As String 'Save complete path for use in I/O file operations later since cant use compacted path in textbox.
    11.    
    12.     sPath = ShowOpen(frmMain.hwnd, "Text Files Only (*.txt)" & vbNullChar & "*.txt" & vbNullChar, "Browse for file", _
    13.     OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST)
    14.     If Len(sPath) > 0 Then
    15.         sSave = String(255, 0)
    16.         sSave = Trim$(sPath)
    17.         PathCompactPath Me.hDC, sPath, ByVal ((txtPath.Width / Screen.TwipsPerPixelX) - 4) '2 pixels for border on each side = 4
    18.         txtPath = sPath
    19.     Else
    20.         txtPath = ""
    21.     End If
    22.    
    23. End Sub
    VB/Outlook Guru!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width