已关联了特定的文件类型,但双击后只启动程序却不打开文件
在程序中,已经将特有的文件格式与程序关联了.
双击文件时,会启动此程序,但却不能打开文件.
我试图得到文件的路径和名称
在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);