CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 1999
    Posts
    11

    How to Change the button caption of CFileDialog?



    Hi,


    I am using CFileDialog for my application, as a prompt to the user to select a

    file to be overwritten. The problem is, the button has a caption "Open". how

    do i change it to "Overwrite"? Also, how do i change the title of the dialog box?


    Raphael

  2. #2
    Join Date
    Mar 1999
    Posts
    3

    Re: How to Change the button caption of CFileDialog?



    Click the properties for the button


    In the caption window type the name you desire for the button


    The same applies for your app

  3. #3
    Join Date
    Apr 1999
    Posts
    11

    But where do I access the properties for the button?



    Hi,

    Well, I am not actually deriving a class from CFileDialog. I just use

    an object of CFileDialog and then using it.

    static char BASED_CODE szFilter[] = "Text Files (*.txt)|*.txt|Word Documents (*.doc)|*.doc|Image Files

    (*.jpg;*.bmp;*.gif)|*.jpg; *.bmp;*.gif|All Files (*.*)|*.*||";

    CFileDialog myDlg (TRUE, "*.txt", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);

    myDlg.m_ofn.lpstrTitle ="Overwrite a File";

    This much I know how to do, that is to replace the title of the dialog box.

    and then to display the dialog box, i just use

    myDlg.DoModal();

    But how do i change the caption of the OK button? the m_ofn structure does not

    have any variable for defining the caption of the OK button


    Raphael





  4. #4
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: But where do I access the properties for the button?





    override OnInitDialog and after CFileDialog has done its stuff,

    get a handle to IDOK and change the text on the returned CWnd


    Sally

  5. #5
    Join Date
    Mar 1999
    Posts
    6

    Re: But where do I access the properties for the button?



    Hi,

    Before you call DoModal() of the file open dialog box set timer like this.

    SetTimer(0,5,NULL);

    Add a command handler for WM_TIMER message in your class.

    In the handler do this

    CWnd* pWndOfTitle = CWnd::FindWindow(NULL, "Overwrite"

    if(pWndOfTitle ){

    CWnd* pWndOfOpen = pWndOfTitle ->GetDlgItem(IDOK);

    pWndOfOpen->SetWindowText("Overwrite"

    }

    The result was as expected. But there was a flicker in every 5 ms. Bcoz

    windows send WM_TIMER message in every 5ms and the handler gets executed.

    I couldn't remove that flicker. If you know the solution please let me know.


    Hope this helps u,

    Reshmi

  6. #6
    Join Date
    Apr 1999
    Posts
    11

    Re: But where do I access the properties for the button?



    Hi,


    Sorry but how do we override OnInitDialog? Can we do that without deriving

    a class from CFileDialog?

  7. #7
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: But where do I access the properties for the button?



    no


    Sally

  8. #8
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: But where do I access the properties for the button?



    it is better to derive CMyFileDialog from CFileDialog, override OnInitDialog

    and SET the text there


    Sally

  9. #9
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: How to Change the button caption of CFileDialog?



    To change the OK button's text, derive a class from CFileDialog and use the undocumented function SetControlText().

    To set an initial directory, set the OPENFILENAME structure member lpstrInitialDir to the directory.

    CFileDialog dlg(...);

    dlg.m_ofn.lpstrInitialDir = "x:\\folder";

    dlg.DoModal();

    If you look on my web site, at my MFC Example Projects for example 11, the CFileDialog class is set up to allow you to

    change the button's text.

    To use it:

    CXDlg2 dlg(TRUE, _T("*&quot, NULL,

    OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,

    _T("(Your File Type) Files (*.*)|*.*|All Files (*.*)|*.*||&quot);

    dlg.m_ofn.lpstrInitialDir = "x:\\folder";

    dlg.SetOKButtonText("OverWrite"

    dlg.DoModal();


    Rail


    Recording Engineer/Software Developer

    Rail Jon Rogut Software


    Rail Jon Rogut Software

  10. #10
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: How to Change the button caption of CFileDialog?



    Oops... sorry, I answered how to set the initial folder, when you were asking how to set the dialog box title, in the OPENFILENAME structure, set the lpstrTitle value:


    CFileDialog dlg(...)


    dlg.m_ofn.lpstrTitle = "Select a file";


    dlg.DoModal();


    Rail

    Recording Engineer/Software Developer

    Rail Jon Rogut Software


    Rail Jon Rogut Software

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured