Giter VIP home page Giter VIP logo

Comments (4)

Duanyll avatar Duanyll commented on September 4, 2024

I think you can ask the user for filename in console not in your code itself!

from random.

Duanyll avatar Duanyll commented on September 4, 2024

But I can open a open file dialog in just three lines! Haha!

from random.

Duanyll avatar Duanyll commented on September 4, 2024

You can use this

#include "windows.h"

OPENFILENAME ofn;
static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH];
static TCHAR szFilter[] = TEXT("PDF Files (.pdf)\0.pdf\0")
TEXT("All Files (.)\0*.*\0\0");
ZeroMemory(&ofn, sizeof(ofn));
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFileTitle = szTitleName;
ofn.nMaxFileTitle = MAX_PATH;
ofn.lpstrFilter = szFilter;
ofn.lpstrDefExt = TEXT("pdf");
ofn.lpstrTitle = NULL;
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
ofn.lStructSize = sizeof(OPENFILENAME); // No OFN_ENABLEHOOK
ofn.hwndOwner = m_hWnd;
if (GetOpenFileName(&ofn))
{
MessageBox(szFileName)克雄

首页 » C/C++ » Win32打开文件/保存文件/选择文件夹对话框
Win32打开文件/保存文件/选择文件夹对话框 2
This entry was posted in C/C++ MFC Win32 Windows and tagged C++ MFC VC++ Win32 对话框 on 2016年7月27日 by Next

  1. 效果图

  2. 打开文件
    OPENFILENAME ofn;
    static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH];
    static TCHAR szFilter[] = TEXT("PDF Files (.pdf)\0.pdf\0")
    TEXT("All Files (.)\0*.*\0\0");
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFileTitle = szTitleName;
    ofn.nMaxFileTitle = MAX_PATH;
    ofn.lpstrFilter = szFilter;
    ofn.lpstrDefExt = TEXT("pdf");
    ofn.lpstrTitle = NULL;
    ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
    ofn.lStructSize = sizeof(OPENFILENAME); // No OFN_ENABLEHOOK
    ofn.hwndOwner = m_hWnd;
    if (GetOpenFileName(&ofn))
    {
    freopen(szfilename,"r",stdin);
    //Your code here
    }

I am too lazy to send a pull request

from random.

Duanyll avatar Duanyll commented on September 4, 2024

filter自己改一下

from random.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.