我从CStatic继承了新类CMyStatic,同时处理CMyStatic的WM_CREATE消息OnCreate,
但是为什么OnCreate处理函数不进入执行?如何使OnCreate中的代码自动触发?

解决方案 »

  1.   

    对话框设计时,CStatic风格选中Notify,依然不能解决问题:
    全部代码如下:执行时,PreSubclassWindow()可以执行到,但OnCreate偏偏就是不行。
    但我的代码一定要在OnCreate函数中执行的。哪位大虾遇到过同样问题,请指点。class CMyStatic : public CStatic
    {
    public:
    CMyStatic();
    virtual ~CMyStatic(); //{{AFX_VIRTUAL(CMyStatic)
    protected:
    virtual void PreSubclassWindow();
    //}}AFX_VIRTUALprotected:
    //{{AFX_MSG(CMyStatic)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };CMyStatic::CMyStatic()
    {
    }CMyStatic::~CMyStatic()
    {
    }
    BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
    //{{AFX_MSG_MAP(CMyStatic)
    ON_WM_CREATE()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyStatic message handlersvoid CMyStatic::PreSubclassWindow() 
    {
    CStatic::PreSubclassWindow();
    AfxMessageBox("PreSubclassWindow");
    }int CMyStatic::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CStatic::OnCreate(lpCreateStruct) == -1)
    return -1;

    AfxMessageBox("OnCreate"); return 0;
    }
      

  2.   

    CWnd::OnCreate
    This method is called by the framework when an application requests that the Windows CE window be created by calling the Create or CreateEx method. The CWnd object receives this call after the window is created but before it becomes visible. OnCreate is called before the Create or CreateEx method returns. 
      

  3.   

    >>>>> Mackz(在相互)你是不是用你的类来子类化了?当然不行。我是在对话框设计时,把STATIC控件定义为CMyStatic变量。另外,我知道CWnd::OnCreate是CWnd的WM_CREATE处理函数,而且会自动触发,
    可是我想让CStatic的WM_CREATE的CStatic::OnCreate也自动进入。我之所以用CStatic而不用CWnd,是因为CStatic用起来方便,不需要写代码来Create.
      

  4.   

    CWnd::OnCreate
    This method is called by the framework when an application requests that the Windows CE window be created by calling the Create or CreateEx method. The CWnd object receives this call after the window is created but before it becomes visible. OnCreate is called before the Create or CreateEx method returns.
    我是动态生成,然后create的才能处理wm_create,但是如果是资源里面就生成得就不能处理wm_create
    关注解决办法
      

  5.   

    用对话框模板创建的控件好像都不会收到 WM_CREATE 消息。
      

  6.   


    You can initialize your static control object in overrided PresubclassWIndow function.your static control is initialized during dialog initialization ,then is attached to your static control object during the first updatedata call in CDialog::OnInitDialog
      

  7.   

    动态生成create的才能处理wm_create,如果是资源里面生成得就不能处理wm_create.
      

  8.   

    我在资源里找到
     LTEXT           "Static",IDC_fan,251,106,52,38
    可能这个就是初始化,代替了类中的
      

  9.   

    需要自己调用create才可以
    m_MyStatic.Create(_T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, 
                    CRect(10,10,150,50), this);