如何固定子窗口的层次,不受鼠标点击子窗时层次变化?

解决方案 »

  1.   

    请看图,可以解决。Dialog1.h头文件#if !defined(AFX_DIALOG1_H__219A3285_6999_47A6_9064_66A70CAC0CCA__INCLUDED_)
    #define AFX_DIALOG1_H__219A3285_6999_47A6_9064_66A70CAC0CCA__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // Dialog1.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CDialog1 dialogclass CDialog1 : public CDialog
    {
    // Construction
    public:
    CDialog1(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CDialog1)
    enum { IDD = IDD_DIALOG1 };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    BOOL m_bDraging;
    CPoint m_ptDrag;
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDialog1)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CDialog1)
    afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOG1_H__219A3285_6999_47A6_9064_66A70CAC0CCA__INCLUDED_)
      

  2.   

    Dialog1.cpp源文件//代码是我写的随便测试的代码,比较乱,你可以参照修改一下即可。// Dialog1.cpp : implementation file
    //#include "stdafx.h"
    #include "wpc.h"
    #include "Dialog1.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CDialog1 dialog
    CDialog1::CDialog1(CWnd* pParent /*=NULL*/)
    : CDialog(CDialog1::IDD, pParent)
    {
    m_bDraging = FALSE;
    //{{AFX_DATA_INIT(CDialog1)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }
    void CDialog1::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDialog1)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CDialog1, CDialog)
    //{{AFX_MSG_MAP(CDialog1)
    ON_WM_MOUSEACTIVATE()
    ON_WM_LBUTTONDOWN()
    ON_WM_MOUSEMOVE()
    ON_WM_LBUTTONUP()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CDialog1 message handlersint CDialog1::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) 
    {
    // TODO: Add your message handler code here and/or call default
    return MA_NOACTIVATE;
    return CDialog::OnMouseActivate(pDesktopWnd, nHitTest, message);
    }void CDialog1::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    m_bDraging = TRUE;
    m_ptDrag = point;
    SetCapture(); CString str;
    str.Format( _T("被点击时间 %s"),CTime::GetCurrentTime().Format( _T("%H:%M:%S") ) );
    SetDlgItemText( IDC_MOUSE,str );

    CDialog::OnLButtonDown(nFlags, point);
    }void CDialog1::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    if( m_bDraging )
    {
    CWnd * pParent = this;//GetParent();
    if( pParent )
    {
    CRect rc;
    pParent->GetWindowRect( rc );
    GetParent()->ScreenToClient( rc ); CRect rcWorkArea;
    SystemParametersInfo( SPI_GETWORKAREA,0,&rcWorkArea,0 ); int nScreenWidth = GetSystemMetrics( SM_CXSCREEN );
    int nScreenHeight = GetSystemMetrics( SM_CYSCREEN ); //任务栏在左边
    if( rcWorkArea.left > 0 )
    {
    }
    //任务栏在上边
    else if( rcWorkArea.top > 0 )
    {
    }
    //任务栏在下边
    else if( rcWorkArea.Height() < nScreenHeight )
    {
    CPoint ptCursor;
    GetCursorPos( &ptCursor );
    if( ptCursor.y < rcWorkArea.Height() )
    pParent->MoveWindow( rc.left + ( point.x - m_ptDrag.x ),rc.top + ( point.y - m_ptDrag.y ),rc.Width(),rc.Height() );
    }
    //任务栏在右边
    else if( rcWorkArea.Width() < nScreenWidth )
    {
    }
    CWnd * pWnd = GetParent();
    // if( pWnd )
    // pWnd->RedrawWindow();
    }
    //TRACE(_T("CFrameUI::OnMouseMove\r\n") );
    }

    CDialog::OnMouseMove(nFlags, point);
    }void CDialog1::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    m_bDraging = FALSE;
    ReleaseCapture();

    CDialog::OnLButtonUp(nFlags, point);
    }
      

  3.   

    处理窗口的 WM_ACTIVATE 消息,判断 LOWORD(wParam),如果是
    WA_ACTIVE 或 WA_CLICKACTIVE 则使用 SetWindowPos 重新设置 Z Order
      

  4.   

    楼上说的方法应该也行,不过我建议SetWindowPos 放在WM_WINDOWPOSCHANING消息处理函数中,我没有具体测试过。
      

  5.   

    我用的是Child子窗,用SetWindowPos不行。zhllxt能把你的例子发给我试一下吗?
      

  6.   

    例子下载地址:http://img.my.csdn.net/uploads/201204/13/wpc.jpg
    下载后请将文件扩展名改为RAR,VC6的工程。
      

  7.   

    貌似下载不了,我用我的网盘给你下:
    可下载数:20 共享链接:http://163.fm/X4zPZfw 提取码:WXdDfjSJ
      

  8.   

    请用新地址:可下载数:20 共享链接:http://163.fm/N9fobyr 提取码:vaqlzOzg
      

  9.   

    用了zhllxt的例子是可以,现在有个新的问题是如何拖动窗口大小呢?
      

  10.   

    请参照:http://blog.csdn.net/visualeleven/article/details/6600135