Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

Using command line to open the same application but different file

$
0
0
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):
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;
}

Now, the trouble is coming when I want to open a text file, with my application, TextStitch.exe, from command line:

Code:

D:\>d:\tempx\textstitch\debug\textstitch.exe d:\tempx\text1.txt
and I am trying to open the second text file, but with the same instance:
Code:

D:\>d:\tempx\textstitch\debug\textstitch.exe d:\tempx\text2.txt
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:
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;
        }
....
....
}

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.

Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles


Pregnant woman released on bail


Waves Complete v2019.02.14 Incl Emulator-R2R


It’s Kind of a Funny Story 2010 Dual Audio 720p BRRip [Hindi – English] ESubs


CalCen


Serial child killer David Threinen’s reign of terror


Pumped up UDA chief ordered teen to be shot


MCGEE, SAMUEL O., DECEASED, OF...


Alison Moyet - Alf (Deluxe Edition) (2016) flac


Shawn Ogrodnik


WordPress: Reverse Shell



Latest Images