How to display selected file name in VisualC - visual-studio

I created a small MFC application which has a brose button and then a dialog box. on the button event, I am able to successfully open the select file option, but when I select the file, it doesn't get displayed in the Dialog box.
How can I do that?
Please help...

Presumably you are using CFileOpenDialog? - after it returns, you need to get the selected file name from the CFileOpenDialog -

by using
GetModuleFileName(0, PathBuf, PathSize); You can get the pathname and by doing CString PathName = FileDlg.GetPathName(); you can get the path completely.

Related

Windows SaveAs dlg with OFN_OVERWRITEPROMPT doesn't detect file deletions?

I'm using a perfectly usual SaveAs dialog (in Delphi Win32 XE2, the system is Win 7 /64), setting OFN_OVERWRITEPROMPT (or the Delphi wrapper's equivalent dlgSave.Options := [ofPathMustExist, ofOverwritePrompt];. So if I select an existing file, the dialog asks for confirmation to overwrite the file.
Everything works as it should except for one silly thing: when I choose a file, then delete that file right in the same dialog, then press OK, the dialog still asks if it's ok to overwrite the (already deleted) file. Apparently, the dialog checks file existence against a pre-loaded list, not the file system. The problem is not specific to Delphi and can be shown very easily even in Notepad:
Run Notepad.exe
Enter some text
Save as a file
Click File Save As again, in the SaveAs dialog do:
Click on the same file to select it,
Right-click and delete the file,
click OK.
The file is no longer there, but you still get the overwrite prompt.
Can anybody please suggest a way to work around this minor but annoying Windows bug? I assume some message processing / callbacks / hooks might be required? A way of checking the file presence in code while the modal SaveAs dialog is open?

Spring, petclinic, Do you want to save this file, or find a program online to open it?

I downloaded the spring mvc petclinic, when I run it, and clicked in the link :
Display all vitiranians
I got a pop up dilog box saying :
Do you want to save this file, or find a program online to open it ?
in the controller that link is defined like this :
#RequestMapping("/vets")
public ModelMap vetsHandler() {
Vets vets = new Vets();
vets.getVetList().addAll(this.clinic.getVets());
return new ModelMap(vets);
}
My question is :
why it does not dsplay vitiranians and just propmpt me withat dialog box ?
any idea or help will be appreciated.
thanks
The application to be used to open a content of a certain type can be customized in some browsers (I know only for Mozilla and Opera):
Mozilla Firefox users
Open Mozilla Firefox
Click Tools and then Options
Within the Options window click Applications
Select the Content Type you wish to adjust. For example, if you want
to change how a .PDF file opens in Firefox, select Adobe Acrobat Document.
In the Action section, change the action to how you wish to open the
file. If you want to download .PDF files instead of opening them,
select Save file.
Opera users
Open Opera
Click Tools and then Preferences
In the Advanced tab click Downloads
Locate and highlight the file extension you wish to adjust. For
example, pdf (or application/pdf). Tip: You can sort these columns.
Once highlighted, click the Edit button.
Within the file type window, specify how you wish for the file to be
handled.

How to programmatically intercept OSX (10.8) print command?

Basically, if I'd like to be able to handle a print job initialization command. Like hitting Cmd+P on a document or something. I'd like to be able to access the data being printed and programmatically handle it rather than through a GUI.
Thanks!
You can possibly use the OSX automator to do what you need here. It depends on what you want to get out of the printed document. Automator allows you to create print plugins, which you can select from the system print dialog. I see you mentioned already that you don't want to use the "PDF" print menu as is, but perhaps some value can be added with extra automation in a print plugin. The plugin will create a .pdf of the printed documents, to which you can apply an automated sequence of actions.
Start /Applications/Automator
Under "Choose a type for your document:", choose "Print Plugin"
Then set up a sequence of actions you need to process your printed document. For example, you might want to do "Extract PDF Text" or "PDF to Images". Type "pdf" in the search field to see all the pdf-related actions available.
Save the automator workflow. You will only be able to give it a name, but not save it as a file in an arbitrary path.
You can use the plugin by opening the system print dialog in any given application, then dropping down the "PDF" menu in the bottom left-hand corner. You should see your plugin appear there.

How to launch "Choose Application" dialog on Mac?

I am using LSOpenItemsWithRole() to open any file from my application. It works fine for all files which has a default application on Mac, but for the files which cannot be opened with any default application this method returns an error kLSApplicationNotFoundErr and does nothing.
For such cases, I want my application to launch the "Choose Application" dialog box, so that end users can choose any application from there to open the file. This dialog box pops up whenever any such file is directly opened by double clicking. Is there is any direct API call to do the same?
I don't want to use Objective C call, is there any way to do it using Carbon API calls?
You should use an NSOpenPanel, starting the user in the Applications folder use and the panel:shouldEnableURL: delegate method to filter out paths that don't end in .app. You can use setAccessoryView: to add any custom options to the dialog. This is what the Finder is doing when you click on the "Other..." option when selecting which application to use.
I think you can do it by using NavCreateChooseFileDialog, with NavCustomControl to set the initial location and NavDialogSetFilterTypeIdentifiers to filter out non-apps. (Why don't you want to use Objective-C? You know that you can mix Carbon and Cocoa in one app, right?)

Is it possible to replace the system open file dialog?

I want to replace the standard system open file dialog with the one I wrote, that means no matter within which programs you are opening a file, my dialog will be shown instead of the standard one, is this possible?
It seems that that there is no such API provided to accomplish this, is it possible to use some hooking technique, but this has to be reliable and not to be treated as spyware by anti-virus tools?
any other options?
If this is not possible, is it possible to add to the spacebar or toolbar in the standard open file dialog a button which invokes my dialog, which allow users select a file and in turn returns the path of the selected file to the "File name" input box of the standard dialog?
Any hits, links and code examples will be appreciated.
Starting in Vista, the FileOpen/FileSave dialogs are now "Common Item Dialogs" of which IFileOpenDialog & IFileSaveDialog are the two published implementations.
Since they're just COM objects with known CLSIDs you might get away with just replacing them by re-registering using their CLSIDs. Never tried something like that, might trip all sorts of alarm bells.
Pre-Vista file dialogs can be hooked in process, but I've never come across anything about global hooks or equivalent.
If you copy a file/folder to a dialog's filename field it usually pastes the full path anyway.
For example, if you have open both a program calling the standard open/save dialog box and also have a window open at the file or path that you want to work with (open from/save to), you can simply copy the file/folder from the explorer window, and then paste into the filename field of the dialog box, and it will insert the full path of the file/folder. No custom script is required!
Alternatively, for those programs that use custom dialog boxes where this step fails, copy the same file/folder in the window into the address bar of the same window (assuming it is visible). This will paste the full path, which you can copy again, and then paste this full path into the custom dialog box. I often use this when creating Office hyperlinks (Ctrl+K), because the Insert Hyperlink dialog does not work for the first method.
You can also use similar methods but paste into address bar fields and it works.

Resources