SHBrowseForFolder parent window

I'm developing an application in C++ using VS.net. I need a browser to return 
a folder that the user selects. SHBrowseForFolder seems to do the trick in 
most instances. I have one place that it fails. During the 
CWinApp::InitInstance() method the m_hWnd of the main window's parent frame 
window (GetMainWindow()->GetParentFrame()->m_hWnd;) is not setup yet. The 
BrowseInfo::hwndOwner requires it. When I create a CDialog at this point it 
only requires a pointer to the CFrameWnd and it works fine. Any ideas how I 
can get around this? 

Thanks, Neil
0
NeilB (111)
5/13/2005 9:15:20 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
597 Views

Similar Articles

[PageSpeed] 32

On Fri, 13 May 2005 14:15:20 -0700, Neil B wrote:

> I'm developing an application in C++ using VS.net. I need a browser to return 
> a folder that the user selects. SHBrowseForFolder seems to do the trick in 
> most instances. I have one place that it fails. During the 
> CWinApp::InitInstance() method the m_hWnd of the main window's parent frame 
> window (GetMainWindow()->GetParentFrame()->m_hWnd;) is not setup yet. The 
> BrowseInfo::hwndOwner requires it. When I create a CDialog at this point it 
> only requires a pointer to the CFrameWnd and it works fine. Any ideas how I 
> can get around this? 

Just use NULL for the HWND. That's what ends up happening in the CDialog
case as well, because the CFrameWnd isn't bound to an HWND at that time.
Don't pass the desktop window handle; to understand why, see:

What's so special about the desktop window?
http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx

-- 
Doug Harrison
Microsoft MVP - Visual C++
0
dsh (2498)
5/13/2005 9:33:06 PM
Doug,

Thanks, That worked great.

Do you known how to specify a folder in the list as the inital one selected. 
In some instances I have a preferred default and would like the user to be 
able to just click OK if they have no other preference?
 
Neil

"Doug Harrison [MVP]" wrote:

> On Fri, 13 May 2005 14:15:20 -0700, Neil B wrote:
> 
> > I'm developing an application in C++ using VS.net. I need a browser to return 
> > a folder that the user selects. SHBrowseForFolder seems to do the trick in 
> > most instances. I have one place that it fails. During the 
> > CWinApp::InitInstance() method the m_hWnd of the main window's parent frame 
> > window (GetMainWindow()->GetParentFrame()->m_hWnd;) is not setup yet. The 
> > BrowseInfo::hwndOwner requires it. When I create a CDialog at this point it 
> > only requires a pointer to the CFrameWnd and it works fine. Any ideas how I 
> > can get around this? 
> 
> Just use NULL for the HWND. That's what ends up happening in the CDialog
> case as well, because the CFrameWnd isn't bound to an HWND at that time.
> Don't pass the desktop window handle; to understand why, see:
> 
> What's so special about the desktop window?
> http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx
> 
> -- 
> Doug Harrison
> Microsoft MVP - Visual C++
> 
0
NeilB (111)
5/14/2005 12:04:02 PM
you can use a callback function to adjust it when the initialization is 
done.
"Neil B" <NeilB@discussions.microsoft.com> д����Ϣ����:A978E522-681C-4D4F-805B-A3534AC46A81@microsoft.com...
> Doug,
>
> Thanks, That worked great.
>
> Do you known how to specify a folder in the list as the inital one 
> selected.
> In some instances I have a preferred default and would like the user to be
> able to just click OK if they have no other preference?
>
> Neil
>
> "Doug Harrison [MVP]" wrote:
>
>> On Fri, 13 May 2005 14:15:20 -0700, Neil B wrote:
>>
>> > I'm developing an application in C++ using VS.net. I need a browser to 
>> > return
>> > a folder that the user selects. SHBrowseForFolder seems to do the trick 
>> > in
>> > most instances. I have one place that it fails. During the
>> > CWinApp::InitInstance() method the m_hWnd of the main window's parent 
>> > frame
>> > window (GetMainWindow()->GetParentFrame()->m_hWnd;) is not setup yet. 
>> > The
>> > BrowseInfo::hwndOwner requires it. When I create a CDialog at this 
>> > point it
>> > only requires a pointer to the CFrameWnd and it works fine. Any ideas 
>> > how I
>> > can get around this?
>>
>> Just use NULL for the HWND. That's what ends up happening in the CDialog
>> case as well, because the CFrameWnd isn't bound to an HWND at that time.
>> Don't pass the desktop window handle; to understand why, see:
>>
>> What's so special about the desktop window?
>> http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx
>>
>> -- 
>> Doug Harrison
>> Microsoft MVP - Visual C++
>> 


