今天调试程序中发现怪事 我用SetParent函数传递窗体1的Picture1到窗体2的Picture2中 传递后Picture2显示的控件操作都没问题,但今天像text、combo等控件都无法输入或操作了只有command有效,百思不得其解。请各位高手老大给点良方!

解决方案 »

  1.   


    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
                                                    ByVal hWndNewParent As Long) As Long
    Private Sub Command1_Click()
      Form2.Show
      SetParent Text1.hWnd, Form2.hWnd
    End Sub
      

  2.   

    问题依旧没有解决,不过谢谢zsj1101。
      

  3.   

    An  edit,  list  box,  or  combo  box  control  sends  notifications  to  the  original  parent  window  even  after  SetParent  has  been  used  to  change  the  control's  parent.  A  button  control  sends  notifications  to  the  new  parent  after  SetParent  has  been  used  to  change  its  parent.    
     
    Edit,  list  box,  and  combo  box  controls  keep  a  private  copy  of  the  window  handle  of  the  parent  at  the  time  of  creation.  This  handle  is  not  changed  when  SetParent  is  used  to  change  the  control's  parent.  Consequently,  the  notifications  (EN_*,  LBN_*,  and  CBN_*  notifications)  go  to  the  original  parent.    
     
    Note  that  WM_PARENTNOTIFY  messages  go  to  the  new  parent  and  GetParent()  returns  the  new  parent.  If  it  is  required  that  notifications  go  to  the  new  parent  window,  code  must  be  added  to  the  old  parent's  window  procedure  to  pass  on  the  notifications  to  the  new  parent.  
    谁能翻译一下
      

  4.   

    textbox,listbox,combobox控件在使用SetParent改变控件的Parent属性时,把通知送至原来的父窗口,而commandbox控件把通知送至新的父窗口。
    textbox,listbox,combobox控件在创建时保存了一个父窗口句柄的备份,使用SetParent是无法改变控件的Parent属性的,因此,通知(EN_*,  LBN_*,  and  CBN_*  notifications)被送到了原父窗口。
    注释:送消息WM_PARENTNOTIFY 到新的父窗口,GetParent返回新的父窗口,假如你想要传递通知到新的父窗口,你必须给原来的父窗口添加代码以传递通知到新的父窗口。
    唉!挣点分真不容易呀