-
open text file using shell
Hi,
I will like to open a text file using notepad or wordpad or
whatever text editor that the target machine has using shell
command.
Is there a way to determine what text editor application that
the target machine has?
Also, how can I open a text file using that editor in read-only
mode without changing the attribute of that text file?
Hian Chew
-
Re: open text file using shell
"Hian Chew" <hschew00@yahoo.com> wrote in message
news:3aa51e39$1@news.devx.com...
>
> Hi,
> I will like to open a text file using notepad or wordpad or
> whatever text editor that the target machine has using shell
> command.
> Is there a way to determine what text editor application that
> the target machine has?
For that I'd use the ShellExecute API call
> Also, how can I open a text file using that editor in read-only
> mode without changing the attribute of that text file?
That would depend on the editor. Not all will support a way to do it and
certainly not consistently.
Given your requirements why not present your own form with a textbox or
richtextbox and the text loaded into that? You can then control it being
read only and not have to worry about what is or is not on the user's
system.
-
Re: open text file using shell
"Hian Chew" <hschew00@yahoo.com> wrote in message
news:3aa51e39$1@news.devx.com...
>
> Hi,
> I will like to open a text file using notepad or wordpad or
> whatever text editor that the target machine has using shell
> command.
> Is there a way to determine what text editor application that
> the target machine has?
For that I'd use the ShellExecute API call
> Also, how can I open a text file using that editor in read-only
> mode without changing the attribute of that text file?
That would depend on the editor. Not all will support a way to do it and
certainly not consistently.
Given your requirements why not present your own form with a textbox or
richtextbox and the text loaded into that? You can then control it being
read only and not have to worry about what is or is not on the user's
system.
-
Re: open text file using shell
Thanks Bob,
I will do that using textbox.
Another questions:
Is there an API to convert a long filename into a short filename so that
I can display it as item in File Menu or on the form's caption?
Something like
C:\ABC\...\XYZ\filename
"Bob Butler" <butlerbob@earthlink.net> wrote:
>
>"Hian Chew" <hschew00@yahoo.com> wrote in message
>news:3aa51e39$1@news.devx.com...
>>
>> Hi,
>> I will like to open a text file using notepad or wordpad or
>> whatever text editor that the target machine has using shell
>> command.
>> Is there a way to determine what text editor application that
>> the target machine has?
>
>For that I'd use the ShellExecute API call
>
>> Also, how can I open a text file using that editor in read-only
>> mode without changing the attribute of that text file?
>
>That would depend on the editor. Not all will support a way to do it and
>certainly not consistently.
>
>Given your requirements why not present your own form with a textbox or
>richtextbox and the text loaded into that? You can then control it being
>read only and not have to worry about what is or is not on the user's
>system.
>
>
>
-
Re: open text file using shell
Thanks Bob,
I will do that using textbox.
Another questions:
Is there an API to convert a long filename into a short filename so that
I can display it as item in File Menu or on the form's caption?
Something like
C:\ABC\...\XYZ\filename
"Bob Butler" <butlerbob@earthlink.net> wrote:
>
>"Hian Chew" <hschew00@yahoo.com> wrote in message
>news:3aa51e39$1@news.devx.com...
>>
>> Hi,
>> I will like to open a text file using notepad or wordpad or
>> whatever text editor that the target machine has using shell
>> command.
>> Is there a way to determine what text editor application that
>> the target machine has?
>
>For that I'd use the ShellExecute API call
>
>> Also, how can I open a text file using that editor in read-only
>> mode without changing the attribute of that text file?
>
>That would depend on the editor. Not all will support a way to do it and
>certainly not consistently.
>
>Given your requirements why not present your own form with a textbox or
>richtextbox and the text loaded into that? You can then control it being
>read only and not have to worry about what is or is not on the user's
>system.
>
>
>
-
Re: open text file using shell
"Hian Chew" <hschew00@yahoo.com> wrote in message
news:3aa553d7$1@news.devx.com...
>
> Thanks Bob,
> I will do that using textbox.
> Another questions:
>
> Is there an API to convert a long filename into a short filename so that
>
> I can display it as item in File Menu or on the form's caption?
>
> Something like
> C:\ABC\...\XYZ\filename
PathCompactPath or PathCompactPathEx will do this (it needs IE 4.0 or
higher)
http://msdn.microsoft.com/library/de...k/shellcc/shel
l/shlwapi/path/pathcompactpath.htm
I don't have a VB example handy
-
Re: open text file using shell
"Hian Chew" <hschew00@yahoo.com> wrote in message
news:3aa553d7$1@news.devx.com...
>
> Thanks Bob,
> I will do that using textbox.
> Another questions:
>
> Is there an API to convert a long filename into a short filename so that
>
> I can display it as item in File Menu or on the form's caption?
>
> Something like
> C:\ABC\...\XYZ\filename
PathCompactPath or PathCompactPathEx will do this (it needs IE 4.0 or
higher)
http://msdn.microsoft.com/library/de...k/shellcc/shel
l/shlwapi/path/pathcompactpath.htm
I don't have a VB example handy
-
Re: open text file using shell
What about GetShortPathName()
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aa55b6f@news.devx.com...
>
> "Hian Chew" <hschew00@yahoo.com> wrote in message
> news:3aa553d7$1@news.devx.com...
> >
> > Thanks Bob,
> > I will do that using textbox.
> > Another questions:
> >
> > Is there an API to convert a long filename into a short filename so that
> >
> > I can display it as item in File Menu or on the form's caption?
> >
> > Something like
> > C:\ABC\...\XYZ\filename
>
> PathCompactPath or PathCompactPathEx will do this (it needs IE 4.0 or
> higher)
>
>
http://msdn.microsoft.com/library/de...k/shellcc/shel
> l/shlwapi/path/pathcompactpath.htm
>
> I don't have a VB example handy
>
>
-
Re: open text file using shell
What about GetShortPathName()
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aa55b6f@news.devx.com...
>
> "Hian Chew" <hschew00@yahoo.com> wrote in message
> news:3aa553d7$1@news.devx.com...
> >
> > Thanks Bob,
> > I will do that using textbox.
> > Another questions:
> >
> > Is there an API to convert a long filename into a short filename so that
> >
> > I can display it as item in File Menu or on the form's caption?
> >
> > Something like
> > C:\ABC\...\XYZ\filename
>
> PathCompactPath or PathCompactPathEx will do this (it needs IE 4.0 or
> higher)
>
>
http://msdn.microsoft.com/library/de...k/shellcc/shel
> l/shlwapi/path/pathcompactpath.htm
>
> I don't have a VB example handy
>
>
-
Re: open text file using shell
"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.
-
Re: open text file using shell
"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.
-
Re: open text file using shell
"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
-
Re: open text file using shell
"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
-
Re: open text file using shell
Hm, misread the question, so here's a non-api method
Function CompactPath(strPath As String, _
ByVal NumCompacts As Integer, _
Optional ShowMiddleDirs As Boolean = True, _
Optional NumDots As Integer = 2) As String
Dim strParts() As String
Dim i As Long
strParts = Split(strPath, "\")
If NumCompacts > UBound(strParts) - 1 Then
NumCompacts = UBound(strParts) - 1
ElseIf NumCompacts = 1 Then
ShowMiddleDirs = True
End If
For i = UBound(strParts) - 1 To LBound(strParts) Step -1
If ShowMiddleDirs Then
strParts(i) = String(NumDots, ".")
Else
strParts(i) = ""
End If
NumCompacts = NumCompacts - 1
If NumCompacts = 1 Then strParts(i) = String(NumDots, ".")
If NumCompacts = 0 Then Exit For
Next
CompactPath = Join(strParts(), "\")
If Not ShowMiddleDirs Then
Do While InStr(CompactPath, "\\") > 0
CompactPath = Replace(CompactPath, "\\", "\")
Loop
End If
End Function
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"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.
>
>
>
-
Re: open text file using shell
Hm, misread the question, so here's a non-api method
Function CompactPath(strPath As String, _
ByVal NumCompacts As Integer, _
Optional ShowMiddleDirs As Boolean = True, _
Optional NumDots As Integer = 2) As String
Dim strParts() As String
Dim i As Long
strParts = Split(strPath, "\")
If NumCompacts > UBound(strParts) - 1 Then
NumCompacts = UBound(strParts) - 1
ElseIf NumCompacts = 1 Then
ShowMiddleDirs = True
End If
For i = UBound(strParts) - 1 To LBound(strParts) Step -1
If ShowMiddleDirs Then
strParts(i) = String(NumDots, ".")
Else
strParts(i) = ""
End If
NumCompacts = NumCompacts - 1
If NumCompacts = 1 Then strParts(i) = String(NumDots, ".")
If NumCompacts = 0 Then Exit For
Next
CompactPath = Join(strParts(), "\")
If Not ShowMiddleDirs Then
Do While InStr(CompactPath, "\\") > 0
CompactPath = Replace(CompactPath, "\\", "\")
Loop
End If
End Function
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"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.
>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|