0
sheng_jiang (305)
5/14/2005 1:12:37 PM
On Sat, 14 May 2005 05:04:02 -0700, Neil B wrote:

> Doug,
> 
> Thanks, That worked great.
> 
> Do you known how to specify a folder in the list as the inital one selected. 
> In some instances I have a preferred default and would like the user to be 
> able to just click OK if they have no other preference?

See:

How To Browse for Folders from the Current Directory
http://support.microsoft.com/kb/q179378/
0
dsh (2498)
5/14/2005 4:52:21 PM
Thanks again,
That worked well. 

Had two minor problems implementing it thought. 
First, I needed to convert a CString variable to a TCHAR pointer, so I could 
pass the folder name back in the SendMessage, but couldn't find any easy way 
to do that. Normally I'd use LPCSTR(?) but that doesn't work with TCHAR. Any 
ideas?

Second, the call back function generated a compiler error where I assigned 
it's pointer to the BROWSEINFO.plfn variable. When I took the call back 
method out of the CWinApp derived class and make it a function not included 
in any class it worked. Is there a special requirement for call back 
functions not being in the scope of classes?

You've been a great help, Thanks again.
"Doug Harrison [MVP]" wrote:

> On Sat, 14 May 2005 05:04:02 -0700, Neil B wrote:
> 
> > Doug,
> > 
> > Thanks, That worked great.
> > 
> > Do you known how to specify a folder in the list as the inital one selected. 
> > In some instances I have a preferred default and would like the user to be 
> > able to just click OK if they have no other preference?
> 
> See:
> 
> How To Browse for Folders from the Current Directory
> http://support.microsoft.com/kb/q179378/
> 
0
NeilB (111)
5/16/2005 9:11:09 PM
On Mon, 16 May 2005 14:11:09 -0700, Neil B wrote:

> Thanks again,
> That worked well. 
> 
> Had two minor problems implementing it thought. 
> First, I needed to convert a CString variable to a TCHAR pointer, so I could 
> pass the folder name back in the SendMessage, but couldn't find any easy way 
> to do that. Normally I'd use LPCSTR(?) but that doesn't work with TCHAR. Any 
> ideas?

As documented, the pszDisplayName member is expected to point to a buffer
MAX_PATH characters long, so you can either set it to a local array or play
with CString's GetBuffer/ReleaseBuffer.

> Second, the call back function generated a compiler error where I assigned 
> it's pointer to the BROWSEINFO.plfn variable. When I took the call back 
> method out of the CWinApp derived class and make it a function not included 
> in any class it worked. Is there a special requirement for call back 
> functions not being in the scope of classes?

You need to pass it the address of a static member function or non-member
function. Non-static member functions all have a hidden parameter
representing the object's "this" pointer and don't work where ordinary
function pointers are required.
0
dsh (2498)
5/16/2005 10:54:55 PM
Reply:

Similar Artilces:

Q: Hard disk with windows
Hi Can anybody tell me how to get the drive letter of the hard disk which has windows installed e.g. if windows is in c:\Windows, then "c:\" is returned. David "David Jones" <dave@ymchwil.NODAMNSPAM.com> wrote in message news:3f683845$0$270$cc9e4d1f@news.dial.pipex.com... > Hi > > Can anybody tell me how to get the drive letter of the hard disk which has > windows installed e.g. if windows is in c:\Windows, then "c:\" is returned. check out GetWindowsDirectory the rest should be obvious ;-) crimson13 Many thanks Crimson. It was :) &quo...

