请问CTestDlg2::CTestDlg2(CWnd* pParent /*=NULL*/): CDialog(CTestDlg2::IDD, pParent)

wolfza 2001-05-08 02:49:00
CTestDlg2::CTestDlg2(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg2::IDD, pParent)
这句话是什么意思,怎么还联系上了基类,可否详细说明一下
...全文
530 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wolfza 2001-05-09
  • 打赏
  • 举报
回复
盼回复
wolfza 2001-05-08
  • 打赏
  • 举报
回复
请指教
wolfza 2001-05-08
  • 打赏
  • 举报
回复
感觉应该是差不多,小弟不明白的是这句话的语法,平常看到的不都是类似
CTestDlg2::CTestDlg2(CWnd* pParent /*=NULL*/)
现在这句话后面加了个: CDialog(CTestDlg2::IDD, pParent),我顿时迷糊了,可否通俗的解释一下,多谢了
vcbacker 2001-05-08
  • 打赏
  • 举报
回复
我猜想是因为要把CTestDlg2::IDD这个参数传递给父类的构造函数吧。
wolfza 2001-05-08
  • 打赏
  • 举报
回复
没错,看技术内幕时我便有这个疑问,为什么不写在构造函数体内?CTestDlg2::CTestDlg2(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg2::IDD, pParent)
我很不明白,望大虾解惑
vcbacker 2001-05-08
  • 打赏
  • 举报
回复
CTestDlg2::CTestDlg2(CWnd* pParent /*=NULL*/)
: m_rect(0,0,100,100)
差不多吧,:)
wolfza 2001-05-08
  • 打赏
  • 举报
回复
等待
基于DirectSound的简易播放器 #include "stdafx.h" #include "test.h" #include "testDlg.h" #include "process.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CtestDlg dialog CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/) : CDialog(CtestDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CtestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CtestDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_OPEN, &CtestDlg::OnBnClickedButtonOpen) ON_BN_CLICKED(IDC_BUTTON_PLAY, &CtestDlg::OnBnClickedButtonPlay) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_STOP, &CtestDlg::OnBnClickedButtonStop) END_MESSAGE_MAP() //ON_BN_CLICKED(IDC_Sound_Play, OnSound2) //ON_BN_CLICKED(IDC_Sound_stop, OnSound1) //ON_BN_CLICKED(IDC_sound_pause, OnBothSounds) //ON_WM_DESTROY() //ON_BN_CLICKED(IDC_BUTTON_Slow, OnBUTTONSlow) //ON_BN_CLICKED(IDC_BUTTON_Fast, OnBUTTONFast) //ON_BN_CLICKED(IDC_BUTTON_Normal, OnBUTTONNormal) // CtestDlg message handlers BOOL CtestDlg::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 // TODO: Add extra initialization here m_sndSound1 = new CDirectSound(); if(!m_sndSound1) { exit(-1); } return TRUE; // return TRUE unless you set the focus to a control } void CtestDlg::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 CtestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CtestDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } //--------------------------------------------------------------------------------- void CtestDlg::OnBnClickedButtonOpen() { // TODO: Add your control notification handler code here LPCTSTR lpszFilter =L"Wave File(*.wav)|*.wav|All Files|*.*||"; CFileDialog dlg(TRUE,NULL,NULL,/*OFN_HIDEREADONLY |*/ OFN_OVERWRITEPROMPT,lpszFilter); if(dlg.DoModal()==IDOK) { m_soundfile = dlg.GetPathName(); } } // unsigned int WINAPI FileReadProc(LPVOID pOwner) { CtestDlg* pThis = (CtestDlg*)pOwner; pThis->ReadFileProc(); return 1; } // typedef struct _WAVE_FORMAT { WORD AudioFormat; WORD NumChannels; DWORD SampleRate; DWORD ByteRate; WORD BlockAlign; WORD BitsPerSample; }WAVE_FORMAT,*PWAVE_FORMAT; void CtestDlg::OnBnClickedButtonPlay() { // TODO: Add your control notification handler code here if(m_soundfile.IsEmpty()) { MessageBox(L"请选中播放文件!"); return; } USES_CONVERSION; fp = fopen(W2A(m_soundfile.GetBuffer(m_soundfile.GetLength())),"rb"); if(NULL == fp) { MessageBox(L"打开所所定的播放文件失败,请确认文件是否存在!"); return; } fseek(fp,20,0); //Skip previous 20 bytes RIFF header WAVE_FORMAT waveFormat; int nLen =fread(&waveFormat,1,sizeof(WAVE_FORMAT),fp); AUDIO_CONFIG WaveHead; WaveHead.wFormatTag = 1; WaveHead.nChannels = 2; WaveHead.nSamplesPerSec = 44100; WaveHead.nAvgBytesPerSec = 176400; WaveHead.nBlockAlign = 4; WaveHead.wBitsPerSample = 16; WaveHead.nBlockAlign=waveFormat.BlockAlign; WaveHead.nChannels=waveFormat.NumChannels; WaveHead.nSamplesPerSec=waveFormat.SampleRate; WaveHead.wBitsPerSample=waveFormat.BitsPerSample; WaveHead.nAvgBytesPerSec=waveFormat.ByteRate; m_sndSound1->CreateDSound(&WaveHead,8000); fseek(fp,20+sizeof(WAVE_FORMAT),0); unsigned int dwReadID; m_hThread = (HANDLE)_beginthreadex(0,0,FileReadProc,this,0,&dwReadID); Sleep(200); m_bStop = 0; m_bContine = 1; m_sndSound1->Play(); } void CtestDlg::ReadFileProc() { //BYTE buf[1025]; int n = 0; while(1) { BYTE buf[1025]; int nlen; if(m_bStop) break; nlen = fread(buf,1,1024,fp); if(!nlen) break; while(m_sndSound1->WriteDataToBuf(buf,nlen)==-1) { Sleep(100); } } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_bStop = 1; OnBnClickedButtonStop(); if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = 0; } if(m_sndSound1) { delete m_sndSound1; m_sndSound1 = NULL; } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnBnClickedButtonStop() { // TODO: Add your control notification handler code here m_bStop = 1; if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = NULL; } m_sndSound1->Stop(); }

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