社区
界面
帖子详情
请问一个dialog在doModal后如何显示一个MessageBox?
iCharlene
2007-09-11 11:10:09
希望在doModal后停顿3s,然后显示一个MessageBox~~
不知道如何实现,实在是没发现有什么消息被传递
求教~~
...全文
124
6
打赏
收藏
请问一个dialog在doModal后如何显示一个MessageBox?
希望在doModal后停顿3s,然后显示一个MessageBox~~ 不知道如何实现,实在是没发现有什么消息被传递 求教~~
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
qeq2008
2007-09-12
打赏
举报
回复
不会吧一定用定时器吗?
用Sleep(3000);
iCharlene
2007-09-12
打赏
举报
回复
我试试WM_ACTIVATE看
我是苦力
2007-09-12
打赏
举报
回复
呵呵,开个线程加个settimer,不要说没有窗口就不能加settimer哦
lushiyun
2007-09-12
打赏
举报
回复
把定时器直接加到DOMODAL后,或者用活动窗口消息响应WM_ACTIVATE,还是可以的
iCharlene
2007-09-11
打赏
举报
回复
我晕,定时器加哪去啊???
难道加到init里?
我在dialog的init里边还加了些访问网络的代码,等返回的时间
可能都不止3s了,这可是个土办法~
如果有什么窗口/对话框创建完毕的消息就好了
gpgty
2007-09-11
打赏
举报
回复
设置个3s的定时器,响应WM_TIMER消息,在响应函数里面加Messagebox,再关掉定时器就可以了
MFC多窗口例程
No.4 简单的MFC多对话框演示程序 “Multi
Dialog
” 演示如何在工程中拥有多个对话框,及如何在
一个
对话框中调用另
一个
对话框。 重点:1、多个对话框类的建立;2、对话框的模式(Mo
dal
)调用方法;3、Spin控件的使用。 新建
一个
基于对话框的MFC工程, 通过菜单"Insert>>Resource"打开添加资源对话框, 在其中选择
Dialog
后点击New创建
一个
新的对话框 按Ctrl+W打开ClassWizard,系统会提示刚才创建了
一个
新的对话框资源,是否建立对应的类, 选择建立,然后在New Class窗口中Class Name栏输入它的名称:CSubClass1, 确定后系统会自动生成SubClass1.h和SubClass1.cpp并加入工程中,其中有已经创建好的CSubClass1的类的基本代码。 把这个对话框的Caption属性改为“难度选择”,在它上面画三个Radio“简单”、“标准”、“困难”, 并建立相关联的变量m_Option1。(要注意的是在ClassWizard中注意Class Name中应该选CSubClass1而不是之前的主对话框类) 按照相同方法建立第二个新对话框,类名“CSubClass2”,Caption为“关卡选择”。 在上面画
一个
Edit和
一个
Spin,注意先画Edit后画Spin,将Spin的Auto buddy和Set buddy integer勾上。 按Ctrl+W打开ClassWizard,为Edit建立关联变量,不过注意是int型而不是CString型, 也为Spin建立关联变量m_Spin1,注意这次是Control型变量CSpinButtonCtrl。 下面为这两个对话框添加代码。 双击“难度选择”对话框的OK按钮,建立对话框的OnOK映射。 在其中加入(在C
Dialog
::OnOK();之前): UpdateData(TRUE); if ((m_Option1>2) ||(m_Option1<0)) {
MessageBox
("错误的选择!","提示",MB_OK); return; } 下面对“关卡选择”对话框添加初始化代码, 由于关卡的有效值只有1到6,因此需要在初始化时设置Spin控件的有效值范围。 按Ctrl+W打开ClassWizard,在左侧列表选择这个对话框类CSub
Dialog
2, 在右侧列表中选择WM_INIT
DIALOG
,点击右边的“Add Function...”按钮, 接着点击右边的“Edit Code”按钮,在其中中加入(在C
Dialog
::OnInit
Dialog
()那句之后,在return TRUE那句之前): m_Spin1.SetRange(1,6); m_Text1=1; m_Spin1.SetPos(1); 其中CSpinButtonCtrl::SetRange()函数的作用是设置和他关联的Spin控件的范围,两个参数分别是下界和上界。 而CSpinButtonCtrl::SetPos()是设定Spin的当前位置。 两个新的对话框都已建立完毕,下来是如何在主对话框中使用的问题。 首先,两个新对话框都有各自的类,分别在Sub
Dialog
1.h和Sub
Dialog
2.h中有定义。(类的细节则在对应的cpp中定义) 因此,主对话框想要调用这两个新对话框,需要先包含这两个头文件, 在你要使用的地方(本例是Multi
Dialog
Dlg.cpp中)文件前面加上 #include "Sub
Dialog
1.h" #include "Sub
Dialog
2.h" 然后在想要调用的地方就可以使用了。 本例中,首先为主窗口的两个Edit建立CString型关联变量m_Text1和m_Text2, 然后在两个按钮的消息映射函数中分别加入: CSub
Dialog
1
dialog
1; //定义CSub
Dialog
1型对话框的
一个
新对象
dialog
1.
DoM
o
dal
(); //使用“模式”调用,
显示
对话框 m_Text1.Format("%d",
dialog
1.m_Option1); //此句在上面对话框没有关闭前不会执行到 UpdateData(FALSE); 和 CSub
Dialog
2
dialog
1;
dialog
1.
DoM
o
dal
(); m_Text2.Format("%d",
dialog
1.m_Text1); UpdateData(FALSE); 其中第一句均为定义对话框新实例的语句,定义
一个
你想要的类型的对话框。 第二句是通过调用C
Dialog
::
DoM
o
dal
()方法,来
显示
这个对话框,并进入“模式”(Mo
dal
)状态 在“模式”状态,当子对话框没有关闭之前,调用它的父对话框不能被响应, 并且其语句执行会停留在刚才的
DoM
o
dal
语句上等待,直到子对话框关闭才接着执行下
一个
语句。 第三第四句将子对话框得到的数据(即类的成员变量)
显示
在父对话框的Edit上。 四句执行完后退出该函数,这时刚才定义的CSub
Dialog
1等对话框类变量被销毁,因此创建的话框也被销毁。
mfc程序实践
(1)模态对话框 1.创建
一个
mfc111工程,添加
一个
新的
Dialog
,同时为该
Dialog
创建
一个
类。 2.Button添加command消息调用
DoM
o
dal
()。 (2)非模态对话框 1.声明该类的指针调用Create()函数,为按键设置COMMAND消息,其中调用DestroyWindow()函数。 (3)加法器 1.在对话框中加入3个edit空件。为3个edit控件分别添加整型变量m_num1,m_num2,m_num3. 2.为OK控件添加COMMAND消息。在void CTEST2::OnOK()函数中写入代码,实现两数相加。再将和在第三个edit中
显示
出来。 (4)上网问卷调查 1.在对话框中加入两组radio button每组三个,(只能进行单选)再加入一组Check Box(3个)实现多选 2.每组选中第
一个
属性设置为Group。 3.在BOOL CTEST3::OnInit
Dialog
()函数中添加代码实现缺省情况下选中状态。 4.为OK添加COMMAND消息实现选择。并利用
MessageBox
()输出。 (5)动态创建按钮 1.添加button1.为button1添加COMMAND消息。 2. 调用Create()创建对话框。
显示
我的文档路径
显示
我的文档路径,// WENDANGDlg.cpp : implementation file // #include "stdafx.h" #include "WENDANG.h" #include "WENDANGDlg.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 C
Dialog
{ 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() : C
Dialog
(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { C
Dialog
::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, C
Dialog
) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWENDANGDlg
dialog
CWENDANGDlg::CWENDANGDlg(CWnd* pParent /*=NULL*/) : C
Dialog
(CWENDANGDlg::IDD, pParent) { //{{AFX_DATA_INIT(CWENDANGDlg) // 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 CWENDANGDlg::DoDataExchange(CDataExchange* pDX) { C
Dialog
::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWENDANGDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWENDANGDlg, C
Dialog
) //{{AFX_MSG_MAP(CWENDANGDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWENDANGDlg message handlers BOOL CWENDANGDlg::OnInit
Dialog
() { C
Dialog
::OnInit
Dialog
(); // 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 return TRUE; // return TRUE unless you set the focus to a control } void CWENDANGDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.
DoM
o
dal
(); } else { C
Dialog
::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 CWENDANGDlg::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 { C
Dialog
::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CWENDANGDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CWENDANGDlg::OnOK() { char m_lpszDefaultDir[MAX_PATH]; char szDocument[MAX_PATH]={0}; memset(m_lpszDefaultDir,0,_MAX_PATH); LPITEMIDLIST pidl=NULL; SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl); if (pidl && SHGetPathFromIDList(pidl, szDocument)) { GetShortPathName(szDocument,m_lpszDefaultDir,_MAX_PATH); }
MessageBox
(m_lpszDefaultDir); }
MFC制作的MP3
使用MFC制作MP3打开vc6.0,建立如图所示mfc工程文件 选择基于对话框的确定 删除所有空间,建立如图所示对话框 属性如下: 播放 IDC_open; 添加 IDC_fileopen; 暂停 IDC_pause; 删除 IDC_del; 停止 IDC_stop; 退出 IDC_exit; 音乐名编辑框 IDC_filename; 音量控制滑块 IDC_SLIDER1; 音量控制编辑框 IDC_vol; 建立类向导对应如下: 在工程文件,右键,插入,bitmap位图 引入你想插入的背景图,必须是bmp格式的 进入你的dlg.cpp文件 在onpaint函数下
简易的播放器
基于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 C
Dialog
{ public: CAboutDlg(); //
Dialog
Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : C
Dialog
(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { C
Dialog
::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, C
Dialog
) END_MESSAGE_MAP() // CtestDlg
dialog
CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/) : C
Dialog
(CtestDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CtestDlg::DoDataExchange(CDataExchange* pDX) { C
Dialog
::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CtestDlg, C
Dialog
) 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::OnInit
Dialog
() { C
Dialog
::OnInit
Dialog
(); // 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.
DoM
o
dal
(); } else { C
Dialog
::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 { C
Dialog
::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|*.*||"; CFile
Dialog
dlg(TRUE,NULL,NULL,/*OFN_HIDEREADONLY |*/ OFN_OVERWRITEPROMPT,lpszFilter); if(dlg.
DoM
o
dal
()==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() { C
Dialog
::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(); }
界面
15,979
社区成员
115,897
社区内容
发帖
与我相关
我的任务
界面
VC/MFC 界面
复制链接
扫一扫
分享
社区描述
VC/MFC 界面
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章