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 / Win API / June 2008



Tip: Looking for answers? Try searching our database.

GetOpenFileName & hook proc api calls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MBB - 28 May 2008 22:40 GMT
hello, all,

i have a winapi question regarding some GetOpenFileName behavior.
it's not a language matter but i can find no other winapi group that looks more
appropriate. if there is one, please advise.

the problem: i'm in win2K. i call GetOpenFileName with a OFN struct that
specifies a multiselect listbox yet when i try to harvest the number of
selections, SendMessage returns LB_ERR (-1) which indicates the listbox is
single selection.

ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;

So the listbox in the dialog is supposed to allow multiple selections and it
does. However, in my hook proc, i trap the CDN_FILEOK message (sent when the
user has clicked OK) and attempt to get the number of selections with a few api
calls:

HWND hListboxOfFilenames = :: GetDlgItem (hDlgMerge, lst1);
long NumSelected = :: SendMessage (hListboxOfFilenames, LB_GETSELCOUNT, (WPARAM)
0, (LPARAM) 0);

(lst1 is the ID of the listbox in question according to "Explorer-Style Control
Indentifiers". hDlgMerge is a handle to the dialog.)
Always NumSelected = -1.

(i am trying to determine the # of files selected because the format of the
selected filenames (in the ofn.lpstrFile member) depends on whether more than
one was selected. so i naively assumed i could discover this in the hook proc
and communicate the info via the ofn.lCustData member. but LB_GETSELCOUNT does
not seem to be working as advertised.)

does anybody have any ideas about what is going on?

TIA!
Karl E. Peterson - 28 May 2008 23:21 GMT
> So the listbox in the dialog ...
<snip>
> does anybody have any ideas about what is going on?

<refrain>Are you familiar with Spy++?</refrain>

That's not a listbox - it's a listview.  This is a ClassicVB group, and it doesn't
appear you're using that langauge.  So, best suggestion would be to google
"CDN_SELCHANGE" and see how that's typically handled in your language of choice.
Signature

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

MBB - 29 May 2008 02:08 GMT
>> So the listbox in the dialog ...
> <snip>
[quoted text clipped - 5 lines]
> appear you're using that langauge.  So, best suggestion would be to google
> "CDN_SELCHANGE" and see how that's typically handled in your language of choice.

the MSDN article that discusses the CDN_SELCHANGE notification refers to the
control as a list box, as do other articles.

yes, i am familiar with Spy++. so what's your point?

how do you know what language i am using?
i stated clearly in my message that this is an api question.
isn't winapi part of this group's name?
if i write a VB Classic app that tries to do the same thing and fails in the
same way, will you take a less antagonistic approach?

i goggled extensively BEFORE posting.
can you suggest a more appropriate group where i might re-post this question?
(as i wrote: if there is one, please advise.)

congratulations!
you have just provided the most unhelpful MS news group reply i have EVER
received. what is accomplished by being so snarky?
Dean Earley - 29 May 2008 09:39 GMT
> can you suggest a more appropriate group where i might re-post this
> question?
> (as i wrote: if there is one, please advise.)

microsoft.public.platformsdk.*, most likely
microsoft.public.platformsdk.base.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

MBB - 29 May 2008 18:46 GMT
>> can you suggest a more appropriate group where i might re-post this
>> question?
>> (as i wrote: if there is one, please advise.)
>
> microsoft.public.platformsdk.*, most likely
> microsoft.public.platformsdk.base.

thanks for the recommendation.
Karl E. Peterson - 29 May 2008 21:38 GMT
>>> So the listbox in the dialog ...
>> <snip>
[quoted text clipped - 9 lines]
> the MSDN article that discusses the CDN_SELCHANGE notification refers to the
> control as a list box, as do other articles.

Perhaps.

> yes, i am familiar with Spy++. so what's your point?

That using it would show the user is interacting with a listview.  I'm not aware of
the hidden listbox mentioned by Scott, nor did I need to be to deal with the
CDN_SELCHANGE notification.

> how do you know what language i am using?

I don't.  I just had a pretty good idea it wasn't ClassicVB.  Is it?

> i stated clearly in my message that this is an api question.

Yep.

> isn't winapi part of this group's name?

Yep.

> if i write a VB Classic app that tries to do the same thing and fails in the
> same way, will you take a less antagonistic approach?

No, I'd offer you the code I use.  To be precise, in OFNHookProc...

  Select Case uMsg
     Case WM_NOTIFY
        ' The OFNOTIFY struct is passed in the lParam of this message.
        Call CopyMemory(ofn, ByVal lParam, Len(ofn))
        ' A pointer to an OPENFILENAME structure is passed in OFNOTIFY.
        Call CopyMemory(opfile, ByVal ofn.lpOFN, Len(opfile))

        ' Branch based on notification code.
        Select Case ofn.hdr.code

           Case CDN_FILEOK
              ' This is our chance to say whether the file selection is valid.

           Case CDN_FOLDERCHANGE
              'Debug.Print "CDN_FOLDERCHANGE"

           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
              ' Get size of buffer required for path.
              nChars = SendMessage(hWnd, CDM_GETFOLDERPATH, 0&, ByVal m_FolderEx)
              ' Get the full buffer for the path.
              If nChars > 0 Then
                 m_FolderEx = Space$(nChars)
                 Call SendMessage(hWnd, CDM_GETFOLDERPATH, nChars, ByVal
m_FolderEx)
              End If
        End Select
  End Select

It's probably a little non-standard, but it does the job for me.  I stash the file
and folder strings in persisted (module-scope) variables, to be acted upon when the
dialog is dismissed.

> i goggled extensively BEFORE posting.
> can you suggest a more appropriate group where i might re-post this question?
> (as i wrote: if there is one, please advise.)

Looks like you got a couple of other suggestions.  I'm not saying this group is
INappropriate, either, fwiw.

> congratulations!
> you have just provided the most unhelpful MS news group reply i have EVER
> received.

Kewl.  :-)

