大家好:
   
     在继承CEdit控件写了一个自义消息(userMesage),当KeyUp响应时就发送userMessage消息。
但,需要把该控件用在对话框中,怎样才能把userMessage消息在对话框也能使用(消息在外部可见)?请多多指教,在线急等!!
   

解决方案 »

  1.   

    窗口子类化,你看看SubClassWindow(**)这个函数,应该就可以了
      

  2.   

    SubclassWindow( HWND hWnd )是CWnd的成员函数,封状好了的,你只要把你控件的hWnd传过去就可以了呀,很简单的
      

  3.   

    Up,SubclassWindow(this->GetSafeHwnd())放大哪里调呢?
      

  4.   

    给你个例子吧:
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
    {
    if ( CMDIFrameWnd::OnCreateClient(lpcs, pContext) )
    {
    m_wndMDIClient.SubclassWindow(m_hWndMDIClient);
    return TRUE;
    }
    else
    return FALSE;

    就在你消息里写就可以了
      

  5.   

    // EditCls.cpp : implementation file
    //#include "stdafx.h"
    #include "Project1.h"
    #include "EditCls.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // EditClsEditCls::EditCls()
    {
    SubclassWindow(this->GetSafeHwnd());
    }EditCls::~EditCls()
    {
    }
    BEGIN_MESSAGE_MAP(EditCls, CEdit)
    //{{AFX_MSG_MAP(EditCls)
    ON_WM_KEYUP()
    ON_MESSAGE(WM_USER_KEYUPS, OnKeyUps)
    //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // EditCls message handlersvoid EditCls::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default

    SendMessage(WM_USER_KEYUPS);
    CEdit::OnKeyUp(nChar, nRepCnt, nFlags);}void EditCls::OnKeyUps(WPARAM wParam,LPARAM lParm)
    {
    this->SubclassWindow(this->GetSafeHwnd());
       AfxMessageBox("Hello");
    }
      

  6.   

    OnKeyUps是与WM_USER_KEYUPS相关的函数
      

  7.   

    调用SubClassWindow(...)不是this指针,因为你是要使它能在对话框里使用,所以你必须要用到对话框的对象来调用SubClassWindow(...),这个函数的作用你还是很模糊,它是让其他窗口拥有用户自定义的消息,所以必须是要获得其他窗口的指针来调用它
      

  8.   

    比如说你对CEdit重写为CMyEdit,那么你就在CEdit类的OnInitDialog()函数中调用它:
    CMyEdit m_edit;
    m_edit.SubClassWindow(GetDlgItem(IDC_EDIT)->m_hWnd);
    这样就OK了;
      

  9.   

    多谢指教,那我还得传一个对话框的hwnd进来对吗?
      

  10.   

    zhihong123能不能交个朋友啊,
    QQ:516681534
      

  11.   

    捕获对话框的消息,进行特殊处理,再操作CEdit
    可能对话框把消息给捕获了,而不是CEdit