Solved

How to modify file name in CFileDialog ?

Posted on 1998-04-17
2
468 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 48
wait notify demo infinite loop 3 94
Detect file exist or not 3 127
Excel file not created as expected 7 46
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

22 Experts available now in Live!

Get 1:1 Help Now