设为首页 加入收藏

TOP

C++MFC编程笔记day09 MF界面控件的使用1(四)
2015-07-20 17:55:33 来源: 作者: 【 】 浏览:27
Tags:MFC 编程 笔记 day09 界面 控件 使用
you by the framework. void CDlgCtrlDlg::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 CDlgCtrlDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CDlgCtrlDlg::OnOpenFile() { // TODO: Add your control notification handler code here char lpszFilter[]="视频(*.avi)|*.avi|视频(*.rmvb)|*.rmvb|所有文件(*.*)|*.*||"; CFileDialog dlg(TRUE,NULL,NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, lpszFilter); if(IDOK!=dlg.DoModal()) return; //编辑框中更新文件路径 m_strFilePath=dlg.GetPathName(); UpdateData(FALSE); //列表加入文件名 //m_listFileName.AddString(dlg.GetFileName()); CString strName=dlg.GetFileName(); if (LB_ERR==m_listFileName.FindString(-1,strName)) { //添加文件名称 int nIndex=m_listFileName.AddString(strName); CString *pPath=new CString; *pPath=m_strFilePath; //通过附加数据,保存文件路径 m_listFileName.SetItemData(nIndex,(DWORD)pPath); } //动画控件播放动画 play(); } void CDlgCtrlDlg::play() { int nCount=1;//保存播放的次数 if (m_btnReplay.GetCheck()) { int nSel=m_cboPlayCount.GetCurSel(); switch(nSel) { case 0://重复播放 nCount=-1; break; case 1://重复一次 nCount=2; break; case 2://重复两次 nCount=3; break; } } m_animateVideo.Open(m_strFilePath); m_animateVideo.Play(0,-1,nCount); } void CDlgCtrlDlg::OnDblclkListFilename() { //获取双击时,当前的选择项 int nSel=m_listFileName.GetCurSel(); if (LB_ERR==nSel)return; //播放当前选中的文件 CString *pPath=(CString*) m_listFileName.GetItemData(nSel); m_strFilePath=*pPath; //播放 play(); UpdateData(FALSE); AfxMessageBox(*pPath); } void CDlgCtrlDlg::OnClose() { //字符串路径在附加数据里,关闭时要删除 for (int i=0;i



示例2:
1、新建MFC对话框应用程序DlgCtrl2。
2、可视化编辑界面控件

\
3、ctrl+w 绑定控件对应的成员变量

\
4、ctrl+w 绑定列表框项的双击事件和按钮的单击事件

\
5、***Dlg.cpp中的主要实现代码(部分是自动生成的)

#include "stdafx.h"
#include "DlgCtrl2.h"
#include "DlgCtrl2Dlg.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(CAbout
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 3321(很好的题目,参看了很多.. 下一篇POJ 3071 Football(简单 概率DP)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: