What is the function of getopenfilename? It is better to have an example

Source: Internet
Author: User
Question:What is the function of getopenfilename? It is better to have an example.

  • Original Discussion link:Http://community.csdn.net/expert/topicview1.asp? Id = 723371
  • Forum:Basic ClassAudit Team:VC/MFC
  • Questioner:MuhuairuReleased:
  • Thanks:Acptvc
  • Keywords:VC/mfc function base class HTTP reference file name hwnd null handle getopenfilename openfilename ofn
  • Answer:

    What is the function of getopenfilename? It is better to have an example.
    ------------------------------------------------------------- The getopenfilename function is used to create an open dialog box, allowing you to specify the drive, directory, and one or more file names to open. Its prototype is as follows:
    Bool getopenfilename (
    Lpopenfilename lpofn // initialization data
    );

    The parameter lpofn is a pointer to the openfilename structure, which contains the information required to initialize the "open" dialog box. When this function returns, this structure contains the user's selected information.

    You can refer to the following code:

    Openfilename ofn; // Common Dialog Box Structure
    Char szfile [260]; // buffer for file name
    Hwnd; // owner window
    Handle Hf; // file handle

    // Initialize openfilename
    Zeromemory (& ofn, sizeof (openfilename ));
    Ofn. lstructsize = sizeof (openfilename );
    Ofn. hwndowner = hwnd;
    Ofn. lpstrfile = szfile;
    Ofn. nmaxfile = sizeof (szfile );
    Ofn. lpstrfilter = "All/0 *. */0 text/0 *. txt/0 ";
    Ofn. nfilterindex = 1;
    Ofn. lpstrfiletitle = NULL;
    Ofn. nmaxfiletitle = 0;
    Ofn. lpstrinitialdir = NULL;
    Ofn. Flags = ofn_pathmustexist | ofn_filemustexist;

    // Display the open dialog box.

    If (getopenfilename (& ofn) = true)
    HF = createfile (ofn. lpstrfile, generic_read,
    0, (lpsecurity_attributes) null,
    Open_existing, file_attribute_normal,
    (Handle) null );

    For more information, see:
    Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/shellcc/platform/commctls/winui/commdlg_3cbp.asp

    -Microsoft Global Technical Center VC Technical Support

    This post is provided as "the status quo" without any guarantee and does not grant any rights. For more information, see the terms of use.
    Http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp ).

    To create a better discussion environment for you, please join our user satisfaction survey
    (Http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp? Key = (S, 49854782 )).

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.