Hi all of you.
I come here with a problem: can I use command line to open the same application, but different file ? How ?
Here is the situation: I have a SDI app, with CView based on CEditView, which can load text files. The particularity is that whether if I open another text file, the second text from second file is appended on the previous text. The application is called "TextStitch".
How have I done that ? Here is the code (simple code):
Now, the trouble is coming when I want to open a text file, with my application, TextStitch.exe, from command line:
and I am trying to open the second text file, but with the same instance:
but no, there is open the second instance of TextStitch.exe, with text2.txt file ...
I know, I can make the application as single instance, something like that:
where g_sMutexName ahs the ID of my app. But here, I didn't have the path of the text file in order to load into my app ...
Can you help me ? Thank you.
I come here with a problem: can I use command line to open the same application, but different file ? How ?
Here is the situation: I have a SDI app, with CView based on CEditView, which can load text files. The particularity is that whether if I open another text file, the second text from second file is appended on the previous text. The application is called "TextStitch".
How have I done that ? Here is the code (simple code):
Code:
BOOL CTextStitchDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
CString sTextPrev, sTextLast;
((CEditView*)m_viewList.GetHead())->GetWindowText(sTextPrev);
if(! CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
((CEditView*)m_viewList.GetHead())->GetWindowText(sTextLast);
((CEditView*)m_viewList.GetHead())->SetWindowText(sTextPrev + _T("\r\n") + sTextLast);
return TRUE;
}
Code:
D:\>d:\tempx\textstitch\debug\textstitch.exe d:\tempx\text1.txt
Code:
D:\>d:\tempx\textstitch\debug\textstitch.exe d:\tempx\text2.txt
I know, I can make the application as single instance, something like that:
Code:
BOOL CTextStitchApp::InitInstance()
{
CWnd* pWnd = CWnd::FindWindow(g_sMutexName, NULL);
if(NULL != pWnd && NULL != pWnd->GetSafeHwnd())
{
// A prevous running instance already created a window with the given class name.
// Bring it to front then return.
pWnd->ShowWindow(SW_SHOWNA);
if(pWnd->IsIconic())
pWnd->ShowWindow(SW_RESTORE);
pWnd->SetForegroundWindow();
return FALSE;
}
....
....
}
Can you help me ? Thank you.