首页 > 代码库 > CDialog的使用

CDialog的使用

1,先添加资源

2,头文件

#ifndef MyMain_h_#define MyMain_h_#include <afxwin.h>#include "resource.h"class MyApp:public CWinApp{public:    BOOL InitInstance();};class MyDialog:public CDialog{    enum{IDD=IDD_DIALOG1};public:    MyDialog();    ~MyDialog();    virtual BOOL OnInitDialog();private:    CComboBox m_CComboBox;};#endif

3,实现

#include "MyMain.h"MyApp myApp;BOOL MyApp::InitInstance(){    MyDialog tMyDialog;    tMyDialog.DoModal();    return TRUE;}MyDialog::MyDialog():CDialog(MyDialog::IDD){}MyDialog::~MyDialog(){}BOOL MyDialog::OnInitDialog(){    m_CComboBox.Create( WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWNLIST            ,CRect(50,50,150,170)            ,this            ,IDC_COMBO1        );    m_CComboBox.AddString(_T("L"));    m_CComboBox.AddString(_T("M"));    m_CComboBox.AddString(_T("B"));    m_CComboBox.AddString(_T("P2P"));    m_CComboBox.AddString(_T("ALL"));    return TRUE;}

4,看结果:

附加一个Demo