Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You this really water #1

Closed
Duanyll opened this issue Jun 7, 2018 · 4 comments
Closed

You this really water #1

Duanyll opened this issue Jun 7, 2018 · 4 comments

Comments

@Duanyll
Copy link

Duanyll commented Jun 7, 2018

  1. ui water
  2. Import logic difficult
  3. Anyway it very water
@Duanyll
Copy link
Author

Duanyll commented Jun 7, 2018

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

@Duanyll
Copy link
Author

Duanyll commented Jun 7, 2018

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

@Duanyll
Copy link
Author

Duanyll commented Jun 7, 2018

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

@Duanyll
Copy link
Author

Duanyll commented Jun 7, 2018

filter自己改一下

@Llf0703 Llf0703 closed this as completed Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants