// Dialog1.cpp
// MFC Application Demonstrating a dialog box

#include <afxwin.h>
#include "dialog1.h"
#include "resource.h"

CMainWin::CMainWin()
{
    Create(NULL, "Demonstrate Dialog Boxes", WS_OVERLAPPEDWINDOW,
           rectDefault, NULL, "DialogMenu");
}

// The application's message map
BEGIN_MESSAGE_MAP(CMainWin, CFrameWnd)
    ON_COMMAND(IDM_DIALOG, OnDialog)
    ON_COMMAND(IDM_EXIT, OnExit)
END_MESSAGE_MAP()

// Process IDM_DIALOG menu item
void CMainWin::OnDialog()
{
    CSampleDialog diagOb("SampleDialog", this);
    diagOb.DoModal();  // activate the modal dialog box
}

// Process IDM_EXIT menu item
void CMainWin::OnExit()
{
    SendMessage(WM_CLOSE);  // Terminate the application and window
}

// The SampleDialog's message map
BEGIN_MESSAGE_MAP(CSampleDialog, CDialog)
    ON_COMMAND(IDD_RED, OnRed)
    ON_COMMAND(IDD_GREEN, OnGreen)
    ON_COMMAND(IDCANCEL, OnCancel)
    // IDOK is handled by default handler
END_MESSAGE_MAP()

// Process IDD_RED Button
void CSampleDialog::OnRed()
{
    MessageBox("Red", "Color Selected");
}

// Process IDD_GREEN Button
CSampleDialog::OnGreen()
{
    MessageBox("Green", "Color Selected");
}

// Process IDANCEL Button
void CSampleDialog::OnCancel()
{
    EndDialog(0); // Get rid of the dialog box
}

// IDOK Button will be handled by the default handler

// Initialize the application
BOOL CApp::InitInstance()
{
    m_pMainWnd = new CMainWin;
    m_pMainWnd->ShowWindow(m_nCmdShow);
    m_pMainWnd->UpdateWindow();
    return TRUE;
}


// Instantiate the Application
CApp App;