// testcbxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testcbx.h"
#include "testcbxDlg.h"

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


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
        // No message handlers
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestcbxDlg dialog

CTestcbxDlg::CTestcbxDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTestcbxDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CTestcbxDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestcbxDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestcbxDlg)
    DDX_Control(pDX, IDC_COMBO, m_comboType);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestcbxDlg, CDialog)
    //{{AFX_MSG_MAP(CTestcbxDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestcbxDlg message handlers

BOOL CTestcbxDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    int nTypeTYM,nTypeTYC,nTypeTYX;

    HICON hIcon = AfxGetApp()->LoadIcon(IDI_SMALL3);
    nTypeTYM = m_comboType.AddIcon(hIcon);
    ::DestroyIcon(hIcon);
    
    hIcon = AfxGetApp()->LoadIcon(IDI_SMALL5);
    nTypeTYC = m_comboType.AddIcon(hIcon);
    ::DestroyIcon(hIcon);

    hIcon = AfxGetApp()->LoadIcon(IDI_SMALL4);
    nTypeTYX = m_comboType.AddIcon(hIcon);
    ::DestroyIcon(hIcon);

    m_comboType.SetBkGndColor(RGB(244,244,244));
    m_comboType.SetHiLightBkGndColor(RGB(157,206,255));
    m_comboType.SetTextColor(RGB(0,128,255));
    m_comboType.SetHiLightTextColor(RGB(255,255,0));
    m_comboType.SetHiLightFrameColor(RGB(255,0,255));

    WORD wParentIdx1 = m_comboType.AddCTString(nRootIndex,nTypeTYM,"Root 1");
    WORD wParentIdx2 = m_comboType.AddCTString(nRootIndex,nTypeTYM,"Root 2");

    WORD wParentlevel1 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"Root 1 1st level child");
    WORD wParentlevel2 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"Root 1 2nd level child");
    WORD wParentlevel3 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"Root 1 3rd level child");
    WORD wParentlevel4 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"Root 1 4th level child");

    WORD wParentIdx3 = m_comboType.AddCTString(nRootIndex,nTypeTYM,"Root 3");
    WORD wParentIdx4 = m_comboType.AddCTString(nRootIndex,nTypeTYM,"Root 4");

    m_comboType.AddCTString(wParentIdx4,nTypeTYC,"Root 4 1st level child");
    m_comboType.AddCTString(wParentIdx4,nTypeTYC,"Root 4 2nd level child");

    wParentlevel1 = m_comboType.AddCTString(wParentIdx3,nTypeTYC,"Root 3 1st level child");
    
    m_comboType.AddCTString(wParentlevel1,nTypeTYX,"Root 3 1st level child's 1st level child");
    m_comboType.AddCTString(wParentlevel1,nTypeTYX,"Root 3 1st level child's 2nd level child");
    m_comboType.AddCTString(wParentlevel1,nTypeTYX,"Root 3 1st level child's 3rd level child");

    wParentlevel2 = m_comboType.AddCTString(wParentIdx3,nTypeTYC,"Root 3 2nd level child");
    wParentlevel3 = m_comboType.AddCTString(wParentIdx3,nTypeTYC,"Root 3 3rd level child");

    m_comboType.SetCurSel(0);
//    m_comboType.EnableWindow(FALSE);
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestcbxDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestcbxDlg::OnPaint() 
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestcbxDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}