WBWnd.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:6k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // WBWnd.cpp: implementation of the CWBWnd class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "..WB.h"
- #include "WBWnd.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CWBWnd::CWBWnd( CDrawView * view , bool m_bRect , bool m_bCapture ) : CDraw( view ) , CDialog( IDD_CAPTURE_DIALOG )
- {
- //{{AFX_DATA_INIT(CWBWnd)
- //}}AFX_DATA_INIT
- this->m_bDown = false;
- this->type = WBWND;
- this->screenDC = NULL;
- this->m_bRect = m_bRect;
- if( this->pen.GetSafeHandle( ) )
- this->pen.DeleteObject( );
- this->pen.CreatePen( PS_DOT , 1 , RGB( 0 , 0 , 0 ) );
- if( this->brush.GetSafeHandle( ) )
- this->brush.DeleteObject( );
- this->brush.CreateStockObject( NULL_BRUSH );
- //如果是选择
- if( this->m_bRect )
- {
- ::Sleep( 100 );
- this->DoModal( );
- }
- else if( m_bCapture )
- this->view->SetCapture( );
- }
- CWBWnd::~CWBWnd( )
- {
- }
- void CWBWnd::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CWBWnd)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CWBWnd, CDialog)
- //{{AFX_MSG_MAP(CWBWnd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CWBWnd::OnInitDialog( )
- {
- CDialog::OnInitDialog( );
- ::SetClassLong( this->GetSafeHwnd( ) , GCL_HCURSOR , ( long )::AfxGetApp( )->LoadStandardCursor( MAKEINTRESOURCE( IDC_CROSS ) ) );
- //移动窗口
- this->MoveWindow( 0 , 0 , ::GetSystemMetrics( SM_CXSCREEN ) , ::GetSystemMetrics( SM_CYSCREEN ) );
- //把桌面的的图形捕捉过来
- ::Sleep( 100 );
- CWindowDC dc( CWnd::GetDesktopWindow( ) );
- this->screenDC = new CMemDC( &dc , false );
- return TRUE;
- }
- LRESULT CWBWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch( message )
- {
- case WM_LBUTTONDOWN :
- {
- this->start.x = LOWORD(lParam);
- this->start.y = HIWORD(lParam);
- }
- break;
- case WM_MOUSEMOVE :
- if( wParam & MK_LBUTTON )
- {
- this->end.x = LOWORD(lParam);
- this->end.y = HIWORD(lParam);
- this->Invalidate( );
- }
- break;
- case WM_LBUTTONUP :
- {
- if( this->wndBitmap.GetSafeHandle( ) ) this->wndBitmap.DeleteObject( );
- if( this->wndDC.GetSafeHdc( ) ) this->wndDC.DeleteDC( );
- this->wndDC.CreateCompatibleDC( this->screenDC );
- CRect rc( this->start , this->end );
- this->wndBitmap.CreateCompatibleBitmap( this->screenDC , rc.Width( ) , rc.Height( ) );
- this->wndDC.SelectObject( &this->wndBitmap );
- this->wndDC.BitBlt( 0 , 0 , rc.Width( ) , rc.Height( ) , this->screenDC , rc.left , rc.top , SRCCOPY );
- if( this->rgn.GetSafeHandle( ) )
- this->rgn.DeleteObject( );
- this->rgn.CreateRectRgn( 0 , 0 , rc.Width( ) , rc.Height( ) );
- CPoint point = this->view->GetScrollPosition( );
- this->rgn.OffsetRgn( point );
- delete this->screenDC; this->screenDC = NULL;
- this->SendMessage( WM_CLOSE );
- this->Draw( );
- this->view->Invalidate( );
- ::Sleep( 100 );
- this->view->PostMessage( WM_LBUTTONUP , wParam , MAKEWPARAM( point.x , point.y ) );
- }
- break;
- case WM_PAINT :
- if( this->screenDC )
- {
- CPaintDC dc( this );
- dc.BitBlt( 0 , 0 , ::GetSystemMetrics( SM_CXSCREEN ) , ::GetSystemMetrics( SM_CYSCREEN ) , this->screenDC , 0 , 0 , SRCCOPY );
- if( this->start != this->end )
- {
- CMemDC memDC( &dc );
- CRect rc( this->start , this->end );
- memDC.SelectObject( &this->pen );
- memDC.SelectObject( &this->brush );
- memDC.Rectangle( &rc );
- }
- }
- break;
- case WM_ERASEBKGND :
- return true;
- }
- return CDialog::WindowProc(message, wParam, lParam);
- }
- void CWBWnd::LButtonDown( UINT nFlags , CPoint point )
- {
- }
- void CWBWnd::LButtonUp( UINT nFlags , CPoint point )
- {
- if( ! this->m_bRect )
- {
- this->CaptureBitmap( );
- ::ReleaseCapture( );
- }
- }
- void CWBWnd::MouseMove( UINT nFlags , CPoint point )
- {
- }
- CDC * CWBWnd::Draw( CDC * pDC )
- {
- if( pDC == NULL )
- pDC = this->view->GetMemDC( );
- if( this->rgn.GetSafeHandle( ) )
- {
- CRect rc;
- this->rgn.GetRgnBox( &rc );
- if( ! this->wndDC.GetSafeHdc( ) && this->wndBitmap.GetSafeHandle( ) )
- {
- this->wndDC.CreateCompatibleDC( pDC );
- this->wndDC.SelectObject( &this->wndBitmap );
- }
- pDC->BitBlt( rc.left , rc.top , rc.Width( ) , rc.Height( ) , &this->wndDC , 0 , 0 , SRCCOPY );
- }
- return pDC;
- }
- void CWBWnd::CaptureBitmap( void )
- {
- if( this->wndBitmap.GetSafeHandle( ) )
- this->wndBitmap.DeleteObject( );
- if( this->wndDC.GetSafeHdc( ) )
- this->wndDC.DeleteDC( );
- CPoint point;
- ::GetCursorPos( &point );
- CWnd * pWnd = CWnd::WindowFromPoint( point );
- if( ! pWnd )
- pWnd = CWnd::GetDesktopWindow( );
- CWindowDC dc( pWnd );
- this->wndDC.CreateCompatibleDC( &dc );
- CRect rc;
- pWnd->GetWindowRect( &rc );
- this->wndBitmap.CreateCompatibleBitmap( &dc , rc.Width( ) , rc.Height( ) );
- this->wndDC.SelectObject( &this->wndBitmap );
- this->wndDC.BitBlt( 0 , 0 , rc.Width( ) , rc.Height( ) , &dc , 0 , 0 , SRCCOPY );
- if( this->rgn.GetSafeHandle( ) )
- this->rgn.DeleteObject( );
- this->rgn.CreateRectRgn( 0 , 0 , rc.Width( ) , rc.Height( ) );
- point = this->view->GetScrollPosition( );
- this->rgn.OffsetRgn( point );
- this->Draw( );
- this->view->Invalidate( );
- }
- CBitmap * CWBWnd::GetBitmap( void )
- {
- if( ! this->wndBitmap.GetSafeHandle( ) )
- {
- if( ! this->rgn.GetSafeHandle( ) )
- return NULL;
- CRect rc;
- this->rgn.GetRgnBox( &rc );
- this->wndBitmap.CreateCompatibleBitmap( this->view->GetMemDC( ) , rc.Width( ) , rc.Height( ) );
- }
- return & this->wndBitmap;
- }