Re: Common Dialog - Change file extension



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?
: >> >
: >> >
: >> >
: >>
: >>
: >
: >
:
:

.



Relevant Pages

  • Re: alphabetically arranging combobox entries
    ... and adding their filename ... > (wihtout extension) to a JCombobox. ... > It is working but the combobox entries are not appearing ...
    (comp.lang.java.help)
  • Re: Common Dialog - Change file extension
    ... My filename is "Newfile.txt" ... the 'Save as type' combobox in the Common Dialog Control. ... right now - I change the combobox and it either ignores the file extension ...
    (microsoft.public.vb.general.discussion)
  • Re: Using an Excel sheet for batch delete
    ... but wondered what the routine would make of the situation where the input to both source and destination popups was identical. ... When I used it on filenames with no extension, ... Does the filename contain any dots. ... If SourcePath = "" Then Exit Sub ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Apply LEN result to string?
    ... If the end result is to strip the extension off a filename then you could do ... Public Function RemoveExtension(ByVal FileName As String, ... Using VB to fetch the filename and placing it in cell B1., ...
    (microsoft.public.excel.programming)
  • Re: Cant copy/paste
    ... MS-MVP Windows Shell/User ... I have these five Nvidia entries disabled. ... Filename: C:\WINDOWS\System32\nvshell.dll ... Extension Name: Desktop Explorer Menu ...
    (microsoft.public.windowsxp.help_and_support)

Loading