CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

高分求教!!如何在Radio Button的BN_CLICKED事件中调用对话框

楼主doushi(斗士)2003-06-02 22:36:16 在 VC/MFC / 基础类 提问

一个基于对话框的MFC程序,在主对话框中有一组(两个)Radio   Button,其中一个的BN_CLICKED事件中调用了另一个对话框,当鼠标点击时能正常响应,但如果将焦点放到没有BN_CLICKED事件的Radio   Button上,然后使用光标移动键移动到有BN_CLICKED事件的Radio   Button上,弹出对话框后点“确定”或“取消”按钮退出时则陷入对Ridion   Button的BN_CLICKE事件响应函数的递归调用,在本人的环境下大约18次后创建对话框失败。  
   
  以下是例子的代码:  
  这是一个由VC向导生成的对话框程序,在对话框上添加了两个Radio   Button,另外增加了一个对话框,没有任何附加内容(仅有“确定”和“取消”按钮),对应CMyDialog类。  
   
  //   testDlg.cpp   :   implementation   file  
  //  
   
  #include   "stdafx.h"  
  #include   "test.h"  
  #include   "testDlg.h"  
  #include   "MyDialog.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(CAboutDlg)  
  //}}AFX_DATA_MAP  
  }  
   
  BEGIN_MESSAGE_MAP(CAboutDlg,   CDialog)  
  //{{AFX_MSG_MAP(CAboutDlg)  
  //   No   message   handlers  
  //}}AFX_MSG_MAP  
  END_MESSAGE_MAP()  
   
  /////////////////////////////////////////////////////////////////////////////  
  //   CTestDlg   dialog  
   
  CTestDlg::CTestDlg(CWnd*   pParent   /*=NULL*/)  
  :   CDialog(CTestDlg::IDD,   pParent)  
  {  
  //{{AFX_DATA_INIT(CTestDlg)  
  //   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   CTestDlg::DoDataExchange(CDataExchange*   pDX)  
  {  
  CDialog::DoDataExchange(pDX);  
  //{{AFX_DATA_MAP(CTestDlg)  
  //   NOTE:   the   ClassWizard   will   add   DDX   and   DDV   calls   here  
  //}}AFX_DATA_MAP  
  }  
   
  BEGIN_MESSAGE_MAP(CTestDlg,   CDialog)  
  //{{AFX_MSG_MAP(CTestDlg)  
  ON_WM_SYSCOMMAND()  
  ON_WM_PAINT()  
  ON_WM_QUERYDRAGICON()  
  ON_BN_CLICKED(IDC_RADIO2,   OnRadio2)  
  //}}AFX_MSG_MAP  
  END_MESSAGE_MAP()  
   
  /////////////////////////////////////////////////////////////////////////////  
  //   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  
   
  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,   (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   CTestDlg::OnQueryDragIcon()  
  {  
  return   (HCURSOR)   m_hIcon;  
  }  
   
  void   CTestDlg::OnRadio2()    
  {  
          //   TODO:   Add   your   control   notification   handler   code   here  
          int   nRet;  
          CMyDialog   Dlg;  
          nRet   =   Dlg.DoModal();   //   调用对话框  
          if   (-1   ==   nRet)  
          {  
                  return;   //   调试时可在此处设置断点  
          }  
  }  
   
  问题点数:0、回复次数:3Top

1 楼ccwing(不是背书郎)回复于 2003-06-02 22:59:22 得分 0

void   CTestDlg::OnRadio2()   这样改:  
   
  首先把焦点弄到别的控件,再显示对话框——烂主意Top

2 楼kingtsui(http://community.studyez.com/blogs/silentacorn)回复于 2003-06-02 23:02:24 得分 0

你的光标移动键是指什么?   Tab键吗?Top

3 楼doushi(斗士)回复于 2003-06-03 19:43:41 得分 0

光标移动键是指上“↑”下“↓”左“←”右“→”键Top

相关问题

  • 怎么调用对话框?
  • 如何调用对话框
  • 如何调用通用对话框中保存的对话框
  • 在对话框程序中如何调用对话框?
  • 子对话框调用主对话框变量
  • 调用模态对话框的问题
  • 关于对话框调用的问题
  • 在PB怎样调用OpenFile对话框?
  • 如何调用下载对话框?
  • 如何调用多个对话框

关键词

  • 移动
  • 对话框
  • caboutdlg
  • ctestdlg
  • afx
  • 调用
  • bn
  • cdialog
  • aboutbox
  • onradio

得分解答快速导航

  • 帖主:doushi

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo