`
paulfzm
  • 浏览: 873169 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

CDialog::OnInitDialog() ----转

    博客分类:
  • vc++
阅读更多

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

。。。。。。。

}

作用:是响应WM_INITDIALOG消息的处理函数.
       声明:OnInitDialog()说明:
这里主要说明一个它与构造函数的一些相同点和不同点.
相同点:
               都可以进行初始化的工作.
不同点:
               InitDialog是响应WM_INITDIALOG消息的函数.构造函数,是当你对一个对象实例话的时候,调用的函数. 在这里,构造函数早于InitDialog的调用。
               构造函数:对话框还不存在,使用hwnd之类的东西会不管用  
               InitDialog:对话框已存在.而且如果你初始话时需要分配很大的内存,那么放在OnInitDialog()会更合适。
               控件的初始化要放在OnInitDialog  
               普通成员变量的初始化可以放在构造函数中
       但是它的return   TRUE与return FALSE有什么区别呢?
       MSDN上面:
       Return Value
Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.
       至于应用场合:假设这个Dialog上要求输入内容,如果dialog一弹出来就自动把输入焦点放在第一个编辑框上不就很方便嘛,可以直接输入内容了。这时候OnInitDialog()就需要返回TRUE。
       个人总结是:当返回TRUE时表明Windows自动的将输入焦点置于序列上排第一的 某个空件上;而当返回FALSE时只是表明你将输入焦点人为的改变在其他的某个控件上。

问题:CDialog::OnInitDialog() 遇到错误 弹出 “试图执行系统不支持的操作“

有百分之八十的原因是你使用了一个资源,比如一个EDIT,同时你又在类中建了一个成员,如CEdit m_editTest;但是现在你把这个EDIT删除了,而m_editTest却没有删除。你只要在ClassWizard中找到这个定义,将其删除就一切OK了。

虽然屏蔽CDialog::OnInitDialog()   这一句话可以让程序通过编译,但是会导致一系列BUG

比如:

1.

((CTabCtrl*)GetDlgItem(IDC_TAB1))->InsertItem(0,"WMS本地");

// CTab.InsertItem(0,"WMS本地");        //屏蔽后,如此添加标签有错,必须如上所示方法使用
((CTabCtrl*)GetDlgItem(IDC_TAB1))->InsertItem(1,"WFS在线");

2.TABCTRL控件的切换

if(CTab.GetCurSel() == 0)
{
WMS_Page.ShowWindow(SW_SHOW);
WFS_Page.ShowWindow(SW_HIDE);
}
else if (CTab.GetCurSel() == 1)
{
WFS_Page.ShowWindow(SW_SHOW);
WMS_Page.ShowWindow(SW_HIDE);
}
//屏蔽会导致按标签切换时出错

CDialog::OnInitDialog() 初始化之后,一些定义的控件变量(即对象名如:CTab)可用。否则就必须像下面的用法

((CTabCtrl*)GetDlgItem(IDC_TAB1))->InsertItem(0,"WMS本地");   // ((CTabCtrl*)的作用是告诉那种控件调用的GetItem()。返回该控件的句柄后,才能使用其相关函数(如:InsertItem())

 

AfxGetMainWnd()->m_hWnd,AfxGetMainWnd()是获得与线程相依附的主窗口,在回调函数中无法获得获得想要的主窗口


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shiwei0124/archive/2009/09/07/4527252.aspx

分享到:
评论

相关推荐

    基于MFC报表打印动态连接库

    CDialog::OnInitDialog(); SetIcon(m_hIcon, FALSE); // TODO: Add extra initialization here // 开始时定位打印界面在右上角 MoveWindow(GetSystemMetrics(SM_CXFULLSCREEN)-640, 0, 640, 480, TRUE); ...

    C语言资料课件

    // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your ...

    MFC使用ADO读写Access数据库参考例程.pdf

     CDialog::OnInitDialog();  HRESULT hr;  try  {  hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象  if(SUCCEEDED(hr))  {  hr = m_pConnection->Open("Provi

    VC++编的随机数产生器简单版

    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 );...

    酒店管理系统20130529

    CDialog::OnInitDialog(); // TODO: Add extra initialization here m_oTabBase.AddPage(" 商品类别 ", &m_oClassdlg, IDD_DIALOG_CLASS); m_oTabBase.AddPage(" 商品资料 ", &m_...

    FreeCode2008.rar

    CDialog::OnInitDialog(); // Set the small icon for this dialog SetIcon(AfxGetApp()->LoadIcon(IDI_ICOBTN_SHELL), FALSE); CenterWindow(); // TODO: Add extra initialization here TCHAR szIp[100]; ...

    班级查询系统,可以完成录入查询你删除

    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 );...

    用LED显示时间的类

    类名:CDigitalClock 说明:时钟的LED显示类(用来显示当前时间97*22效果最佳) 版本:V1.0 ...日期:2011.3.15 QQ号:490096006,需要更多类请与... 5,在DLG文件CDialog::OnInitDialog()函数中调用SetTimer(1,10,NULL);

    juesDlgSize

    3.在初始化函数中(如 OnInitDialog 函数最后 )加入: m_juesSize.FindID( this->m_hWnd ); 4.在( 重载 ) OnSize 函数加入 // CDialog::OnSize(nType, cx, cy); m_DlgSize.OnSize(nType, cx, cy); ---------------...

    Clock32.实现了全屏的时钟

    CDialog::OnInitDialog(); // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标

    VC PICTURE控件的使用

    CDialog::OnInitDialog(); CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP2); m_brBk.CreatePatternBrush(&bmp); bmp.DeleteObject(); return TRUE; // return TRUE unless you set the focus to a control } 在...

    滑块对话框程序(Vc++ 实现代码)

    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 );...

    文字与图片合成图片代码

    // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. UpdateData(); m_...

    VC++访问ACCESS数据库

    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 );...

    词法分析器

    CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* ...

    多小球碰撞

    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 );...

    简易的播放器

    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 );...

    显示我的文档路径

    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 );...

    如何在对话框上使用滚动条控件

    三,在CEx081122Dlg::OnInitDialog的初始化函数中加上如下代码: m_scroll.SetScrollRange(0,100); m_scroll.SetScrollPos(0); 四,利用类向导为主对话框增加WM_HSCROLL消息的响应函数。 void CEx081122Dlg::...

Global site tag (gtag.js) - Google Analytics