创建两个CWnd对象pwnd 和pwnd2,将其Create()出来,分别标注为A和B。根据下面的代码,A和B将部分重叠,且B在A之上。但当点击重叠部分时,响应点击的却是A而非B。即使添加代码C1和C2,重设置Z-order或用CWnd::SetForegroundWindow(),
CWnd::SetFocus()也不行。
  BOOL CXXXDlg::OnInitDialog()
  {
         ...... CRect rect(50,50,100,100);
pwnd=new CWnd;
pwnd->Create("Button",NULL,WS_VISIBLE|WS_CHILD,rect,this,0);
pwnd->SetWindowText(" A ");
//   pwnd->SetWindowPos(&wndBottom ,50,50,50,50,  SWP_DRAWFRAME ) ;      // C1 CRect rect2(75,50,125,100);
pwnd2=new CWnd;
pwnd2->Create("Button",NULL,WS_VISIBLE|WS_CHILD,rect2,this,0);
pwnd2->SetWindowText(" B ");
//   pwnd2->SetWindowPos(&wndTopMost , 75,50,50,50, SWP_DRAWFRAME);       // C2
  }怎样才能实现点击重叠部分时,B响应点击???

解决方案 »

  1.   

    我能看出的问题就是,你创建的窗口ID号怎么相同了都是0,
    pwnd2->Create("Button",NULL,WS_VISIBLE|WS_CHILD,rect2,this,0);
    两个窗口的ID号好像不可以相同啊
      

  2.   

    pwnd2->SetFocus();也替我看看:
    http://expert.csdn.net/Expert/topic/1404/1404676.xml?temp=.4430963
      

  3.   

    pwnd2->SetFocus();好象不行吧??
      

  4.   

    to: hnyyy(前进) 
    >>pwnd2->SetFocus(); // that's a mistake.To:  eEric(Paranoia)
    你可能犯了一個和hnyyy(前进) 一樣的小錯誤。
    according to msdn: CWnd::SetFocus
    "Call this member function to claim the input focus. The input focus directs all subsequent keyboard input to this window. Any window that previously had the input focus loses it.""If the current window is active but does not have the focus (that is, no window has the focus), any key pressed will produce the messages WM_SYSCHAR, WM_SYSKEYDOWN, or WM_SYSKEYUP. "So, try pwnd->SetFocus(); // not pwnd2 in the case.
      

  5.   

    oops, I made a mistake.
    sorry to: hnyyy(前进). 
      

  6.   

    是的,原来重叠部分由TABORDER决定,大致可以这样:
    void CYourDlg::OnButton1() 
    {
    GetDlgItem(IDC_BUTTON1)->BringWindowToTop();

    }void CYourDlg::OnButton2() 
    {
    GetDlgItem(IDC_BUTTON2)->BringWindowToTop();}这样就可以保证以后显示最前的能获得消息。然而最初显示时TABORDER在前的,却显示在下面。以致第一次有点问题,你自己解决吧。
      

  7.   

    to:  eEric(Paranoia) 
    如果只想b在a上﹐ 可以用WS_POPUP。
    pwnd2->CreateEx(NULL, "Button", NULL, WS_VISIBLE|WS_CHILD|WS_POPUP, rect2, this, 0);
      

  8.   

    又来看看,楼上:WS_POPUP能与WS_CHILD共存?
      

  9.   

    这个程序只是一个用来说明问题的例子,再真实的程序中,我是用了继承自CWnd
    的派生类产生对象,存在同样的问题。
    我只想让在上边的子窗体响应点击.
      

  10.   

    CRect rect(50,50,100,100);
    pwnd=new CWnd;
    pwnd->Create("Button",NULL,WS_VISIBLE|WS_CHILD,rect,this,1425);
    pwnd->SetWindowText(" A ");
    //   pwnd->SetWindowPos(&wndBottom ,50,50,50,50,  SWP_DRAWFRAME ) ;      // C1 CRect rect2(75,50,125,100);
    pwnd2=new CWnd;
    pwnd2->Create("Button",NULL,WS_VISIBLE|WS_CHILD,rect2,this,1426);
    pwnd2->SetWindowText(" B ");
       pwnd->SetWindowPos(pwnd2 , 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
      

  11.   

    只发现pwnd->SetWindowPos 时的参数中多了个 SWP_NOMOVE ,这样就能达到目的了?不过 masterz(MS MVP) 怎么说也是五颗星应该不会乱写的。。
      

  12.   

    at least in my test program it works.
    the difference is not only SWP_NOMOVE, but the HWND hWndInsertAfter parameter.