Solved

How to modify file name in CFileDialog ?

Posted on 1998-04-17
2
467 Views
Last Modified: 2013-11-20
I'd like to change the file name in the CFileDialog each time the
file type is changed.  edt1 is the id of the edit box in FILEOPENORD.  Why
doesn't SendDlgItemText(edt1,"filename.ext") work & what  should I do
instead ?

class MyFileDialog : public CFileDialog
{
   public:
    MyFileDialog (BOOL bOpenFileDialog,LPCTSTR lpszDefExt, LPCTSTR
lpszFileName, DWORD dwFlags,LPCTSTR lpszFilter, CWnd* pParentWnd)
    : CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags,
lpszFilter, pParentWnd) {}
    virtual void OnTypeChange();
};

void MyFileDialog::OnTypeChange()
{
       SendDlgItemText(edt1,"filename.ext");
}

// MENU AND CONTROL COMMAND
BOOL SaveAs(CWnd *pWnd)
{
    static char szFilter[] = "Doc Files (*.doc)|*.doc|Text Files
(*.txt)|*.txt|All Files (*.*)|*.*||";

    MyFileDialog dlg(TRUE,"txt","*.txt",OFN_HIDEREADONLY |
OFN_CREATEPROMPT | OFN_EXPLORER,szFilter,pWnd);
     
if(dlg.DoModal()==IDOK && dlg.GetPathName()) {
TheApp.PathName=dlg.GetPathName();
    }
    return FALSE;
}


0
Comment
Question by:robg041798
2 Comments
 
LVL 4

Accepted Solution

by:
piano_boxer earned 100 total points
ID: 1300215
This is because the hwnd in CFileDialog is not the same as the 'real' one.

To get a handle for the real dialog do this:

void MyFileDialog::OnTypeChange()
{
    CWnd* pDialogWnd = GetForegroundWindow();
    ASSERT_VALID(pDialogWnd);

    pDialogWnd->SetDlgItemText(edt1,"filename.ext");
}





0
 

Author Comment

by:robg041798
ID: 1300216
Perfect!  Thank you so much.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

19 Experts available now in Live!

Get 1:1 Help Now