Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / September 2008



Tip: Looking for answers? Try searching our database.

Capture filename from dialog box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don - 05 Sep 2008 16:52 GMT
How can I capture the name of the file a user right clicks in the open
file dialog using the common dialog box control?

I can capture the name if a file is double clicked, or OPEN is clicked
after selecting a file, or CANCEL clicked, but if they choose to right
click on a file and choose OPEN WITH option, then I can't seem to get
the name of the file they selected.

Don
Bob Butler - 05 Sep 2008 17:02 GMT
> How can I capture the name of the file a user right clicks in the open
> file dialog using the common dialog box control?
[quoted text clipped - 3 lines]
> click on a file and choose OPEN WITH option, then I can't seem to get
> the name of the file they selected.

If they do that whatever app is selected will be started.  If it's your app
then a second instance of your app will start and Command$ will contain the
path to the selected file.
Jeff Johnson - 05 Sep 2008 17:05 GMT
> How can I capture the name of the file a user right clicks in the open
> file dialog using the common dialog box control?
[quoted text clipped - 3 lines]
> click on a file and choose OPEN WITH option, then I can't seem to get
> the name of the file they selected.

They're not actually selecting the file at that point, at least not as far
as the common dialog is concerned. If they right-clicked and chose Select,
then that would be equivalent clicking Open, but not using Open With. Open
With is provided by Windows Explorer, and it's as invisible to the common
dialog as, say, copy and paste.

The bottom line is: tell your user not to do that, or at least that it's not
something your app supports.
Ken Halter - 05 Sep 2008 17:27 GMT
> How can I capture the name of the file a user right clicks in the open
> file dialog using the common dialog box control?
[quoted text clipped - 5 lines]
>
> Don

fwiw, the functionality you're describing is built in to the dialog and
every app using that dialog has the same limitations, regardless of which
language was used to write the app. You can probably setup a hooked dialog
to intercept this kind of thing, but constantly fighting the built in
behavior of any component, is an uphill battle.... the code below allows you
to completely replace the ocx you're using. It /probably/ traps right-click,
if you want it to, but I'm not sure.

CommonDialog/Direct
http://www.vbaccelerator.com/home/vb/code/Libraries/Common_Dialogs/Common_Dialog
_Direct/article.asp


<q>
There are a number of areas where Common Dialog/Direct improves upon the
implementation of COMDLG32.OCX supplied with VB:

Common Dialog hooks are supported. It is possible to:
  Confirm files being chosen before a file dialog is closed
  Centre dialogs accurately to any object
  Incorporate a common dialog into your own form, like the Add Form and New
Project dialogs in VB5.
  Templates are supported.

The file dialogs return the selected filter index when the user chooses a
file. You can get and set the custom colours set up in the colour dialog. It
is possible to show the Page Setup dialog for the printer
</q>

Signature

Ken Halter
Part time groupie

Don - 08 Sep 2008 13:27 GMT
Thanks for the link, Ken.  I downloaded the full code and it works
great.  I followed the suggestion Karl posted to use the SendMessage
API to get the path and file I needed if a user right clicked and
chose the "Open With" option.  Works so well, I'll probably stick with
and work with those class files rather than using the common dialog
control.

Don

>> How can I capture the name of the file a user right clicks in the open
>> file dialog using the common dialog box control?
[quoted text clipped - 32 lines]
>is possible to show the Page Setup dialog for the printer
></q>
Karl E. Peterson - 05 Sep 2008 21:06 GMT
> How can I capture the name of the file a user right clicks in the open
> file dialog using the common dialog box control?

You'd have to use the GetOpenFileName API directly, set a callback hook to the
common dialog that results, and watch for CDN_SELCHANGE notifications.  Call
SendMessage with CDM_GETSPEC to get the filename:

     Case CDN_SELCHANGE
        ' Find handle to dialog window.
        hWnd = GetParent(hDlg)
        ' Get size of buffer required for filespec.
        nChars = SendMessage(hWnd, CDM_GETSPEC, 0&, ByVal m_FileEx)
        ' Get the full buffer for the filespec(s)
        If nChars > 0 Then
           m_FileEx = Space$(nChars)
           Call SendMessage(hWnd, CDM_GETSPEC, nChars, ByVal m_FileEx)
        End If

Optionally, test which mouse button is down at this point, to decide how to proceed.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

Don - 07 Sep 2008 02:54 GMT
THANK YOU, Karl!!!

Works like a charm!

Don

>> How can I capture the name of the file a user right clicks in the open
>> file dialog using the common dialog box control?
[quoted text clipped - 15 lines]
>
>Optionally, test which mouse button is down at this point, to decide how to proceed.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.