|
-
Nov 24th, 2019, 07:30 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] in-time hook OpenSaveFileDialog to add Encoding Dropdown
The OpenFileDialog is opened, when we select File filter *.txt, OpenFileDialog will auto add Encoding Dropdown on OpenFileDialog window. Is it possible?
Last edited by DaveDavis; Nov 24th, 2019 at 07:58 PM.
Reason: add pic
-
Nov 25th, 2019, 01:17 AM
#2
Re: in-time hook OpenSaveFileDialog to add Encoding Dropdown
On Vista+ you can use the new IFileOpenDialog object to add custom controls.
And it's not directly on topic, but an unrelated demo of mine shows how to show or not show those controls depending on file type selected (it's an imaging demo that shows a box to adjust image quality only when JPG is the selected save type).
-
Nov 25th, 2019, 01:59 AM
#3
Thread Starter
Fanatic Member
Re: in-time hook OpenSaveFileDialog to add Encoding Dropdown
 Originally Posted by fafalone
On Vista+ you can use the new IFileOpenDialog object to add custom controls.
And it's not directly on topic, but an unrelated demo of mine shows how to show or not show those controls depending on file type selected (it's an imaging demo that shows a box to adjust image quality only when JPG is the selected save type).
It is exact what I am looking for. How to set additional controls position/alignment?
The demo is very advanced and sophistic. I haven't got clue how to do modifiaction for my case because I haven't understood how it works.
I used this to do Dialog hook. But I don't know how to hook the selection of filter because dialog is already being brought out.
Last edited by DaveDavis; Nov 25th, 2019 at 02:09 AM.
-
Nov 25th, 2019, 02:43 AM
#4
Re: in-time hook OpenSaveFileDialog to add Encoding Dropdown
Look at the WIC demo I linked, it just makes the single customization of adding a particular control when a certain type is selected (and hiding it when any other is selected).
Module-level vars:
Code:
Private fsd As FileSaveDialog
Private fdc As IFileDialogCustomize
Private WithEvents cEvents As cFileDlgEvents
The save button click:
Code:
Private Sub Command3_Click()
Set fsd = New FileSaveDialog
Dim SaveFilter() As COMDLG_FILTERSPEC
ReDim SaveFilter(1)
SaveFilter(0).pszName = "JPEG Image (*.jpg)"
SaveFilter(0).pszSpec = "*.jpg"
SaveFilter(1).pszName = "PNG Image (*.png)"
SaveFilter(1).pszSpec = "*.png"
fsd.SetTitle "Save image as..."
fsd.SetFileTypes UBound(SaveFilter) + 1, VarPtr(SaveFilter(0).pszName)
fsd.SetOptions FOS_STRICTFILETYPES
Set fdc = fsd
fdc.AddText 2000, "Image Quality (Percent)"
fdc.AddEditBox 3000, "100"
On Error Resume Next
Set cEvents = New cFileDlgEvents
fsd.Advise cEvents, dwCk
fsd.Show Me.hWnd
Dim siRes As IShellItem
fsd.GetResult siRes
If (siRes Is Nothing) = False Then
Dim sSave As String, lpSave As Long
Dim nFmt As Long
siRes.GetDisplayName SIGDN_FILESYSPATH, lpSave
sSave = LPWSTRtoSTR(lpSave)
fsd.GetFileTypeIndex nFmt
Debug.Print "Calling save(" & nFmt & ") " & sSave
Dim sHR As Long
Select Case nFmt
Case 1
If Right$(sSave, 4) <> ".jpg" Then sSave = sSave & ".jpg"
sHR = cWI.SaveJPG(sSave, CSng(strImgQ) / 100)
Case 2
If Right$(sSave, 4) <> ".png" Then sSave = sSave & ".png"
sHR = cWI.SavePNG(sSave)
End Select
If sHR = S_OK Then
Label4.Caption = "Saved."
Else
Label4.Caption = "Error: 0x" & Hex$(sHR)
End If
Else
Debug.Print "No item"
End If
End Sub
and handling the events for the save format change:
Code:
Private Sub cEvents_OnOk()
Dim lp As Long, sz As Long
fdc.GetEditBoxText 3000, lp
sz = LPWSTRtoSTR(lp)
strImgQ = sz
End Sub
Private Sub cEvents_TypeChange(nIdx As Long)
Debug.Print "TypeChange " & nIdx
If nIdx = 2 Then
fdc.SetControlState 2000, CDCS_INACTIVE
fdc.SetControlState 3000, CDCS_INACTIVE
ElseIf nIdx = 1 Then
fdc.SetControlState 2000, CDCS_VISIBLE Or CDCS_ENABLED
fdc.SetControlState 3000, CDCS_VISIBLE Or CDCS_ENABLED
End If
End Sub
(You'd use .GetSelectedControlItem instead of GetEditText to get the selected combobox item)
The events class included (cFileDlgEvents) could be used as-is, all it does is raise events for OnOk (clicked Save button) and OnTypeChange (format dropdown selection changed).
If you wanted to do it the way that demo does, you'd need to find the hWnd of the format list combo then watch its parent window for the CBN_SELCHANGE notification.
Last edited by fafalone; Nov 25th, 2019 at 02:47 AM.
-
Nov 25th, 2019, 03:49 AM
#5
Thread Starter
Fanatic Member
Re: in-time hook OpenSaveFileDialog to add Encoding Dropdown
Thanks for showing me related codes.
 Originally Posted by fafalone
If you wanted to do it the way that demo does, you'd need to find the hWnd of the format list combo then watch its parent window for the CBN_SELCHANGE notification.
We have to watch CDN_TYPECHANGE as your code did by cEvents_TypeChange.
-
Nov 25th, 2019, 08:48 AM
#6
Thread Starter
Fanatic Member
Re: [RESOLVED] in-time hook OpenSaveFileDialog to add Encoding Dropdown
Wondering after hook applied, the dialog turn into Explorer-style instead of Vista native style. fafalone solution using IFileDialogCustomize is better (only work on vista or newer?).
This blog shows the limits.
Last edited by DaveDavis; Nov 25th, 2019 at 08:56 AM.
-
Nov 25th, 2019, 01:09 PM
#7
Re: [RESOLVED] in-time hook OpenSaveFileDialog to add Encoding Dropdown
If just using the APIs, the style changes to the old ugly style if you subclass it. Using modern interfaces are better IMO. They should work as far back as XP/Win2000.
Here's another version, similar to fafalone's. Major difference is no TLB required, not that a TLB is a bad thing 'cause it isn't.
http://www.vbforums.com/showthread.p...t-Another-One)
-
Nov 25th, 2019, 07:05 PM
#8
Thread Starter
Fanatic Member
Re: [RESOLVED] in-time hook OpenSaveFileDialog to add Encoding Dropdown
 Originally Posted by LaVolpe
If just using the APIs, the style changes to the old ugly style if you subclass it. Using modern interfaces are better IMO. They should work as far back as XP/Win2000.
Here's another version, similar to fafalone's. Major difference is no TLB required, not that a TLB is a bad thing 'cause it isn't.
http://www.vbforums.com/showthread.p...t-Another-One)
It's comprehensive solution in VB6! I will do more testing before put in use. Can I use it in commercial product for local small comunity?
Currently I am looking for .NET solution because my software has two language:.NET and VB6. Any good links in .NET?
Edited: For .NET, we can use Windows-API-Code-Pack-1.1. But I haven't yet figured out how to on-demand add Encoding dropdown by Filter Type .txt.
Edited:
But I haven't yet figured out how to on-demand add Encoding dropdown by Filter Type .txt.
The solution is to set Encoding Dropdown Visible on demand.
Only problem left is how to position the dropdown combobox. fafalone's code and Windows-API-Code-Pack-1.1 don't have custom size/location attributes for adding controls.
Last edited by DaveDavis; Nov 26th, 2019 at 12:48 AM.
-
Nov 26th, 2019, 06:58 AM
#9
Re: [RESOLVED] in-time hook OpenSaveFileDialog to add Encoding Dropdown
Whether using fafalone's or my implementation of those interfaces, we don't have control where the dialog places the added stuff. If one got froggy, they could possibly use APIs to reposition that stuff. Those interfaces expose the dialog's hWnd and with an hWnd there isn't much you can't do via APIs.
As for your question regarding commercial use. I have no problem, but will not support/offer enhancements. You use the class as-is without any implied warranty. In other words, don't try to hold me accountable if my code breaks your code. I always accept bug reports regardless.
Tags for this Thread
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
|
Click Here to Expand Forum to Full Width
|