Exemplo n.º 1
0
/*****************************Private*Routine******************************\
* SetRecentFiles
*
* Writes the most recent files to the registry.
* Purges the oldest file if necessary.
*
\**************************************************************************/
int
SetRecentFiles(
    TCHAR *FileName,    // File name to add
    int iCount,         // Current count of files
    int iMenuPosition   // Menu position of start of MRU list
    )
{
    TCHAR   FullPathFileName[MAX_PATH];
    TCHAR   *lpFile=0;
    TCHAR   szKey[32];
    int     iCountNew, i;

    //
    // Check for duplicates - we don't allow them
    //
    for(i = 0; i < iCount; i++)
    {
        if(0 == lstrcmpi(FileName, aRecentFiles[i]))
        {
            return iCount;
        }
    }

    //
    // Throw away the oldest entry
    //
    MoveMemory(&aRecentFiles[1], &aRecentFiles[0],
               sizeof(aRecentFiles) - sizeof(aRecentFiles[1]));

    //
    // Copy in the full path of the new file.
    //
    GetFullPathName(FileName, MAX_PATH, FullPathFileName, &lpFile);
    StringCchCopy(aRecentFiles[0], NUMELMS(aRecentFiles[0]), FullPathFileName);

    //
    // Update the count of files, saturate to MAX_RECENT_FILES.
    //
    iCountNew = min(iCount + 1, MAX_RECENT_FILES);

    //
    // Clear the old stuff and the write out the recent files to disk
    //
    for(i = 1; i <= iCountNew; i++)
    {
        (void)StringCchPrintf(szKey, NUMELMS(szKey),TEXT("File %d\0"), i);
        ProfileStringOut(szKey, aRecentFiles[i - 1]);
    }

    //
    // Update the file menu
    //
    GetRecentFiles(iCount, iMenuPosition);

    return iCountNew;  // the updated count of files.
}
Exemplo n.º 2
0
void RecentFilesManager::SetFileToRecent(const DAVA::String& file)
{
    DAVA::Vector<String> vectorToSave = GetRecentFiles();
    DAVA::FilePath filePath(file);
    DAVA::String stringToInsert = filePath.GetAbsolutePathname();
    //check present set to avoid duplicates
    vectorToSave.erase(std::remove(vectorToSave.begin(), vectorToSave.end(), stringToInsert), vectorToSave.end());
    
    vectorToSave.insert(vectorToSave.begin(), stringToInsert);

    uint32 recentFilesMaxCount = SettingsManager::GetValue(Settings::General_RecentFilesCount).AsInt32();

    DAVA::uint32 size = vectorToSave.size() > recentFilesMaxCount ? recentFilesMaxCount : vectorToSave.size();
    KeyedArchive* archive = new KeyedArchive();
    for (DAVA::uint32 i = 0; i < size; ++i)
    {
        archive->SetString(Format("%d",i), vectorToSave[i]);
    }
    SettingsManager::SetValue(Settings::Internal_RecentFiles, DAVA::VariantType(archive));
    SafeRelease( archive);
}
Exemplo n.º 3
0
/*****************************Private*Routine******************************\
* InitInstance
*
*
* This function is called at initialization time for every instance of
* this application.  This function performs initialization tasks that
* cannot be shared by multiple instances.
*
* In this case, we save the instance handle in a static variable and
* create and display the main program window.
*
\**************************************************************************/
BOOL
InitInstance(
    HINSTANCE hInstance,
    int nCmdShow
    )
{
    HWND    hwnd;
    RECT    rc;
    POINT   pt;

    /*
    ** Save the instance handle in static variable, which will be used in
    ** many subsequence calls from this application to Windows.
    */
    hInst = hInstance;

    if(! LoadWindowPos(&rc))
    {
        rc.left = rc.top = 0;
        rc.bottom = rc.right = 400;
    }

    /*
    ** Create a main window for this application instance.
    */
    hwnd = CreateWindow(szClassName, IdStr(STR_APP_TITLE),
                        WS_THICKFRAME | WS_POPUP | WS_CAPTION  |
                        WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
                        WS_CLIPCHILDREN,
                        rc.left, rc.top,
                        rc.right - rc.left, rc.bottom - rc.top,
                        NULL, NULL, hInstance, NULL);

    /*
    ** If window could not be created, return "failure"
    */
    if(NULL == hwnd)
    {
        return FALSE;
    }

    hwndApp = hwnd;
    nRecentFiles = GetRecentFiles(nRecentFiles, 2);

    pt.x = lMovieOrgX = 0;
    pt.y = lMovieOrgY = 0;

    // if we fail to get the working area (screen-tray), then assume
    // the screen is 640x480
    //
    if(!SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE))
    {
        rc.top = rc.left = 0;
        rc.right = 640;
        rc.bottom = 480;
    }

    if(!PtInRect(&rc, pt))
    {
        lMovieOrgX = lMovieOrgY = 0L;
    }

    /*
    ** Make the window visible; update its client area; and return "success"
    */
    SetPlayButtonsEnableState();
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    return TRUE;
}