EDN首页   博客首页

日志档案

发表于 2007-9-14 20:24:46

0

标签: VC  

我的第一个VC例子注解

void CEx7_2Dlg::OnCleartext()
{
 // TODO: Add your control notification handler code here
 GetDlgItem(IDC_MYTEXT)->SetWindowText("");  //获取ID控件
 
}

void CEx7_2Dlg::OnCopyText()
{
 // TODO: Add your control notification handler code here
 CString str;
 CListBox* lbx;

 GetDlgItem(IDC_MYTEXT)->GetWindowText(str);
 lbx=(CListBox*)GetDlgItem(IDC_TEXTLIST);  //转化类型
 lbx->AddString(str);
 
}

void CEx7_2Dlg::OnDblclkTextlist()      //列表框双击
{
 // TODO: Add your control notification handler code here
 CListBox* lbx;
 CString str;

 lbx=(CListBox*)GetDlgItem(IDC_TEXTLIST);
 lbx->GetText(lbx->GetCurSel(),str);     //返回项目编号,LB_ERR,
 GetDlgItem(IDC_MYTEXT)->SetWindowText(str);


}

void CEx7_2Dlg::OnClearlist()
{
 // TODO: Add your control notification handler code here
 CListBox *lbx;

 lbx=(CListBox*)GetDlgItem(IDC_TEXTLIST);
 lbx->ResetContent();         //清除列表框数据
 
}

BOOL CEx7_2App::InitInstance()
{
 // Standard initialization
 // If you are not using these features and wish to reduce the size
 //  of your final executable, you should remove from the following
 //  the specific initialization routines you do not need.

 CEx7_2Dlg dlg;
 m_pMainWnd = &dlg;             //CEx7_2Dlg作为主窗口
 int nResponse = dlg.DoModal(); //启动对话框
 if (nResponse == IDOK)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with OK
 }
 else if (nResponse == IDCANCEL)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with Cancel
 }

 // Since the dialog has been closed, return FALSE so that we exit the
 //  application, rather than start the application's message pump.
 return FALSE;
}

class CEx7_2Dlg : public CDialog
{
// Construction
public:
 CEx7_2Dlg(CWnd* pParent = NULL); // 父窗口指针

// Dialog Data
 //{{AFX_DATA(CEx7_2Dlg)
 enum { IDD = IDD_EX7_2_DIALOG };       //对话框资源的ID
  // NOTE: the ClassWizard will add data members here
 //}}AFX_DATA

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

// Implementation
protected:
 HICON m_hIcon;

 // Generated message map functions
 //{{AFX_MSG(CEx7_2Dlg)
 virtual BOOL OnInitDialog();     //成员函数
 afx_msg void OnPaint();
 afx_msg HCURSOR OnQueryDragIcon();
 afx_msg void OnCleartext();
 afx_msg void OnCopyText();
 afx_msg void OnDblclkTextlist();
 afx_msg void OnClearlist();
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()           //消息响应列表
};

CEx7_2Dlg::CEx7_2Dlg(CWnd* pParent /*=NULL*/)
 : CDialog(CEx7_2Dlg::IDD, pParent)       //调用父类CDialog的构造函数
{
 //{{AFX_DATA_INIT(CEx7_2Dlg)
  // 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);        //哪个CWinApp对象的指针,载入图标
}

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

 // 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
 
 // TODO: Add extra initialization here
 
 return TRUE;  // return TRUE  unless you set the focus to a control
}

BEGIN_MESSAGE_MAP(CEx7_2Dlg, CDialog)     //消息列表
 //{{AFX_MSG_MAP(CEx7_2Dlg)
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_BN_CLICKED(IDC_CLEARTEXT, OnCleartext)
 ON_BN_CLICKED(IDC_COPY, OnCopyText)
 ON_LBN_DBLCLK(IDC_TEXTLIST, OnDblclkTextlist)
 ON_BN_CLICKED(IDC_CLEARLIST, OnClearlist)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

 


 

系统分类: 单片机   |   用户分类: VC++学习   |   来源: 原创   |   【推荐给朋友】   |   【添加到收藏夹】

    阅读(1490)    回复(1)  

投一票您将和博主都有获奖机会!