[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to modify file name in CFileDialog ?

Posted on 1998-04-17
2
Medium Priority
?
488 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 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