Solved

Derived CFileDialog

Posted on 1997-05-19
10
549 Views
Last Modified: 2013-11-19
How can I create a custom Explorer (OFN_EXPLORER) custom File Open dialog with my controls on it ?
I copied the dialog template from the comdlg32.dll and added my controls. I created a new class derived from CFileDialog associated member variables with the newly created controls, in the constructor I once tried adding OFN_ENABLETEMPLATE but no go, and another  time I changed the m_lpTemplateName member of the m_ofn member and still nothing...

Any ideas ?
0
Comment
Question by:dkremer
  • 6
  • 4
10 Comments
 
LVL 2

Expert Comment

by:rajesh032097
ID: 1301634
Can you give the exact steps you followed for subclassing the CFileDialog?
0
 
LVL 2

Accepted Solution

by:
rajesh032097 earned 150 total points
ID: 1301635
Hi,
If the steps you have followed are just as given above, probably you have missed adding the name of the resource template in the resource.h since it doesn't happen automatically.
You can add following line in resource.h to give an id to the file dialog template.
#define IDD_NEWFILEOPEN  150 /// or any unique number
also add following line in your class definition, public section:
enum { IDD = IDD_NEWFILEOPEN };
Hope this solves your problem.
0
 
LVL 1

Author Comment

by:dkremer
ID: 1301636
The ID is already defined in Resource.H as I copied the dialog template in the ComDlg32.DLL using the Visual Studio so when I pasted it it added the ID, and I manually added the IDD=IDD_MY_DIALOG to the derived class, still it doesn't show (I traced until it calls the API function which supposed to open the dialog and nothing appears). It (DoModal) returns with an ID of 2.
Please help !!! ;-)

   Cheers,
      - Dror

0
 
LVL 2

Expert Comment

by:rajesh032097
ID: 1301637
Hi,
I am not able to figure out what is wrong with these details. One thing I suspect is that you are calling the CFileDialog DoModal() from a DLL. This is the problem I was facing in my application since proper resource handle switching needs to be done in DLL ( an extended DLL).
Another check you can do is to see whether the resource ID is unique. But usually this problem ends up with some assertion.
Please give me a more wide picture of how you have implemented the dialog.
0
 
LVL 1

Author Comment

by:dkremer
ID: 1301638
Yeah, that's right, I'm calling DoModal from inside an ActiveX control I'm writing. I'm trying to write a custom file open dialog with a preview "pane" on the side allowing Visual Basic to use it as if they were using the Microsoft Common Dialogs control.
Why doesn't it work with DLLs ?

   Thanks,
      - Dror.

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Expert Comment

by:rajesh032097
ID: 1301639
Hi,
 Then that might be the real problem.
Go to microsoft site knowledge base area and query about resources in extension DLL. Article ID is Q150121 and title is "PRB : MFC loads wrong resources in Extension DLL".
All you have to do is switch the resource handle before calling DoModal() to the handle of your DLL and then after DoModal() reset it.
This worked well in my application. Similar should work in your case as well.
0
 
LVL 1

Author Comment

by:dkremer
ID: 1301640
Hi.
I hope this is really the problem, mind sending me a sample since I'm haveing implementing the information from the KB and the DLLHUSK sample as I can't use DllMain - MFC already supplies a function for OCX controls and don't know where to initialize the AFX_EXTENSION_MODULE variable. I'm not I sure this is the problem, 'cuz, in applications that use extention DLLs this error should occur when a function in the DLL calls AfxGetInstanceHandle() it would return the applications handle and not the extention DLL handle, where as in OCXs each OCX has a COleControlModule (which derives CWinApp) and it "replaces" the application object in a standard application. I use the resources alot in the OCX and never had a problem and had to change it by calling AfxSetResourceHandle(). But hey, I'm willing to try out anything now ;-)
I've read stuff about problems with subclassing Explorer style file dialogs in microsoft.public.vc.mfc and someone said you couldn't replace the template, you can add your own as a child (???) and if you want to do stuff on the already existing controls you have to do it at run-time. He also posted an example but it was too old and was deleted from the server (I tried www.dejanews.com but they don't carry the attachments ;-( ).
Anyway, thanks,
    - Dror

0
 
LVL 2

Expert Comment

by:rajesh032097
ID: 1301641
This is the way I implemented CFileDialog in my application ( an extended DLL)

CMyView::ShowFileDialog()
{
 HINSTANCE hInstOld = AfxGetResourceHandle();
 AfxSetResourceHandle(MyDLL.hModule);
 
 CMyFileDialog dlg(TRUE, lpszDeftext, lpszFileName, dwFlags,  szFilter,this); // with properly initialized parameters
 dlg.DoModal();
 AfxSetResourceHandle(hInstOld);
}

Hope this works in your application as well.
0
 
LVL 1

Author Comment

by:dkremer
ID: 1301642
Hi.
As I said in the previous comment, I can't initialize the AFX_EXTENSION_MODULE in DllMain since MFC has a special DllMain for OCX Dlls. Again, as I said in the previous comment, there shouldn't be any need to use is since OCXs __HAVE__ CWinApp derived as an application object and thus have an hInstance and don't need to use the extra functions required for an extention DLL.

    Thanks,
       - Dror

0
 
LVL 2

Expert Comment

by:rajesh032097
ID: 1301643
I don't know how to solve the problem in OCX since I haven't worked on OCXs. You can check whether the constructor of the CFileDialog is getting proper resource handle by debugging the application.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
repeatEnd java challenge 42 83
repeatSeparator  java  challenge 13 56
Line meaning 9 77
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now