Solved

How to modify file name in CFileDialog ?

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 95
method notes when mouse over in eclipse 5 90
x-bar in Google Sheets 2 93
Capture logon name 13 104
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. …
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 …
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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