CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    R.O.C
    Posts
    33

    Cool Open a file by using DialogBox

    When we push the button of "open file", it always show a window to let us select file. Now I want to open this window by pushing a button in DialogBox. How can I do it?
    I know CWinApp::OnFileOpen() can open file, but I don't know how to do in detail. Please help me !!
    Thanks a lot !!

    programming environment: VC 6.0:

  2. #2
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    Do you want any functionality or something?
    What I usually do is create a button and:

    Code:
    	OPENFILENAME ofn = {0};
    	char szName[MAX_PATH];
    	*szName = 0;
    
    	CString transfile1;
    
    	ofn.lStructSize = sizeof(OPENFILENAME);
    	ofn.hwndOwner = AfxGetApp()->m_pMainWnd->m_hWnd;
    	ofn.lpstrFilter = NULL;
    	ofn.lpstrFilter = "Exe files (*.exe)\0*.exe\0All files (*.*)\0*.*\0";
    	ofn.lpstrCustomFilter = NULL;
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFile = &szName[0];
    	ofn.nMaxFile = MAX_PATH;
    	ofn.lpstrInitialDir = NULL;
    		//m_DefaultDir;
    	ofn.lpstrTitle = "Open Executable File";
    	ofn.lpstrFileTitle = NULL;
    	ofn.lpstrDefExt = "TXT";
    	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_EXPLORER;
    
    	GetOpenFileName(&ofn);
    and then I do whatever (be it execute the file, store the folder path, etc.).
    Last edited by eagle1; February 19th, 2004 at 10:37 PM.

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