Re: Common Dialog - Change file extension
- From: "Randy Birch" <rgb_removethis@xxxxxxxx>
- Date: Thu, 11 Aug 2005 01:07:32 -0400
As I mentioned before, VB's dialog (in fact no common dialog) provides this
functionality natively. In order to change the extension you have to :
- use the API common dialog
- set up a hook for the dialog
- watch for the WM_NOTIFY message
- when received, use Copymemory against lparam to copy the data into a
OFNOTIFY structure
- perform a select case on the notify.hdr.code member of the UDT
- look for the CDN_TYPECHANGE notification
- send a message to the control to extract the current text in the filename
textbox
- send a message to the control to get the index of the selected file type
- modify the retrieved filename to reflect the changed extension
- send the string back to the control's filename text box using SendMessage
Very roughly the code is like:
Public Function OFNHookProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim notify As OFNOTIFY
Dim ofnp2 As OPENFILENAMEPTR
Select Case uMsg
Case WM_NOTIFY
Call CopyMemory(notify, ByVal lParam, Len(notify))
Select Case notify.hdr.code
Case CDN_TYPECHANGE:
Debug.Print "CDN_TYPECHANGE"
'<do other things here>
OFNHookProc = 1
Case Else
End Select
Case Else:
End Select
End Function
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------
"Elmo Watson" <sputnik75043@xxxxxxxxxxxxxxxxx> wrote in message
news:%23mH52tbnFHA.2472@xxxxxxxxxxxxxxxxxxxxxxx
: Still, no one has addressed how to access the event of the 'Save as type'
: combobox in the common dialog.
: One more time - - -
: Let's say I have (as filters):
: ASP
: ASPX
: HTM
: CSS
:
: My filename is "Newfile.txt"
:
: I want, however to save it as NewFile.HTM
:
: so - I want to click the combobox ('Save as type') - - and I want the
: filename to change from 'Newfile.txt' to 'Newfile.HTM', JUST from changing
: the 'Save as type' combobox in the Common Dialog Control.
:
: right now - I change the combobox and it either ignores the file extension
: that I changed it to, or, (and I don't have an exact, repeatable scenario
on
: this) sometimes, it saves as
: Newfile.txt.htm
:
: I guess I should ask - - - Is this at all possible? - then, if the answer
: is yes - - how?
:
: "Elmo Watson" <sputnik@xxxxxxxxxxxxxxxx> wrote in message
: news:uJ89HIUnFHA.4064@xxxxxxxxxxxxxxxxxxxxxxx
: > That does help in something else I'm going for -
: > but what I was talking about was, when you change the File Extension in
: > the
: > 'Save as type' combo box - I need that extension to change in the
filename
: > textbox
: >
: > Like if the filename is :
: > Newfile.txt
: > Then, I choose .doc from the 'Save as type' combo box - -
: > I want the filename to change to
: > Newfile.doc
: >
: >
: > "Ted" <2000@xxxxxxxxxx> wrote in message
: > news:%23kcYuBUnFHA.576@xxxxxxxxxxxxxxxxxxxxxxx
: >> Dim d$
: >> d$ = UCase(Right(CommonDialog1.FileName, 3))
: >> If d$ = "TXT" Then
: >> RichTextBox1.SaveFile CommonDialog1.FileName, rtfText
: >> Else
: >> RichTextBox1.SaveFile CommonDialog1.FileName, rtfRTF
: >> End If
: >>
: >> Or you can use the select case
: >> d$ = UCase(Right(CommonDialog1.FileName, 3))
: >> Select Case
: >> Case d$ = "TXT"
: >> RichTextBox1.SaveFile CommonDialog1.FileName, rtfText
: >> Case d$= "RTF"
: >> RichTextBox1.SaveFile CommonDialog1.FileName, rtfRTF
: >>
: >> Case Else
: >> msgbox "Doc is not supported for example"
: >> End Select
: >>
: >>
: >> "Elmo Watson" <sputnik@xxxxxxxxxxxxxxxx> wrote in message
: >> news:OhhxMLTnFHA.3256@xxxxxxxxxxxxxxxxxxxxxxx
: >> > with the built in Common Dialog - - let's say I have 5 or 6 levels of
: >> > filetypes an app can open
: >> >
: >> > When the user changes the file type - how can I get the matching
: > extension
: >> > to change in the filename textbox of the Common dialog?
: >> >
: >> >
: >> >
: >>
: >>
: >
: >
:
:
.
- References:
- Common Dialog - Change file extension
- From: Elmo Watson
- Re: Common Dialog - Change file extension
- From: Elmo Watson
- Re: Common Dialog - Change file extension
- From: Elmo Watson
- Common Dialog - Change file extension
- Prev by Date: Re: Common Dialog - Change file extension
- Next by Date: vb-listview-plz help me out
- Previous by thread: Re: Common Dialog - Change file extension
- Next by thread: Re: Common Dialog - Change file extension
- Index(es):
Relevant Pages
|
Loading