sanfan49er 0 Newbie Poster

Hello everybody this is my second posting and I have been working on this code for quite some time and its a module thats part of my coding but I am having quite a bit of trouble from having a check box checked and it changing the picture I got it to the basics but I need help to do it also CheckBox1 is checked, changing the contents of the text box also changes the first item of the list box to match. After that I should be finished if somebody can help me asap

//////////////////////////////////////////////////////////////////////
// CMyApplication.cpp
// This defines the functions in our derived class CMyApplication
//////////////////////////////////////////////////////////////////////

#include "CMyApplication.h"
#include "CSprite.h"
#include "CGraphics.h"
#include "Utils.h"

//////////////////////////////////////////////////////////////////////
// CMyApplication::Initialize()										
// Initialize the application, this is called after the window has
// been displayed, and D3D has been initialized
//////////////////////////////////////////////////////////////////////
void CMyApplication::Initialize()
{
	m_sprConsole = new CSprite();
	m_sprConsole->Load(L"Console.png");

	// Create our two new pictures
	m_sprPicture1 = new CSprite();
	m_sprPicture2 = new CSprite();
	
	// Now we init the graphical user interface
	InitGUI();
}

//////////////////////////////////////////////////////////////////////
// CMyApplication::Cleanup()											
// Called when the application terminates to clean up memory, etc	
//////////////////////////////////////////////////////////////////////
void CMyApplication::Cleanup()
{
	SAFEDELETE(m_sprPicture1);
	SAFEDELETE(m_sprPicture2);
	SAFEDELETE(m_sprConsole);
	SAFEDELETE(m_pGraphics);
}

//////////////////////////////////////////////////////////////////////
// CMyApplication::InitGUI()
// Initializes the Graphical User Interface for the application
//////////////////////////////////////////////////////////////////////
void CMyApplication::InitGUI()
{
	// Call parent initialize
	CApplication::InitGUI();
	
	// Set our starting y position to the top of the console
	int y = m_iConsoleY;

    m_GUI.AddButton(IDC_BUTTON, L"Exit App", m_iWidth-140, m_iHeight-42, 125, 22 );
	m_GUI.AddEditBox(IDC_TEXTBOX, L"TextBox! Edit me!",m_iConsoleX+10,y+=10,200,30,false,NULL);
	m_GUI.AddSlider(IDC_SLIDER,m_iConsoleX+10,y+=22,200,32,0,100,50,false,NULL);

	// List box
	m_GUI.AddListBox( IDC_LISTBOX, m_iConsoleX+12, y+=25, 200, 45, 0 );
	for( int i = 0; i < 15; ++i )
	{
		WCHAR wszText[50];
		swprintf(wszText, L"Listbox item %d", i);
		m_GUI.GetListBox( IDC_LISTBOX )->AddItem(wszText, (LPVOID)(size_t)i);
	}

	// Checkboxes
	y=m_iConsoleY;
	m_GUI.AddCheckBox(IDC_CHECKBOX1,L"CheckBox1",m_iConsoleX+220,y+=10,100,16);
	m_GUI.AddCheckBox(IDC_CHECKBOX2,L"CheckBox2",m_iConsoleX+220,y+=16,100,16);

	// Radio buttons
	m_GUI.AddRadioButton(IDC_RADIO1,0,L"RadioButton1",m_iConsoleX+220,y+=16,100,16);
	m_GUI.AddRadioButton(IDC_RADIO2,0,L"RadioButton2",m_iConsoleX+220,y+=16,100,16);

	// Another group of radio buttons
	m_GUI.AddRadioButton(IDC_RADIO3,1,L"RadioButton3",m_iConsoleX+220,y+=16,100,16);
	m_GUI.AddRadioButton(IDC_RADIO4,1,L"RadioButton4",m_iConsoleX+220,y+=16,100,16);

	// ComboBox
	y=m_iConsoleY;
	m_GUI.AddComboBox(IDC_COMBOBOX1,m_iConsoleX+420,y+=10,150,24);
	m_GUI.GetComboBox(IDC_COMBOBOX1)->SetDropHeight(50);
	for(int i=1;i<=NUM_PICTURES;i++)
	{
		WCHAR wszText[50];
		swprintf(wszText, L"Hammer%d.png", i);
		m_GUI.GetComboBox(IDC_COMBOBOX1)->AddItem(wszText, NULL);
	}

	// Another combo box
	m_GUI.AddComboBox(IDC_COMBOBOX2,m_iConsoleX+420,y+=24,150,24);
	m_GUI.GetComboBox(IDC_COMBOBOX2)->SetDropHeight(50);
	for(int i=1;i<=NUM_PICTURES;i++)
	{
		WCHAR wszText[50];
		swprintf(wszText, L"Hammer%d.png", i);
		m_GUI.GetComboBox(IDC_COMBOBOX2)->AddItem(wszText, NULL);
	}

	// Add our static textbox
	m_GUI.SetFont(1,L"Arial",24,FW_BOLD);
	m_GUI.AddStatic(IDC_STATIC,L"Not yet initialized",4,4,m_iWidth,m_iConsoleY);
    m_GUI.GetControl(IDC_STATIC)->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP|DT_WORDBREAK;
	m_GUI.GetControl(IDC_STATIC)->GetElement(0)->iFont = 1;

	// Go through and initialize all our members by sending a blank message
	// otherwise all our variables will start out with garbage!
	for(int i=0; i < IDC_STATIC; i++)
	{
		OnGUIEvent(EVENT_INITIALIZE,i,m_GUI.GetControl(i));
	}
}