Display Screen 1/2 Grid; 1/2 VBE (or at least Code Window)
Is there a way (button, command, etc) to be able to view (quickly, and side by side) a my worksheet (only 1 workbook is open say) and my code window? If you just want to look at macros do a cltr+' (key to left of 1). John North Yorkshire UK "Jim May" <jmay@cox.net> wrote in message news:Fqb7d.10064$0j.2648@lakeread07... > Is there a way (button, command, etc) to be able to view (quickly, and > side > by side) > a my worksheet (only 1 workbook is open say) and my code window? > > Jim With Excel workbook open to the sheet of your choice and VBE o...

Filter Combo Box in subform by data in parent form
I have a question similar to this one: http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.access&tid=7e76737a-8ab0-44df-87b4-ff519f51e212&cat=en-us-office-access&lang=en&cr=US&sloc=en-us&m=1&p=1 I have followed the code and it works for the first item I select in the parent table, but not when I try to change to the second item. Forms and fields are: frmTotalDetails autOperatorID sfrmPODInfoSearch autOperatorID autPOD_ID uses table tblPODInfo I need to filter the autPOD_ID in the subform by which operator is selected in...

CFileDialog Look and Feel in Windows OS
I noticed that my application does not adapt the look and feel of CFileDialogs of WinXP/WinVista. During runtime, the icons, combox boxes, button and other controls still looks like the ones in Win2K. I compiled the application in Visual Studio 2005. What can be my problem? Your help will be very much appreciated. Thank you. Take a look at this: http://www.codeproject.com/w2k/xptheme.asp Tom "beta_tester08" <beta_tester08@discussions.microsoft.com> wrote in message news:BFB28EB8-A0BA-4BEC-8285-03C1FAA48FD4@microsoft.com... >I noticed that my application does not ad...

Upgraded from Vista to Windows 7 now Outlook 2007 won't run
Everything else seems to be running fine, but i am unable to run Outlook at all. Once i run the program it hangs in a 'not responding' stage and i have to kill it with task manager. HELP Did you try creating a new profile for Outlook to use? http://www.howto-outlook.com/faq/newprofile.htm In addition, have you checked your event viewer for any details regarding Microsoft Office? Do other Office applications open and run as expected? Have you tried opening Outlook in safe mode? Start > Run > outlook.exe /safe (note the space between outlook.exe and /safe) ...

SHBrowseForFolder
I want to set the pidlRoot member of the BROWSEINFO structure to a default location. How do I get a PIDL from a path represented by a text string like this: _T("C:\Program Files")? Thanks I'm not certain about the pidl for an arbitrarily named folder, but if your real interest is the "Program Files" folder, then you shouldn't use a text string anyway, since the text is user-selectable and in fact changes based on language locales. For "Program Files" and other special folders, you can get the pidl using the SHGetFolderLocation function, passing in a CS...

starup/popup window
How do disable the Money window that automatically pops up when I start/power on my computer? ...

SHBrowseForFolder Subclassing.
I would like to change the name of the "cancel" button. Is that possible with Subclassing, Superclassing, etc.? ....Bruce Maybe this article can help you: http://www.codeproject.com/dialog/browse_for_folder_dialog.asp -- Mav Rossi "Bruce Arnold" <b_a_r_n_o_l_d@b_l_a_s_t.n_e_t> ha scritto nel messaggio news:cka5tv4rf6mq086b1nf6t6gom5rgds0a33@4ax.com... > I would like to change the name of the "cancel" button. Is that > possible with Subclassing, Superclassing, etc.? > ...Bruce > > And this too: http://www.codeproject.com/dialog/browse...

Diagnosing Windows Installer 3.1 hang
We are encountering an issue regarding the usage of Windows Installer. Our system is Windows XP SP3 with updates applied. The version of Windows Installer is 3.01.4002.5512. We have an automated installer that processes msi files. The msis are invoked via the command line via msiexec. There is a random issue where msiexec is not exiting and is thus causing our installation processing application to hang waiting for it to return. Our application is creating an instance of msiexec via command line usage. Using ProcessExplorer to do some diagnosis, there are also two additi...

Reorder with parent/child items
I have some items I order by the case, but sell per each. I have these set up as parent and child items and selling works great. The problem comes when ordering. I would like to order a new case when I have about 12 items left, but I can't figure out a way to do that. Is there a feature I'm missing that says when child item reaches a quantity of 12 to order a parent item? The only other thing I can come up with is when the parent item reaches 0 to order another, but that's a LOT more than I need or can keep on my shelves. As you're figuring out Parent/Chi...

Database Properties Window won't open
I've got Visio 2003 Professional. I can't get the Database properties window to open. I've already used it on this machine but since shutting down last night and turning it back on again this morning I can't get the database properties window to open. I double click on the tables in my ERD... nothing. I right mouse click on a table and select "Database Properties..." ... nothing. What's going on? Thanks. Be careful if you close the Database properties window you can have it again. There is no command to reopen it (certainly a bug). But be glad i have a...

Windows Vista
I'm hoping someone can answer this question for me. I just saw a screen capture of what appears to be either Vista's Windows Explorer or Search Screen. Near the top of the 'screen' it says: Show Only: 'All' 'E-Mail' 'Document' 'Picture' 'Music' 'Other' What I want to know is how this affects e-mail. I currently use Outlook 2003 for e-mail and the PST file is password protected since more then one person uses the computer. As a result I obviously don't want my e-mail searched and displayed to anyone who just clicks on the &#...

Problems with files attaches in windows mail
Can´t open files (xls, doc, etc etc) in windows mail. I´m windows Vista Home Premium. Please help. Thank you You must have either Microsoft Office or the free OpenOffice.org installed. "Deidos" <Deidos@discussions.microsoft.com> wrote in message news:4A8CD0F1-8858-41C4-85F5-2985B4F29571@microsoft.com... > Can´t open files (xls, doc, etc etc) in windows mail. I´m windows Vista > Home > Premium. Please help. > Thank you I have IE8 and Microsoft Office 2002 "Charles W Davis" wrote: > You must have either Microsof...

