?
Solved

How to modify file name in CFileDialog ?

Posted on 1998-04-17
2
Medium Priority
?
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
piano_boxer earned 400 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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: 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…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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