//////////////////////////////////////////////////////////////////////
// CMyApplication::UpdateScene(...)
// This function updates our static text control based on the GUI
//////////////////////////////////////////////////////////////////////
void CMyApplication::UpdateScene(float fTimeScale)
{
	// Update the contents of our textbox
	WCHAR wszText[256];
	swprintf(wszText,L"--Variables------\nSlider:%d\nText:%s\nListBox Text: %s\nCheckBox1: %d\nCheckBox2: %d\nRadio1: %d, Radio2:%d, Radio3:%d, Radio4: %d\nCombo1: %s\nCombo2: %s",
		m_iSlider,m_strText.c_str(),m_strListBox.c_str(),m_flgCheck1,m_flgCheck2,m_flgRadio1,
		m_flgRadio2,m_flgRadio3,m_flgRadio4,m_strCombo1.c_str(),m_strCombo2.c_str());
	m_GUI.GetStatic(IDC_STATIC)->SetText(wszText);

	// Call the parent update function, which performs a quickstep on our ODE world
	CApplication::UpdateScene(fTimeScale);
}

//////////////////////////////////////////////////////////////////////
// CMyAppliction::Render()
// Draw our two sprites on the screen
//////////////////////////////////////////////////////////////////////
void CMyApplication::Render()
{
	// Call the parent draw function, which clears the screen and draws
	// the console/GUI
	CApplication::Render();

	// Draw our two sprites on top
	m_sprPicture1->Draw(390,16);
	m_sprPicture2->Draw(390,32+m_sprPicture1->GetHeight());
}

//////////////////////////////////////////////////////////////////////
// CApplication::OnGUIEvent(...)
// Called when a GUI event occurs
//////////////////////////////////////////////////////////////////////
void CMyApplication::OnGUIEvent(UINT nEvent,int nControlID,CDXUTControl *pControl)
{
	// See if our exit button was pressed, if it was, then set our running flag
	// to false, if nEvent is EVENT_INITIALIZE dont exit however, because thats the event
	// we send to initialize our data members
	if(nControlID==IDC_BUTTON && nEvent != EVENT_INITIALIZE)
	{
		SetRunning(false);
	}
	else if(nControlID==IDC_SLIDER)
	{
		// Update our slider variable
		CDXUTSlider *pSlider = (CDXUTSlider *)pControl;
		m_iSlider = pSlider->GetValue();
	}
	else if(nControlID==IDC_TEXTBOX)
	{
		// Update our textbox variable
		CDXUTEditBox *pEditBox = (CDXUTEditBox *)pControl;
		WCHAR wszText[50];
		pEditBox->GetTextCopy(wszText,50);
		m_strText = wszText;
	}

	else if(nControlID==IDC_CHECKBOX1)
	{
		// Set our check box
		CDXUTCheckBox *pCheckBox = (CDXUTCheckBox *)pControl;
		m_flgCheck1 = pCheckBox->GetChecked();

	}
	else if(nControlID==IDC_CHECKBOX2)
	{
		// Set our second check box
		CDXUTCheckBox *pCheckBox = (CDXUTCheckBox *)pControl;
		m_flgCheck2 = pCheckBox->GetChecked();
	}
	else if(nControlID==IDC_LISTBOX)
	{
		// Update listbox
		CDXUTListBox *pListBox = (CDXUTListBox *)pControl;
		
		// Make sure something is selected
		if(pListBox->GetSelectedIndex() >= 0 && pListBox->GetSelectedItem()->strText)
			m_strListBox = pListBox->GetSelectedItem()->strText;
		else
			m_strListBox = L"";
	}
	
	// Check for our 4 radio buttons
	else if(nControlID==IDC_RADIO1)
	{
		CDXUTRadioButton *pButton = (CDXUTRadioButton *)pControl;
		m_flgRadio1 = pButton->GetChecked();
	}
	else if(nControlID==IDC_RADIO2)
	{
		CDXUTRadioButton *pButton = (CDXUTRadioButton *)pControl;
		m_flgRadio2 = pButton->GetChecked();
	}
	else if(nControlID==IDC_RADIO3)
	{
		CDXUTRadioButton *pButton = (CDXUTRadioButton *)pControl;
		m_flgRadio3 = pButton->GetChecked();
	}
	else if(nControlID==IDC_RADIO4)
	{
		CDXUTRadioButton *pButton = (CDXUTRadioButton *)pControl;
		m_flgRadio4 = pButton->GetChecked();
	}
	else if(nControlID==IDC_COMBOBOX1)
	{
		// Get string from the first combo box
		CDXUTComboBox *pCombo = (CDXUTComboBox *)pControl;
		m_strCombo1 = pCombo->GetSelectedItem()->strText;

		// Figure out the new filename to load, and load it
		wstring strFilename = wstring(L"Images\\") + m_strCombo1;
		m_sprPicture1->Load(strFilename);

	}
	else if(nControlID==IDC_COMBOBOX2)
	{
		// Get string from the first combo box
		CDXUTComboBox *pCombo = (CDXUTComboBox *)pControl;
		m_strCombo2 = pCombo->GetSelectedItem()->strText;

		// Figure out the new filename to load, and load it
		wstring strFilename = wstring(L"Images\\") + m_strCombo2;
		m_sprPicture2->Load(strFilename);
	}	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.