open text file using shell - Page 2


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: open text file using shell

  1. #16
    Hian Chew Guest

    Re: open text file using shell


    Bob,
    Regarding the API PathCompactPath, if I want to get a short path
    using this API and use it on an MDI form's menu item(caption),
    what device-context handle (hdc) do I use?
    MDI form or the menu does not has hdc.

    Hian Chew

    "Bob Butler" <butlerbob@earthlink.net> wrote:
    >
    >"Bob Butler" <butlerbob@earthlink.net> wrote in message
    >news:3aa55d8d@news.devx.com...
    >>
    >> "Ian Williams" <advice@kingsoft-dk.com> wrote in message
    >> news:3aa55cd4$1@news.devx.com...
    >> > What about GetShortPathName()

    >>
    >> GetShortPathName replaces long names withe 8.3 equivalent and that might

    >be
    >> a good first try...
    >>
    >> if the full long name doesn't fit call GetShortPathName and try that.

    If
    >> that doesn't fit use PathCompactPath and/or PathCompactPathEx to get the
    >> ellipsis version. If all else fails just show the first 'n' characters.

    >
    >I did a quick example using all 3 API calls....
    >
    >Option Explicit
    >Private Const MAX_PATH = 260
    >Private Declare Function PathCompactPath Lib "Shlwapi.dll" _
    > Alias "PathCompactPathA" (ByVal hDC As Long, _
    > ByVal lpszPath As String, ByVal dx As Long) As Long
    >
    >Private Declare Function PathCompactPathEx Lib "Shlwapi.dll" _
    > Alias "PathCompactPathExA" (ByVal pszOut As String, _
    > ByVal pszSrc As String, ByVal cchMax As Long, _
    > Optional ByVal dwFlags As Long = 0) As Long
    >
    >Private Declare Function GetShortPathName Lib "kernel32" _
    > Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
    > ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    >
    >Public Function FitPathToLabel(ByVal FilePath As String, _
    > ByVal LabelControl As Label) As String
    >Dim oForm As Form
    >Dim lLabelWidth As Long ' width in pixels
    >Dim bOK As Boolean
    >Dim lResult As Long
    >Dim lMax As Long
    >Dim sOut As String
    >Set oForm = LabelControl.Parent ' need the form for the hDC and TextWidth
    >lLabelWidth = oForm.ScaleX(LabelControl.Width, oForm.ScaleMode, vbPixels)
    >If oForm.TextWidth(FilePath) < lLabelWidth Then
    > FitPathToLabel = FilePath ' it fits as-is
    >Else
    > sOut = String$(MAX_PATH + 1, vbNullChar) ' init buffer
    > lResult = GetShortPathName(FilePath, sOut, Len(sOut))
    > If lResult > 0 And Left$(sOut, 1) <> vbNullChar Then
    > sOut = Left$(sOut, lResult) ' see if 8.3 format will fit
    > lResult = oForm.ScaleX(oForm.TextWidth(sOut), oForm.ScaleMode, vbPixels)
    >
    > If lResult < lLabelWidth Then
    > FitPathToLabel = sOut
    > bOK = True ' got it
    > End If
    > End If
    > If Not bOK Then ' still no good - try compacting the path
    > sOut = FilePath & String$(MAX_PATH + 1, vbNullChar)
    > bOK = CBool(PathCompactPath(oForm.hDC, sOut, lLabelWidth))
    > If bOK Then
    > lResult = InStr(1, sOut, vbNullChar) ' trim nulls
    > If lResult > 0 Then sOut = Left$(sOut, lResult - 1)
    > FitPathToLabel = sOut ' compacting worked!
    > End If
    > End If
    > If Not bOK Then ' still a problem -- try compacting another way
    > lMax = Len(FilePath) - 1
    > Do Until lMax < 1 Or bOK = True
    > sOut = String$(MAX_PATH + 1, vbNullChar) ' init buffer
    > If CBool(PathCompactPathEx(sOut, FilePath, lMax)) Then
    > lResult = InStr(1, sOut, vbNullChar) ' trim nulls
    > If lResult > 0 Then sOut = Left$(sOut, lResult - 1)
    > lResult = oForm.ScaleX(oForm.TextWidth(sOut), oForm.ScaleMode,
    >vbPixels)
    > If lResult < lLabelWidth Then
    > bOK = True
    > FitPathToLabel = sOut
    > End If
    > End If
    > lMax = lMax - 1
    > Loop
    > End If
    > If Not bOK Then FitPathToLabel = "..." ' nothing fits!
    >End If
    >Set oForm = Nothing
    >End Function
    >
    >
    >



  2. #17
    Hian Chew Guest

    Re: open text file using shell


    Bob,
    Regarding the API PathCompactPath, if I want to get a short path
    using this API and use it on an MDI form's menu item(caption),
    what device-context handle (hdc) do I use?
    MDI form or the menu does not has hdc.

    Hian Chew

    "Bob Butler" <butlerbob@earthlink.net> wrote:
    >
    >"Bob Butler" <butlerbob@earthlink.net> wrote in message
    >news:3aa55d8d@news.devx.com...
    >>
    >> "Ian Williams" <advice@kingsoft-dk.com> wrote in message
    >> news:3aa55cd4$1@news.devx.com...
    >> > What about GetShortPathName()

    >>
    >> GetShortPathName replaces long names withe 8.3 equivalent and that might

    >be
    >> a good first try...
    >>
    >> if the full long name doesn't fit call GetShortPathName and try that.

    If
    >> that doesn't fit use PathCompactPath and/or PathCompactPathEx to get the
    >> ellipsis version. If all else fails just show the first 'n' characters.

    >
    >I did a quick example using all 3 API calls....
    >
    >Option Explicit
    >Private Const MAX_PATH = 260
    >Private Declare Function PathCompactPath Lib "Shlwapi.dll" _
    > Alias "PathCompactPathA" (ByVal hDC As Long, _
    > ByVal lpszPath As String, ByVal dx As Long) As Long
    >
    >Private Declare Function PathCompactPathEx Lib "Shlwapi.dll" _
    > Alias "PathCompactPathExA" (ByVal pszOut As String, _
    > ByVal pszSrc As String, ByVal cchMax As Long, _
    > Optional ByVal dwFlags As Long = 0) As Long
    >
    >Private Declare Function GetShortPathName Lib "kernel32" _
    > Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
    > ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    >
    >Public Function FitPathToLabel(ByVal FilePath As String, _
    > ByVal LabelControl As Label) As String
    >Dim oForm As Form
    >Dim lLabelWidth As Long ' width in pixels
    >Dim bOK As Boolean
    >Dim lResult As Long
    >Dim lMax As Long
    >Dim sOut As String
    >Set oForm = LabelControl.Parent ' need the form for the hDC and TextWidth
    >lLabelWidth = oForm.ScaleX(LabelControl.Width, oForm.ScaleMode, vbPixels)
    >If oForm.TextWidth(FilePath) < lLabelWidth Then
    > FitPathToLabel = FilePath ' it fits as-is
    >Else
    > sOut = String$(MAX_PATH + 1, vbNullChar) ' init buffer
    > lResult = GetShortPathName(FilePath, sOut, Len(sOut))
    > If lResult > 0 And Left$(sOut, 1) <> vbNullChar Then
    > sOut = Left$(sOut, lResult) ' see if 8.3 format will fit
    > lResult = oForm.ScaleX(oForm.TextWidth(sOut), oForm.ScaleMode, vbPixels)
    >
    > If lResult < lLabelWidth Then
    > FitPathToLabel = sOut
    > bOK = True ' got it
    > End If
    > End If
    > If Not bOK Then ' still no good - try compacting the path
    > sOut = FilePath & String$(MAX_PATH + 1, vbNullChar)
    > bOK = CBool(PathCompactPath(oForm.hDC, sOut, lLabelWidth))
    > If bOK Then
    > lResult = InStr(1, sOut, vbNullChar) ' trim nulls
    > If lResult > 0 Then sOut = Left$(sOut, lResult - 1)
    > FitPathToLabel = sOut ' compacting worked!
    > End If
    > End If
    > If Not bOK Then ' still a problem -- try compacting another way
    > lMax = Len(FilePath) - 1
    > Do Until lMax < 1 Or bOK = True
    > sOut = String$(MAX_PATH + 1, vbNullChar) ' init buffer
    > If CBool(PathCompactPathEx(sOut, FilePath, lMax)) Then
    > lResult = InStr(1, sOut, vbNullChar) ' trim nulls
    > If lResult > 0 Then sOut = Left$(sOut, lResult - 1)
    > lResult = oForm.ScaleX(oForm.TextWidth(sOut), oForm.ScaleMode,
    >vbPixels)
    > If lResult < lLabelWidth Then
    > bOK = True
    > FitPathToLabel = sOut
    > End If
    > End If
    > lMax = lMax - 1
    > Loop
    > End If
    > If Not bOK Then FitPathToLabel = "..." ' nothing fits!
    >End If
    >Set oForm = Nothing
    >End Function
    >
    >
    >



  3. #18
    Bob Butler Guest

    Re: open text file using shell


    "Hian Chew" <hschew00@yahoo.com> wrote in message
    news:3aa6664f$1@news.devx.com...
    >
    > Bob,
    > Regarding the API PathCompactPath, if I want to get a short path
    > using this API and use it on an MDI form's menu item(caption),
    > what device-context handle (hdc) do I use?
    > MDI form or the menu does not has hdc.


    The hDC is used to get font metrics so you can probably use a child form or
    any other hdc (e.g. a hidden picturebox on the MDI or some other such hack).



  4. #19
    Bob Butler Guest

    Re: open text file using shell


    "Hian Chew" <hschew00@yahoo.com> wrote in message
    news:3aa6664f$1@news.devx.com...
    >
    > Bob,
    > Regarding the API PathCompactPath, if I want to get a short path
    > using this API and use it on an MDI form's menu item(caption),
    > what device-context handle (hdc) do I use?
    > MDI form or the menu does not has hdc.


    The hDC is used to get font metrics so you can probably use a child form or
    any other hdc (e.g. a hidden picturebox on the MDI or some other such hack).



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center