> what is accomplished by being so snarky?

Sorry, I thought I had given you the info you needed.  I misunderestimated,
apparently.
Signature

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

Scott Seligman - 29 May 2008 03:17 GMT
>i have a winapi question regarding some GetOpenFileName behavior. it's
>not a language matter but i can find no other winapi group that looks
>more appropriate. if there is one, please advise.

This group is really for using the winapi with VB6. It's not meant
as a catch all for general API questions. I'd recommend trying
microsoft.public.win32.programmer.ui

>the problem: i'm in win2K. i call GetOpenFileName with a OFN struct
>that specifies a multiselect listbox yet when i try to harvest the
>number of selections, SendMessage returns LB_ERR (-1) which indicates
>the listbox is single selection.

Two problems:

The listbox you're looking at is a hidden listbox. I'm guessing it's
there for backwards compatibility reasons, but whatever the case, it's
not the listview that the user makes selections in. I'm not aware of any
documented way to get the listview the user sees, but even if there was,
I wouldn't want to use it in this case because:

It's entirely possible to select multiple files and have nothing at all
selected in the list view. (Granted, this is an edge case, but still a
real one).

You should just look at the string that's returned to you, if it
contains one null-terminated string, then the user selected one file.
If it contains three or more null-terminated strings, then the user
selected multiple files.

Signature

--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
  Power tends to corrupt, and absolute power corrupts absolutely. Great
  men are almost always bad men.
  -- Lord Acton

MBB - 29 May 2008 18:45 GMT
>> i have a winapi question regarding some GetOpenFileName behavior. it's
>> not a language matter but i can find no other winapi group that looks
[quoted text clipped - 25 lines]
> If it contains three or more null-terminated strings, then the user
> selected multiple files.

i appreciate the substantive reply.
i ended up doing what you suggested but was puzzled by the behavior i observed.
your "hidden listbox" remarks will provoke further investigations on my part.
thanks!
Steve - 31 May 2008 11:21 GMT
> hello, all,
>
> i have a winapi question regarding some GetOpenFileName behavior.
> it's not a language matter but i can find no other winapi group that
> looks more appropriate. if there is one, please advise.

The, by far, best one is comp.os.ms-windows.programmer.win32
But it's very, very advanced (plenty of undocumented stuff never seen
elsewhere... then, don't post basic questions :-)
Thorsten Albers - 31 May 2008 18:12 GMT
MBB <marlana_blackburn@infometrix.com> schrieb im Beitrag
<uDtfmtQwIHA.5124@TK2MSFTNGP04.phx.gbl>...
> i have a winapi question regarding some GetOpenFileName behavior.
> it's not a language matter but i can find no other winapi group that looks more
> appropriate. if there is one, please advise.

Your code is C/C++ code. Therefore you should ask in a C/C++ newsgroup.
C/C++ newsgroups usually cover also API programming questions since C/C++
applications usually need a lot of API programming - other than VB which
allows to code nice applications without any API usage.

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

RB Smissaert - 16 Jun 2008 00:28 GMT
Not sure it applies to you (as you code in C++?), but there is a long thread
about
this in vb.general.discussion: GetOpenFileName with multi-select and typelib
You might pick something useful from it.

RBS

> hello, all,
>
[quoted text clipped - 32 lines]
>
> TIA!
 
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



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