Click here to Skip to main content
15,879,535 members
Articles / Multimedia / DirectX

A DirectX Wrapper

Rate me:
Please Sign up or sign in to vote.
4.69/5 (20 votes)
18 Jul 200333 min read 180.9K   4.3K   66  
A DirectX Wrapper
// CreateTab.cpp : implementation file
//

#include "stdafx.h"
#include "LibUtil.h"
#include "CreateTab.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCreateTab dialog


CCreateTab::CCreateTab(CWnd* pParent /*=NULL*/)
	: CDialog(CCreateTab::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCreateTab)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

    *m_libFileName=0;
    *m_pathName=0;

}


void CCreateTab::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCreateTab)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCreateTab, CDialog)
	//{{AFX_MSG_MAP(CCreateTab)
	ON_BN_CLICKED(IDC_BUTTON_CREATEBROWSE, OnButtonCreatebrowse)
	ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
	ON_BN_CLICKED(IDC_BUTTON_SOURCEPATH, OnButtonSourcepath)
	ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCreateTab message handlers

// select the library name, via browse
void CCreateTab::OnButtonCreatebrowse() 
{
    CFileDialog GetFile(TRUE, "lib", m_libFileName, 
        OFN_HIDEREADONLY|OFN_CREATEPROMPT|
        OFN_NOTESTFILECREATE|OFN_PATHMUSTEXIST);

    if ( GetFile.DoModal() == IDOK )
        {
        CWnd *dlg;

        strcpy(m_libFileName, GetFile.GetPathName());
        dlg=GetDescendantWindow(IDC_EDIT_LIBNAME);
        dlg->SetWindowText(m_libFileName);
        }
}

void CCreateTab::OnButtonOpen() 
{
    DWORD newMaxIndex, currIndex;
    CWnd *dlg;
    char temp[TEMP_LEN+1];

    dlg=GetDescendantWindow(IDC_EDIT_LIBNAME);
    dlg->GetWindowText(m_libFileName, MAX_PATH);

    if ( editLib.OpenLibFile(m_libFileName) )
        {
        // failed to open existing lib, try making a new one
        dlg=GetDescendantWindow(IDC_EDIT_MAXITEMS);
        dlg->GetWindowText(temp, TEMP_LEN);
        newMaxIndex=atol(temp);
        if ( newMaxIndex )
            {
            if ( editLib.CreateLibFile(m_libFileName, newMaxIndex) )
                {
                sprintf(temp, "Error creating lib: %s", m_libFileName);
                MessageBox(temp, "Error", MB_ICONERROR);
                }
            else
                {
                sprintf(temp, "%d", newMaxIndex);
                dlg=GetDescendantWindow(IDC_EDIT_CURRMAXITEMS);
                dlg->SetWindowText(temp);
                dlg=GetDescendantWindow(IDC_EDIT_NUMITEMS);
                dlg->SetWindowText("0");
                sprintf(temp, "Created lib: %s", m_libFileName);
                MessageBox(temp, "Created OK");
                }
            }
        else
            {
            MessageBox("Max Items not set", "Error", MB_ICONWARNING);
            }
        }
    else
        {
        // read current libs stats
        currIndex=editLib.GetMaxNumInLib();
        dlg=GetDescendantWindow(IDC_EDIT_MAXITEMS);
        dlg->GetWindowText(temp, TEMP_LEN);
        newMaxIndex=atol(temp);
        if ( newMaxIndex > currIndex )
            editLib.ReSizeLib(newMaxIndex);
        else
            newMaxIndex=currIndex;

        sprintf(temp, "%u", newMaxIndex);
        dlg->SetWindowText(temp);
        dlg=GetDescendantWindow(IDC_EDIT_CURRMAXITEMS);
        sprintf(temp, "%d", newMaxIndex);
        dlg->SetWindowText(temp);
        currIndex=editLib.GetCurrNumInLib();
        sprintf(temp, "%u", currIndex);
        dlg=GetDescendantWindow(IDC_EDIT_NUMITEMS);
        dlg->SetWindowText(temp);
        sprintf(temp, "Opened lib: %s", m_libFileName);
        MessageBox(temp, "Opened OK");
        }
	
}

BOOL CCreateTab::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
    CWnd *dlg;
    
    dlg=GetDescendantWindow(IDC_EDIT_FILTER);
    dlg->SetWindowText("*.*");

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCreateTab::OnButtonSourcepath() 
{
    char temp[TEMP_LEN+1];

    sprintf(temp, "%s\\Select a path", m_pathName);
    CFileDialog GetFile(TRUE, NULL, temp, 
        OFN_HIDEREADONLY|OFN_NOTESTFILECREATE|OFN_PATHMUSTEXIST);

    if ( GetFile.DoModal() == IDOK )
        {
        CWnd *dlg;
        char *t1;

        strcpy(m_pathName, GetFile.GetPathName());
        t1=m_pathName + strlen(m_pathName);
        while ( t1 != m_pathName && *t1 != '\\' )
            t1--;
        if ( *t1 == '\\' )
            *t1=0;
        dlg=GetDescendantWindow(IDC_EDIT_ADDNAME);
        dlg->SetWindowText(m_pathName);
        }
}

void CCreateTab::OnButtonAdd() 
{
    char temp[MAX_PATH*2+1];
    char srcPath[MAX_PATH+1];
    char filter[MAX_PATH+1];
    CWnd *dlg;

    // open the lib if not open
    if ( !editLib.GetLibFileName(temp, MAX_PATH) )
        OnButtonOpen();

    if ( editLib.GetLibFileName(temp, MAX_PATH) )
        {
        // add the files
        dlg=GetDescendantWindow(IDC_EDIT_FILTER);
        dlg->GetWindowText(filter, MAX_PATH);
        if ( *filter )
            {
            dlg=GetDescendantWindow(IDC_EDIT_ADDNAME);
            dlg->GetWindowText(srcPath, MAX_PATH);
            if ( *srcPath )
                {
                strcpy(temp, srcPath);
                strcat(temp, "\\");
                strcat(temp, filter);
                editLib.AddFilesToLib(temp);
                }
            else
                MessageBox("Source path not set.", "Error", MB_ICONWARNING);
            }
        else
            MessageBox("Filter not set.", "Error", MB_ICONWARNING);
        }
    else
        {
        MessageBox("No open Library.", "Error", MB_ICONWARNING);
        }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Canada Canada
Professional Programmer living in Beautiful Vancouver, BC, Canada.

Comments and Discussions