本人在CToolBar上添加了一个Edit控件:
class CMyEdit:public CEdit
{
....
};// 注释 在CMainFrame中有两个成员变量:CEdit m_MyEdit;CMyEdit m_EnhancedEdit;
//我想用m_EnhancedEdit 对m_MyEdit进行子类型化!
BOOL CMainFrame::CreateMyEdit()
{
  WS_BORDER;
  int index=0;
  CRect rect;
  //首先在工具栏上找到要加入edit的位置(事先是一个什么事都不做的按钮:ID_EDIT_TEST)
  while(this->m_wndToolBar.GetItemID(index)!=ID_EDIT_TEST)
index++;
  //修改按钮的属性为分隔条,并扩展按钮的长度为120,
  this->m_wndToolBar.SetButtonInfo(index,ID_EDIT_TEST,TBBS_SEPARATOR,120);
  //获得位置
  this->m_wndToolBar.GetItemRect(index,&rect);
  
  //创建,我不知道如何用AfxRegisterClass()注册我自己的CMyEdit窗口,
  //所以我创建了一个标准的CEdit,我用窗口的字类型化来迂回地达到目的!
  if(!this->m_MyEdit.CreateEx(WS_EX_CLIENTEDGE  ,"EDIT",NULL,
WS_CHILD|WS_VISIBLE|
WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT,
rect,&this->m_wndToolBar, IDC_MY_EDIT))
{
return false;
}
  this->m_MyEdit.ShowWindow(SW_SHOW);
  return true;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.....
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;      // fail to create
} if(!this->CreateMyEdit())
  return -1;
// The following codes is wrong? why? 
this->m_EnhancedEdit.SubclassDlgItem(IDC_EDIT_TEST,&this->m_wndToolBar);
.....

return 0;
}例外,我想用AfxRegisterWndClass ()重新注册一个类似CEdit风格的加强版窗口时,系统却告诉我早已经注册了,,我如何注册呢?------我必须注册!!
-------------------------------
哎分太多,不知道怎么用了!!

解决方案 »

  1.   

    难道SubclassDlgItem()只能在对话框中使用??
      

  2.   

    那位高手知道如何给自己在工具栏上添加的edit 控件添加消息映射??
    本人将给200分!
      

  3.   

    我初学C语言,请各位高手帮忙做两个题:
    1:
    编一程序,建立有20个关键字表,并把该结果存入"KEY.DAT"中.要求采用二维数组方式.
    2:能把从终端读入的一个字符串中的小写字母全部转换成大写字母,然后输出到一个磁盘文件"TEST"中保存,并在屏幕上输出转换之后的字符串.(用惊叹号字符!表示输入字符的结束)
       万分感谢大家了。
      

  4.   

    int CPersonToolBar::CreateToolBar(CWnd *pParent)
    {
      int index=0;
      CRect rect;
      
      if (!this->CreateEx(pParent, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !this->LoadToolBar(IDR_MAINFRAME))
    {
    MessageBox("Failed to create toolbar\n");
    return -1;      // fail to create
    }  while(this->GetItemID(index)!=IDC_INDICATOR)
    index++;
      this->SetButtonInfo(index,IDC_INDICATOR,TBBS_SEPARATOR,120);
      this->GetItemRect(index,&rect);
     
      if(!this->m_wndEdit.CreateEx(WS_EX_CLIENTEDGE  ,
    "EDIT",
    NULL,
    WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT,
    rect,
    this, IDC_TOOLBAR_EDIT))
      return -1;
     //下面的代码有问题,是不是我的子类型化的地方不对?
      //this->m_wndSearchEdit.SubclassWindow(m_wndEdit.m_hWnd); 
      this->m_wndEdit.ShowWindow(SW_SHOW);
      return 0;
    }
      

  5.   

    现在的问题是:
    如何既能使用CEdit::CreateEx()
    又能使添加消息CEdit  WM_CHAR!
    我已经知道了如何在父窗口通过ON_Notification( id, memberFxn )
    响应消息:
    ON_EN_CHANGE 
    ON_EN_ERRSPACE
    ON_EN_HSCROLL   
    等等!
    但是我如何跟踪我键入的每一个字符呢?我想也只能添加消息WM_CHAR
    或者用PreTranslateMessage()
      

  6.   

    干嘛要subclass? 直接用m_EnhancedEdit来创建那个edit框不就完了吗?
      

  7.   

    怎么创建?
    怎么使用CreateEx()创建!
      

  8.   

    BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL);LPCTSTR lpszClassName:怎么写
      

  9.   

    我要:WS_EX_CLIENTEDGE  风格的EDit
      

  10.   

    GetWindowLong(...,GWL_WNDPROC)
    SetWindowLong(...,GWL_WNDPROC)
      

  11.   

    不幸的,
    那时创建CEdit 对象!
      

  12.   

    你要创建的不就是Edit对象吗?只不过窗口风格不同而已。
      

  13.   

    siphonelee(sifone)说得对,GetWindowLong和SetWindowLong
      

  14.   

    实际上我想创建CMyEdit 对象,并且我想用CreateEx()
    创建!
    但是不知道在函数CreateEx()如何指定classname
    so I create a CEdit object ! and I wanna use subclasswindow()to bind it to CMyEdit!
    But I failed!
    why?
      

  15.   

    我知道你想创建CMyEdit对象,所以我让你用_T("edit")作classname参数。你的CMyEdit和CEdit的唯一区别就在于WS_EX_CLIENTEDGE风格,所以你直接指定这个参数就行了。----------------------也许我没有理解你的意思?至于subclass的问题,换成SubclassWindow试试。
      

  16.   

    而且直接用CMyEdit,WM_CHAR的问题就迎刃而解了。
      

  17.   

    Game is over!
    给分!
    int CPersonToolBar::CreateToolBar(CWnd *pParent)
    {
      int index=0;
      CRect rect;
      
      if (!this->CreateEx(pParent, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !this->LoadToolBar(IDR_MAINFRAME))
    {
    MessageBox("Failed to create toolbar\n");
    return -1;      // fail to create
    }  while(this->GetItemID(index)!=IDC_INDICATOR)
    index++;
      this->SetButtonInfo(index,IDC_INDICATOR,TBBS_SEPARATOR,120);
      this->GetItemRect(index,&rect);
     
      //use the style :ES_MULTILINE to enable the RETURN key!
      if(!this->m_wndSearchEdit.Create(
    WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN |WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT,
    rect,this,IDC_TOOLBAR_EDIT))
      return -1;
      
      //关键代码修改部分
      //Modify the window style to be 3D style!
      long dwStyle=::GetWindowLong(this->m_wndSearchEdit.m_hWnd,GWL_STYLE);
      dwStyle=dwStyle|WS_EX_CLIENTEDGE;
      ::SetWindowLong(this->m_wndSearchEdit.m_hWnd,GWL_EXSTYLE,dwStyle);
     
      return 0;
    }
    ------------------------
    void CSearchEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
      CString strTemp,str;
      str="Begin searching the string : ";
      GetWindowText(strTemp);
      CEdit::OnChar(nChar, nRepCnt, nFlags);
    if(nChar==VK_RETURN&&strTemp!="")
    {
      str+=strTemp;
      MessageBox(str);
    }
    //enable the edit box anyway!
    SetFocus();
    }
    --------------------
    虽然不能使用子类型化
    但是问题还是解决了!
    谢谢楼上的各位高手的关注!
    向各位学习!
    南京 扬子石化
    [email protected]