Click here to Skip to main content
13,867,447 members
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 24 Aug 2007
Licenced CPOL

The Ultimate Toolbox Resource File

, 25 Aug 2007
Rate this:
Please Sign up or sign in to vote.
A class for enumerating and parsing file based resources from the Ultimate Toolbox

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\utility\resfile directory of the sample projects download.


The COXResourceFile provides a resource with a CSharedFile (thus CFile) interface. One can read or write any type (e.g. a GIF-picture, a movie etc. as in RT_RCDATA) of resources directly through the familiar methods Read(), Write(), Seek(), Flush(), Close(), etc.. The resource will be loaded into memory and wrapped by a COXResourceFile. All changes will be applied to the resource in memory and will be committed when the file is flushed.

The COXResourceLibrary wraps the Win32 API's resource functions (together with COXResourceFile). One object of the COXResourceLibrary corresponds to a library file (an executable: .DLL or .EXE file), whereas one object of the COXResourceFile corresponds to one resource in a library.


  • Direct access of a resource's binary data through the familiar CFile interface.
  • Easy multiple resources update.
  • Minimum code to be written when implementing drag/drop/copy/paste of resources.
  • Easy to enumerate resources in a library file.
  • Flexible parameter data types when specifying the type or name of a resource.


The samples\utility\resfile sample contains a document class with a COXResourceLibrary m_ResLib member (include OXResourceLibrary.h) and public arrays that will contain the types, names, and languages enumerated:

class CResLibDoc : public CDocument
protected: // create from serialization only


// Attributes

    COXResourceLibrary m_ResLib;
    CStringArray m_sTypes;
    CStringArray m_sNames;
    CWordArray   m_nLangs;

In the OnOpenDocument handler, the selected file is opened and its resources are enumerated:

BOOL CResLibDoc::OnOpenDocument(LPCTSTR lpszPathName) 
    if (!CDocument::OnOpenDocument(lpszPathName))
        return FALSE;
    if (!m_ResLib.Open(lpszPathName))
        AfxMessageBox(_T("Cannot open the specified file."));
        return FALSE;

    if (!m_ResLib.EnumResources(&m_sTypes, &m_sNames, &m_nLangs))
        AfxMessageBox(_T("Cannot enumerate resources."));
        return FALSE;
    return TRUE;

Finally, in the views OnInitialUpdate, the arrays are iterated through in order to populate a tree control:

void CResLibView::OnInitialUpdate()
    CTreeCtrl& rTree = GetTreeCtrl();
    rTree.SetImageList(&m_ilFolder, TVSIL_NORMAL); 

    m_nClipFormat = ((CResFileApp*)AfxGetApp())->m_nClipFormat;
    m_pDoc = GetDocument();
    m_pResLib = &m_pDoc->m_ResLib;

    // calling IsModifiable() once instead of repeatedly checking it

    m_bModifiable = m_pResLib->IsModifiable();

    if (m_pResLib == NULL)

    m_hRootItem = rTree.InsertItem(m_pResLib->GetFileName() + 
        (m_bModifiable ? _T("") : _T(" <<<read />>>")));
    rTree.SetItemData(m_hRootItem, TVI_DATA_FOLDER);

    CString sType, sName, sPrevType;
    HTREEITEM hTypeItem = NULL;
    int iImage = 0;
    for (int i = 0; i < m_pDoc->m_sTypes.GetSize(); i++)            
    // iterate through the resource types enumerated in the document

        sType = m_pDoc->m_sTypes[i];
        sName = m_pDoc->m_sNames[i];
        if (sType != sPrevType)
            sPrevType = sType;
            GetTypeOutput(sType, iImage);

            hTypeItem = rTree.InsertItem(sType, m_hRootItem);
            rTree.SetItemData(hTypeItem, TVI_DATA_FOLDER);

        GetNameOutput(sName, m_pDoc->m_nLangs[i]);

        HTREEITEM hResItem = rTree.InsertItem(sName, iImage, iImage, 
        rTree.SetItemData(hResItem, (DWORD)i);

    rTree.Expand(m_hRootItem, TVE_EXPAND);

An extended overview and complete class references for these classes is available in the compiled HTML help documentation.


Initial CodeProject release August 2007.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

458 members

You may also be interested in...

Comments and Discussions

Questionchange the text of Static ctrl on a dialog?? [modified] Pin
canercaner6-Dec-07 4:26
membercanercaner6-Dec-07 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190214.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid