Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Visual Basic

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-2008, 04:52 PM
Don
 
Posts: n/a
Capture filename from dialog box

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
Reply With Quote
  #2 (permalink)  
Old 09-05-2008, 05:02 PM
Bob Butler
 
Posts: n/a
Re: Capture filename from dialog box


"Don" <dsarvas@yahoo.com> wrote in message
news:48c1543d.7650812@news.west.cox.net...
> 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.


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.

Reply With Quote
  #3 (permalink)  
Old 09-05-2008, 05:05 PM
Jeff Johnson
 
Posts: n/a
Re: Capture filename from dialog box

"Don" <dsarvas@yahoo.com> wrote in message
news:48c1543d.7650812@news.west.cox.net...

> 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.


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.


Reply With Quote
  #4 (permalink)  
Old 09-05-2008, 05:27 PM
Ken Halter
 
Posts: n/a
Re: Capture filename from dialog box

"Don" <dsarvas@yahoo.com> wrote in message
news:48c1543d.7650812@news.west.cox.net...
> 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


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...ct/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>

--
Ken Halter
Part time groupie


Reply With Quote
  #5 (permalink)  
Old 09-05-2008, 09:06 PM
Karl E. Peterson
 
Posts: n/a
Re: Capture filename from dialog box

Don wrote:
> 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.
--
..NET: It's About Trust!
http://vfred.mvps.org


Reply With Quote
  #6 (permalink)  
Old 09-07-2008, 02:54 AM
Don
 
Posts: n/a
Re: Capture filename from dialog box

THANK YOU, Karl!!!

Works like a charm!

Don


On Fri, 5 Sep 2008 13:06:44 -0700, "Karl E. Peterson" <karl@mvps.org>
wrote:

>Don wrote:
>> 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.
>--
>.NET: It's About Trust!
> http://vfred.mvps.org
>
>


Reply With Quote
  #7 (permalink)  
Old 09-08-2008, 01:27 PM
Don
 
Posts: n/a
Re: Capture filename from dialog box

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

On Fri, 5 Sep 2008 09:27:57 -0700, "Ken Halter"
<Ken_Halter@Use_Sparingly_Hotmail.com> wrote:

>"Don" <dsarvas@yahoo.com> wrote in message
>news:48c1543d.7650812@news.west.cox.net...
>> 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

>
>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...ct/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>
>
>--
>Ken Halter
>Part time groupie
>
>


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Visual Basic


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:14 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Xecuter 3 Mod Chip | eHarmony Coupon | Loans | Per Insurance | Online Image Resizer



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114