CEdit :: SetWindowText();创建后在播放之前 [英] CEdit::SetWindowText(); After its creation & before diplaying it

查看:122
本文介绍了CEdit :: SetWindowText();创建后在播放之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SetWindowText函数用一些文本初始化CEdit控件.最好的选择是之后其创建& 之前显示在屏幕上.

我选择了WM_CREATE消息处理程序( OnCreate )来处理此初始化,不幸的是,这个消息处理程序从未被调用过!

我在这里需要一些帮助;(

I want to initialize a CEdit control with some text using SetWindowText function. The best plase to do that is After its creation & Before it is displayed to the screen.

I have chosen WM_CREATE message handler (OnCreate) to handle this initialization, & unfortunately no chance, this message handler has never been invoked!

I need some help here ;(

推荐答案

对于模板创建的控件,永远不会调用OnCreate(),因为控件是在CWnd包装器之前创建并附加的由DoDataExchange().

正如Maximilien已经指出的那样,初始化控件的常用位置是对话框的OnInitDialog()和视图的OnInitialUpdate().

如果需要自初始化控件,则可以使用该控件的PreTranslateMessage(),对该控件进行子类化(请参见_Superman_的注释)或动态创建控件.
For template created controls, OnCreate() is never called, because the controls get created before the CWnd wrappers and are attached by DoDataExchange().

As already noted by Maximilien, the usual places to initialize controls are OnInitDialog() for dialogs and OnInitialUpdate() for views.

If you need a self-initializing control, you may use PreTranslateMessage() of the control, subclassing the control (see comment from _Superman_), or dynamically create controls.


至少,有两个可能的条目:):
At least, there are two possible entries :) :
class CBothContextableEdit : public CEdit
{
  //...

protected:
  virtual void PreSubclassWindow() {
    CEdit::PreSubclassWindow();
    SetWindowText(_T("test"));
  }
  
  afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct) {
    int iResult(CEdit::OnCreate(lpCreateStruct));
    if (GetSafeHwnd()) {
      SetWindowText(_T("test"));
    }
    return iResult;
  }

  DECLARE_MESSAGE_MAP()
};


如果编辑控件在对话框中,则必须在OnInitDialog方法中进行初始化.
如果认为编辑窗口在视图中(例如,对于CFormView),那么我认为(已经有一段时间了),可以在OnInitialUpdate方法中进行操作.

M.
If the edit control is in a dialog, initialization must be done in the OnInitDialog method.

If the edit window is in a view (for example in the case of the CFormView), I think (it''s been a while), you can do it in the OnInitialUpdate method.

M.


这篇关于CEdit :: SetWindowText();创建后在播放之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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