Example #1
0
bool MainApp::OnInit()
{

    UINT openFilesMessage = RegisterWindowMessage("Decoda_OpenFiles");

    // Check to see if another instances is running.

    if (!wxApp::OnInit())
    {
        return false;
    }

    wxImage::AddHandler(new wxXPMHandler);
    wxImage::AddHandler(new wxPNGHandler);

    MainFrame* frame = new MainFrame("Script Debugger", openFilesMessage, wxDefaultPosition, wxSize(1024,768));

    HWND hWndPrev = m_singleInstance.Connect(reinterpret_cast<HWND>(frame->GetHandle()), "Decoda");

    // If we're loading files from the command line (but not a project) file,
    // then don't create a new instance. This happens when the user double clicks
    // in Explorer.
    if (hWndPrev != NULL && m_loadProjectName.IsEmpty() && m_debugExe.IsEmpty() && m_loadFileNames.Count() > 0)
    {

        // Send the command line to the other window.

        wxString fileNames;

        for (unsigned int i = 0; i < m_loadFileNames.Count(); ++i)
        {
            fileNames += m_loadFileNames[i] + ";";
        }

        m_singleInstance.SetCommand(fileNames);
        PostMessage(hWndPrev, openFilesMessage, 0, 0);

        // Show the other window.
        SetForegroundWindow(hWndPrev);
        
        delete frame;
        return false;

    }

    frame->ApplyWindowPlacement();

    // If a project was specified, open it.
    if (!m_loadProjectName.IsEmpty())
    {
        frame->OpenProject(m_loadProjectName);
    }

    // Load any files that were specified on the command line.
    frame->OpenDocuments(m_loadFileNames);

    // Tell the UI to load the last project if we haven't instructed.
    // it to load anything else.

    if (m_loadProjectName.IsEmpty() && m_loadFileNames.IsEmpty())
    {
        frame->AutoOpenLastProject();        
    }

    m_loadProjectName.Clear();
    m_loadFileNames.Clear();

    frame->CheckForUpdate();

    if (!m_debugExe.IsEmpty())
    {
        frame->DebugExe(m_debugExe);
    }

    return true;

}