OnInitDialog不起作用MFC [英] OnInitDialog does not work MFC

查看:195
本文介绍了OnInitDialog不起作用MFC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的Appliation我有2个对话框:DialA和DialB



In DialB :: OnInitDialog()我有一些参数初始化,比如SetLimitText等...



当我通过DialA拨打DialB时(通过按下按钮),预设参数设置为DialB :: OninitDialog()确实有效。但是当我从菜单中拨打DialB时一切正常。



i甚至可以通过调试模式一步一步地走,但是当我进入时,前卫不会去断点通过DialA呼叫DialB。



什么是错?我需要DilB:OnInitDialog适用于两者。帮助Plz



CDialB代码(从OP非解决方案复制)

Hello all,

in my Appliation I have 2 Dialogs : DialA and DialB

In The DialB::OnInitDialog() I Have some parameters intialization like SetLimitText etc ...

When I call DialB via DialA (by pressing a buttom) the preparameters set on the DialB::OninitDialog() does work. But when i Call DialB from The Menu All works fine.

i even trie to go step by step via debug mode but the prog don''t go the breakpoints when i Call DialB via DialA.

What is Wrong ? I need that the DilB:OnInitDialog Works for both. Help Plz

Code of CDialB (copied from OP non-solution)

BOOL CDialB::OnInitDialog()
{
    CDialog::OnInitDialog();
    m_Edit_TRIMESTRECTR.SetLimitText(3);
    UpdateData(TRUE);
 
    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}

推荐答案

OnInitDialog()只被调用一次,因此如果它已被调用,则不会再次调用它。每次显示或打开对话框时都有更好的方法。
OnInitDialog() is only called once, so if it was already called, it will not be called again. There are better ways to do something every time a dialog is displayed or opened.


OnInitDialog()仅在首次创建对话框时调用,并且用于加载GUI组件的默认值(和在创建对话框组件之后,你需要做的任何其他事情,但是在对话框的常规操作之前)....说,如果你需要在每次调出对话框时设置一些东西。

$ / b $ b CEdit :: SetLimitText()只需要在对话框和CEdit控件存在期间调用一次,因此在方法OnInitDialog()中调用它是合适的,然而,你真的应该没有理由不断地设置它。



当你制作CDialog时,你可以用两种方式完成它,在开始时做一次应用程序的执行,只需在需要的时候启动它(适合你经常使用的东西),或者你可以随时将它删除并删除它''将要使用它(当内存使用率非常高时适当,但堆分配可能相对较慢,所以请记住这一点)。简单的方法是只需将对话框放在后面并在需要时将其启动,在这种情况下,OnInitDialog()只会在整个应用程序执行期间调用一次。
OnInitDialog() is only called when the dialog is first created and meant to load default values of GUI components (and anything else you need to do AFTER the dialog components have been created but BEFORE the regular operation of the dialog).... with that said, if you need to set something EVERY time you bring up the dialog.

C:SetLimitText() only needs to be called once during the existance of a dialog and the CEdit control, therefore it is appropriate that it''s called in the method OnInitDialog(), however, there really should be no reason for you to continually set it.

When you make a CDialog you can do it in two ways, make it once at the beginning of the application execution and just bring it up when you need it (appropriate for something you''ll constantly use) or you can just make it and delete it every time you''re going to use it (appropriate when memory usage is at a premium, but heap allocations can be relatively slow so keep that in mind). The simple way is to just make the dialog off the back and bring it up when you need it, in that case, OnInitDialog() will only be called once during the entire app execution.


这篇关于OnInitDialog不起作用MFC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