Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC command line arguments

MFC command line arguments

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondiscussion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jerry Wang 0
    wrote on last edited by
    #1

    Hi, I have a MFC program that I want to make it to take a path instead of a filename for its calling argument. Something like: AppName c:\docs\SupportFilePath I noticed that the default action for having an argument in MFC program is it goes to Document::OnOpenFile(). Is there a way to prevent onOpenFile be called, but instead, get a hold of this argument in CMainFrame::CMainFrame()? Here's what I've figured so far... Is the following an effecient way of getting a hold of the argument and passing it to CMainFrame?? (Inside CApp::InitInstance() ... // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; What do you think? :)

    J J 2 Replies Last reply
    0
    • J Jerry Wang 0

      Hi, I have a MFC program that I want to make it to take a path instead of a filename for its calling argument. Something like: AppName c:\docs\SupportFilePath I noticed that the default action for having an argument in MFC program is it goes to Document::OnOpenFile(). Is there a way to prevent onOpenFile be called, but instead, get a hold of this argument in CMainFrame::CMainFrame()? Here's what I've figured so far... Is the following an effecient way of getting a hold of the argument and passing it to CMainFrame?? (Inside CApp::InitInstance() ... // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; What do you think? :)

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      I'd say this is fine :) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • J Jerry Wang 0

        Hi, I have a MFC program that I want to make it to take a path instead of a filename for its calling argument. Something like: AppName c:\docs\SupportFilePath I noticed that the default action for having an argument in MFC program is it goes to Document::OnOpenFile(). Is there a way to prevent onOpenFile be called, but instead, get a hold of this argument in CMainFrame::CMainFrame()? Here's what I've figured so far... Is the following an effecient way of getting a hold of the argument and passing it to CMainFrame?? (Inside CApp::InitInstance() ... // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; What do you think? :)

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #3

        Jerry Wang wrote: CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo);    Hmmmm...  I am under the impression that you need to call ParseCommandLine(...) first in order to populate the fields you are manipulating (like cmdInfo::m_strFileName)?  Then you can change the m_nShellCommand value to prevent the app from opening the file...?    Peace! -=- James.

        J 1 Reply Last reply
        0
        • J James R Twine

          Jerry Wang wrote: CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo);    Hmmmm...  I am under the impression that you need to call ParseCommandLine(...) first in order to populate the fields you are manipulating (like cmdInfo::m_strFileName)?  Then you can change the m_nShellCommand value to prevent the app from opening the file...?    Peace! -=- James.

          J Offline
          J Offline
          Jerry Wang 0
          wrote on last edited by
          #4

          I think you are right. I wasn't too sure what ParseCommandLine did. Thank you both! :-D

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups