Question

What is handle to the CFileDialog Dropdown control created when we type in the FileName control?

Asked by: pibarale

How do we find the handle of the dropdown control created when we type something in the filename control area. Please refer to the image and the dropdown control is highlighted in the red rectangle.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-02 at 20:02:58ID24866089
Topics

Windows MFC Programming

,

Windows 7

,

Windows Vista

Participating Experts
4
Points
500
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CFileDialog ComboBox
    Hi, environment = VC++6.0 SP3, NT SP5 I'm currently in need of a drive/directory dropdown combobox, similar to the CFileDialogs. My control is currently a ComboBoxEx placed on the first page of a PropertySheet, that is then embeded in a DialogBar. My problem is trying to crea...
  2. Color Dropdown in .NET
    Hi guys, I'm trying to create a color dropdown in .NET for use on a web form. I would like the colors to be named on the dropdown, with the bgcolor of each row, the corresponding color. I would also like the dropdowns value to be in hex. Can anyone help? I have some code, ...
  3. lookahead in a dropdown
    Hey I want to be able to sort a dropdown as the user enters the first few characters..... For example if the user is entering "pa...." then the list should contain first all the strings starting with "pa" and then the remaining strings... H...
  4. dropdown selection
    is it possible to highlight a dropdown selection without using a selectedIndex statement on a page load call?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Subrat2009Posted on 2009-11-02 at 21:37:23ID: 25726291

U can use EnumChildWindows() toget the window handles and use GetClassName() to get the class.

Refer :

Findwindow()

EnumChildWindows()

GetClassName()

 

by: pibaralePosted on 2009-11-02 at 22:29:39ID: 25726469

Hi Subrat2009

Thanks for the prompt respnose.
But all methods you suggest need those say handles (parent and child) and classes name and all these what I am looking for and raise these query.

How should I start?
Could you give me some hint and I am not looking for all the bunch of code?

 

by: alb66Posted on 2009-11-02 at 23:49:17ID: 25726753

You can use Spy++ to get the handl and control ID of the combo box

 

by: DanRollinsPosted on 2009-11-03 at 00:25:23ID: 25726918

I presume that you are bringing up that dialog box by using

   CFileDialog http://msdn.microsoft.com/en-us/library/dk77e5e7(VS.80).aspx

Is that correct?  You are then calling its
    DoModal  http://msdn.microsoft.com/en-us/library/3xb6dhth(VS.80).aspx
function. Is that also correct?  

If so, then the first part of your task is providing a way for the calling object (your program that calls CFileDialog:DoModal() ) get a chance to take some action while the dialog is running (you normally need to wait for it to complete).  You can start by reading this:

   Setting View and Sort in a File Open Dialog
   http://www.experts-exchange.com/A_1334.html

It shows how to ad an OnFIleNameChange() handler.  If my guesses are correct and if you can get that far, then let me know and I will provide the rest of the details on how to obtain the data from the dropdown list.

I am curious, howerver:  Why do you want to know this?

 

by: pibaralePosted on 2009-11-03 at 00:56:30ID: 25727079

Hi Dan,

It is nice to see you again in this discussion.

Actually I am trying to play with messages like WM_KEYUP when the user select some items in this dropdown box say "Program Files". When the user select "Program Files" by pressing VK_DOWN and then release, the text  "Program Files" will be in the combox. This is what I want to stop. I have already implemented some hooks. If know the handle of this dynamic dropdown box then probably it is done.

I will be come back soon after reading all your suggestions.

Thanks
Pibarale.

 

by: Subrat2009Posted on 2009-11-03 at 04:12:15ID: 25728124

Using EnumChildWIndows() we cn get child window handle. which passes parent window handle. see the example below.

Spy++ is using this technique to get all the window handle and class name, text etc....

You can get spy++ source code from codeproject.com.

#include <iostream>
#include <windows.h>

using namespace std;

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {

    cout << "hwnd_Child = " << hwnd << endl;
    return TRUE; // must return TRUE; If return is FALSE it stops the recursion
}

int main() {
   
   HWND hwnd = FindWindow(0, "WindowClass");
   EnumChildWindows(hwnd, EnumChildProc, 0);
   return 0;
}

 

by: mrwad99Posted on 2009-11-05 at 09:30:06ID: 25751813

I became interested in this question and have the following solution to propose.

Based on the concept that DanRollins introduced regarding OnFileNameChange().  Basically, we retrieve the handle to the combo box, then subclass it to give it a new WNDPROC.  In this WNDPROC, we wait for the CBN_SELCHANGE notification, which is fired when the selection changes, then handle it appropriately.  In this example, I just ASSERT; you can do whatever you want though.

The following code assumes we have a class CMyFileDialog, and a member BOOL m_bGotWndProc initialised to FALSE in the constructor.

HTH


LRESULT CALLBACK wndProcComboNew ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	// Retrieve the old WNDPROC
	WNDPROC wndProcOld = NULL;
	VERIFY ( wndProcOld = ( WNDPROC ) GetProp ( hWnd, _T("Original_WndProc") ) );
	if ( !wndProcOld ) return 0; 
	// Handle selection changed in combo accordingly
	if ( uMsg == WM_COMMAND && HIWORD(wParam) == CBN_SELCHANGE )
		ASSERT ( FALSE ); 
	return ::CallWindowProc ( wndProcOld, hWnd, uMsg, wParam, lParam );
} 
/*virtual*/ void CMyFileDialog::OnFileNameChange()
{
	if ( m_bGotWndProc ) return;
	CWnd* pWnd = GetParent()->GetDlgItem ( 0x47C );	// Handle of combo where user types filename
	if ( !pWnd ) return; 
	// Get the old WNDPROC and store it as a property so we can retrieve it in our new WNDPROC
	LONG_PTR wndProcOld = ::SetWindowLongPtr ( pWnd->m_hWnd, GWLP_WNDPROC, ( LONG ) wndProcComboNew );
	if ( wndProcOld )
	{
		if ( ! SetProp ( pWnd->m_hWnd, _T("Original_WndProc"), ( HANDLE ) wndProcOld ) )
		{
			return;
		}
		m_bGotWndProc = TRUE;
	}
}

                                              
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:

Select allOpen in new window

 

by: DanRollinsPosted on 2009-11-05 at 19:48:29ID: 25756466

I still don't know why on earth you want to monkey with that dropdown box.  

It is there to make things easier for the user -- it lists all the items that match with the initial user input.  Instead of typing the full name, you type a partial name, press "down arrow" a few times, and enter.

I assume that there is a specific thing that you want to do; that is, a special reason that you want to control what's in the drop-down list.

 Why not tell us the secret?

I don't ask that out if idle curiousity.  I ask it becasue there is almost certainly a way to accomplish your goal (whatever it is) without messing around with the drop-down box.

 

by: pibaralePosted on 2009-11-05 at 19:51:11ID: 25756477

Hi mrwad99,

Thanks for contributions. But this does not resolve this problem.

DanRollins/mrwad99,

Once again I consolidate my problem. Please find the following.
As shown In the screen shot above, when I type a character say 'p' a list of items starting with this character is populated in the dropdown box shown in the red rectangle. Then I select an item from the dropdown box either with left mouse (WM_LBUTTONDOWN) or  down arrow key (VK_DOWN),; this selected item is displayed in the combox box.

My objective is to handle this two messages.

 

by: pibaralePosted on 2009-11-05 at 19:58:47ID: 25756505

ha... ha... Yes, Dan....

I want to diable the OK button if the item selected using the above procedure has some specific name. That's it.

 

by: DanRollinsPosted on 2009-11-05 at 23:35:21ID: 25757316

As I thought -- You don't need to mess with the drop-down box.

Just wait for the OnFileNameChange notif and disable the OK button at that point.

Pop up a message box in explanation, if you think the user needs it.

 

by: pibaralePosted on 2009-11-06 at 03:24:54ID: 25758199

Dan,

OnFileNameChange is captured if select an item in the list box i.e, CDN_SELCHANGE is captured in the CFileDialog Hook initialize in the constructor.


m_ofn.lpfnHook = reinterpret_cast< LPOFNHOOKPROC >( FileDialogHookProc );

But the same is not happen in case of this smarty dropsown box. So I stuck here.

 

by: mrwad99Posted on 2009-11-06 at 04:18:44ID: 25758440

Adding a custom message proc via m_ofn.lpfnHook will not work.  It gets called when an item in the list control is clicked, or when the "file types" combo gets dropped down, but not for messages going to the filename combo.

OK.  The following code achieves what you are after.  Every time the text in the edit control part of the combo box changes, I TRACE a message.  You can of course do what you want here; eg disable OK button etc.  This covers what you originally stated that you wanted.  

I achieve this by uisng a technique similar to what MFC does when creating, say, a frame window.  I set a hook immediately before creating my file dialog.  When the hook function gets called, I swap the window procedure of the created window with my own one, which specifically handles the event of the text in a combo changing (I just TRACE a message).  This is OK to do since there is only one combo of style drop down, (not drop list), which is the filename one, but if this becomes a problem, we could always check the ID of the control we receive the event for to ensure it is the correct combo.

NOTE: the code can probably be tidied a bit more than what I present here; for example, I use a public member of CMyFileDialog as the hook procedure.  Maybe the hook could be added in an override of DoModal() instead of in client code (my test dialog).  We could also tidy the use of a global HHOOK too I guess, but these are left as an exercise to the reader :)

HTH

class CMyFileDialog : public CFileDialog
{
public:
	// Standard constructor
	explicit CMyFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
		LPCTSTR lpszDefExt = NULL,
		LPCTSTR lpszFileName = NULL,
		DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		LPCTSTR lpszFilter = NULL,
		CWnd* pParentWnd = NULL,
		DWORD dwSize = 0,
		BOOL bVistaStyle = TRUE) : CFileDialog ( bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd, dwSize, bVistaStyle )
	{
	} 
	// Hook procedure waiting for file dialog creation
	static LRESULT CALLBACK WaitForFileDlgHook(int code, WPARAM wParam, LPARAM lParam); 
protected: 
	// Have we changed the WNDPROC?
	static BOOL s_bGotWndProc;
}; 
/* static */ BOOL CMyFileDialog::s_bGotWndProc = FALSE; 
// Global, stores the original hook procedure
HHOOK g_hHookOrig_WaitForFileDlg = NULL; 
LRESULT CALLBACK wndProcDlgNew ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	// Retrieve the old WNDPROC
	WNDPROC wndProcOld = NULL;
	VERIFY ( wndProcOld = ( WNDPROC ) GetProp ( hWnd, _T("Original_WndProc") ) );
	if ( !wndProcOld ) return 0; 
	// Handle change in edit control on combo accordingly
	if ( uMsg == WM_COMMAND && HIWORD(wParam) == CBN_EDITCHANGE )
	{
		TRACE ( _T("Handle the edit text being changed in whatever way here!\n") );
	} 
	return ::CallWindowProc ( wndProcOld, hWnd, uMsg, wParam, lParam );
} 
LRESULT CALLBACK CMyFileDialog::WaitForFileDlgHook(int code, WPARAM wParam, LPARAM lParam)
{
	if ( code = HCBT_CREATEWND )
	{
		//
		// Window has been created
		//		 
		HWND hwndCreated = ( HWND ) wParam;
		ASSERT ( hwndCreated != NULL );		// The window that has been created.  Should not be NULL. 
		LONG_PTR wndProcOld = ::SetWindowLongPtr ( hwndCreated, GWLP_WNDPROC, ( LONG ) wndProcDlgNew);
		if ( wndProcOld )
		{
			if ( ! SetProp ( hwndCreated, _T("Original_WndProc"), ( HANDLE ) wndProcOld ) )
			{
				ASSERT ( FALSE );	// Bad.  Cannot continue, but attempt to restore the original WNDPROC.
				::SetWindowLongPtr ( hwndCreated, GWLP_WNDPROC, ( LONG ) wndProcOld );
			} 
			s_bGotWndProc = TRUE; 
		}
	}
	// Remove hook
	::UnhookWindowsHookEx ( g_hHookOrig_WaitForFileDlg ); 
	return 0;
} 
// Client code to create a CMyFileDialog 
// Create hook, then create dialog.
g_hHookOrig_WaitForFileDlg = ::SetWindowsHookEx ( WH_CBT, CMyFileDialog::WaitForFileDlgHook, NULL, ::GetCurrentThreadId() );
CMyFileDialog dlg ( TRUE, _T("*.*"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("All files (*.*)|*.*|Text files (*.txt)|*.txt||") );
dlg.DoModal();
                                              
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:

Select allOpen in new window

 

by: DanRollinsPosted on 2009-11-06 at 14:03:34ID: 25763485

The designers already put in place this very simple mechanism to disallow unwanted selections without exiting from the dialog.  See:

  CFileDialog::OnFileNameOK  
  http://msdn.microsoft.com/en-us/library/f9707521.aspx

BOOL CFileDlgEx::OnFileNameOK( )
{
	BOOL nRet=0;   // OK to allwo
	CString s= GetFileTitle();
	if ( s == L"Control Panel" ) {
		MessageBeep(-1);
		nRet=1;   // nope.  Disallowed.
	}
	return (nRet );
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: pibaralePosted on 2009-11-06 at 20:21:24ID: 31649230

It was a nice discussion.

 

by: mrwad99Posted on 2009-11-07 at 07:30:04ID: 25766588

pibarale

Thank you for taking the time to accept answers.  However, it is clear that you are not fully aware of how to *grade* answers.

We have provided you with working code that does *exactly* what you requested.  Not partially, but *exactly* what you want.  For that, we expect an A.  

Please read http://www.experts-exchange.com/help.jsp#hs=29&hi=403.  To quote, "an answer is worth an A, unless it doesn't resolve your issue."  I am now thinking that you did not receive a fully working solution, for which we can surely help you further.  Is this the case?  Can you take a few more minutes and explain why you decided on a B as opposed to an A?

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...