Windows Update at Shutdown
Running Win XP Pro and IE8. For about a week or so, when I shutdown, I see the option of clicking to obtain a Windows update, or to shutdown with out the update. I have been clicking on the "update" part and I see the update as being installed and then I do shut down. But the next time I want to shutdown, I get the same option screen again. I can't get to the "no-option" screen that I usually see. Thanks Roger -- Roger [Crosspost to Windows Update] And the update's (or updates') KB number(s) is/are...? WinXP SP2 or SP3? Check y...

Something like "ping" for windows messages.
Hi, I'm pretty new to Windows messaging. I want to measure how responsive my application is to messages. I thought about doing a SetTimer(1000) and measuring how near to a 1 second interval the WM_TIMER message is processed. Then average it out over 10 messages and log it. Then I thought there might already be a tool that runs as an external process and sends some standard message and measures how quick a response is recieved. The equivalent of "ping" in network terms. Is there such a thing? Otherwise, I'll write a little app to send a message to my application. Bette...

Run Time error 2467 when trying to add new record from a parent fo
Hi all I am trying to add a new record from the a parent form to child form, but when I click the button in get the following "expression to you entered refers to an object that is closed or doesn't exist" here is my code Private Sub CreateNewIssue_Click() With Me!mycollection (childford) .SourceObject = "index" (parent form) .SetFocus .Form!mycollection.SetFocus End With DoCmd.GoToRecord , , acNewRec End Sub Please help Thanks Hi, Is there any particular reason you want to use code instead of an append query? Here is an exampl...

Add Windows 7 drivers to the existing printer
Hi, I have SBS 2003 with 2 installed network printers. One of them is most common used and first Windows 7 client on the network cannot install that printer localy (error 0x00000709). How can I add windows 7 drivers to existing printer, without removing it from the server? Thanks "Marcus" <marcus@there-is-no.mail> wrote in message news:exP0610yKHA.1236@TK2MSFTNGP06.phx.gbl... > I have SBS 2003 with 2 installed network printers. One of them is most > common used and first Windows 7 client on the network cannot install that > printer localy (...

VBA in IE window
Hi Im accessing a spreadsheet via a link I have put in a web page. The spreadsheet opens up in an IE window. I am wanting to stop the "save changes" dialog box popping up when I close the window, I cant do this using the usual vba method because it doesnt apply to IE. Would like to exit using an "exit" command button, Any idea how to close the active IE window using VBA? Am also wanting to open it in full screen (compensate for the lack of a full screen command for "taget_blank" in HTML) Any suggestions gratefully received. Try something like t...

FLAC and Windows Media Player 12
Is there any way to play FLAC files with Windows Media Player 12? A hefty percentage of my music library is FLAC. If WMP 12 doesn't support FLAC, it's pretty useless to me. Thanks! Lloyd I ony have WMP 11, so not certain it would work for WMP 12 but try the Ogg Vorbis directshow filter (free) http://www.free-codecs.com/download/Filters_for_Ogg_Vorbis_Speex_Theora_and_FLAC.htm There are othe Flac decoders on that site (use their search box) "L Goldfine" <L Goldfine@discussions.microsoft.com> wrote in message news:72D955F5-D5CB-4E45-B8D7-09262DD...

Windows
it use to be when i opened an excel doc it would open a tab on th bottom of my toolbar. and for every doc opened it would open a new tab well now (not sure how) every doc opens in one tab and i have to go an select each book from the window menu. this is really frusteratin because i work in many excel docs at once and i alt tab all day long. am sure this is an easy fix but i cant seem to figure it out...any hel would be great! Thank you! -- Message posted from http://www.ExcelForum.com Tools>Options...>View Check 'Windows in taskbar' -- HTH Nick Hodge Microsoft MVP - Excel...

Remote Desktop Client 7.0 for Windows Server 2003
The latest Remote Desktop Client was released only for XP and Vista, but I'm using it on Server 2003 with no issues (I've extracted and copied files manually, as update.inf and catalog doesn't match operating system). Is possible to make a installer compatible with Windows 2003? Description: http://support.microsoft.com/kb/969084/en-us Update: http://www.microsoft.com/downloads/details.aspx?FamilyId=72158b4e-b527-45e4-af24-d02938a95683&displaylang=en Thanks! :) Hi Tyler, I think 7.x version is only for Win7/Vista/2008 systems. you can use the RDP c...

SHBrowseForFolder question
Ok, I managed to get SHBrowseForFolder to work and it pops up its dialog box, but I would like to be able to use the info in a drop down combobox integrated into my dialog form. Is there a way to do this. What I have is a combobox that I want to show and select the path in, then a list box to display the files, and another combobox to select which drive. I have a specific reason to do it this way and I was wondering if I can use some of the info from the SHBrowseForFolder to do this. It seems like I should be able to, but I have not been able to find any helpful information on just how...

Windows Server 2008 CD ISOs
I have a server with a CD Drive (not a DVD Drive). I only see a DVD ISO as an option from the MSDN downloads. Where can I find an ISO download that's compatible with a CD drive? Thanks. Patrick Markiewicz wrote: > I have a server with a CD Drive (not a DVD Drive). I only see a DVD ISO as > an option from the MSDN downloads. Where can I find an ISO download that's > compatible with a CD drive? > > Thanks. Why bother wasting an optical disc on an .iso file? Just get a CD/DVD emulator and load the .iso file into one of the emulated CD/DVD drives....

Determining public folder server from Windows Outlook
In short, is there a way to determine the name of the public folder server from Windows Outlook? The main Exchange mail server is easy, but what about the public folder server? Up until a few days ago, my Entourage scheduling functions worked okay because long ago, someone in IT told me the name of the public folder server. But the company changed all of their servers -- it was hard enough finding out the Exchange Mail server, and no one seems to know the public folder server name (my old contact left the company). LDAP servers were not changed. I have Outlook 2002 and also 2000 for Window...

Windows Update on Vista is Wrong
I have Office 2003 on my Vista Home Premium. Yet Windows Update wants to install SP1 for Office 2007. Won't that mess up my office apps? -- Don Gollahon Did you install the Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats? If yes, this is why you are being offered SP1. "Don Gollahon" <dlgllhn@nospam.gmail.com> wrote in message news:xn0fn9cipstk9s000@news.microsoft.com... >I have Office 2003 on my Vista Home Premium. Yet Windows Update wants > to install SP1 for Office 2007. Won't that mess up my office apps? > &...