首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

已关联了特定的文件类型,但双击后只启动程序却不打开文件,该如何解决

2012-03-28 
已关联了特定的文件类型,但双击后只启动程序却不打开文件在程序中,已经将特有的文件格式与程序关联了.双击

已关联了特定的文件类型,但双击后只启动程序却不打开文件
在程序中,已经将特有的文件格式与程序关联了.
双击文件时,会启动此程序,但却不能打开文件.

我试图得到文件的路径和名称
在App的InitInstance中用下面的方法

       
    CCommandLineInfo       cmdInfo;      
    ParseCommandLine(cmdInfo);      
    m_sFileName       =       cmdInfo.m_strFileName; //文件路径      

但是m_sFileName却一直是空的.
请教各位大人..

[解决办法]
用这个看看吧
Corresponds to the lpCmdLine parameter passed by Windows to WinMain.
LPTSTR m_lpCmdLine;
Remarks
Points to a null-terminated string that specifies the command line for the application. Use m_lpCmdLine to access any command-line arguments the user entered when the application was started. m_lpCmdLine is a public variable of type LPTSTR.
Example
BOOL CMyApp::InitInstance()
{
// ...

if (m_lpCmdLine[0] == _T( '\0 '))
{
// Create a new (empty) document.
OnFileNew();
}
else
{
// Open a file passed as the first command line parameter.
OpenDocumentFile(m_lpCmdLine);
}

// ...
}

[解决办法]
那你什么也不用做就能支持了阿。
去掉这句 m_sFileName = cmdInfo.m_strFileName; //文件路径

//Enable drag/drop open
m_pMainWnd-> DragAcceptFiles();
//Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);

// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand=CCommandLineInfo::FileOpen;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
ProcessShellCommand(cmdInfo);

热点排行