SaverWindow.cpp
上传用户:qdhuadeli
上传日期:2007-02-07
资源大小:978k
文件大小:5k
- // SaverWindow.cpp : implementation file
- //
- #include "stdafx.h"
- #include "multiscreen.h"
- #include "SaverWindow.h"
- #include "multimon.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSaverWindow
- CSaverWindow::CSaverWindow()
- {
- }
- CSaverWindow::~CSaverWindow()
- {
- }
- BEGIN_MESSAGE_MAP(CSaverWindow, CWnd)
- //{{AFX_MSG_MAP(CSaverWindow)
- ON_WM_CREATE()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // Following Code taken from Ben Bryant's Smoov Saver. A great saver!
- BOOL CSaverWindow::Create( HWND hwndParent )
- {
- // Register a class with no cursor.
- const char* pszClassName
- = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS|CS_DBLCLKS,NULL);
- #ifdef _DEBUG
- DWORD dwExStyle = 0;
- #else
- DWORD dwExStyle = WS_EX_TOPMOST;
- #endif
- DWORD dwStyle = WS_POPUP | WS_VISIBLE;
- m_bPreview = FALSE;
- if ( hwndParent )
- {
- // Get dimensions of preview window
- ::GetClientRect( hwndParent, &rect );
- dwExStyle = 0;
- dwStyle = WS_CHILD | WS_VISIBLE;
- m_bPreview = TRUE;
- }
- else
- {
- rect.left = ::GetSystemMetrics( SM_XVIRTUALSCREEN );
- rect.top = ::GetSystemMetrics( SM_YVIRTUALSCREEN );
- rect.right = rect.left + ::GetSystemMetrics( SM_CXVIRTUALSCREEN );
- rect.bottom = rect.top + ::GetSystemMetrics( SM_CYVIRTUALSCREEN );
- }
- return CWnd::CreateEx( dwExStyle, pszClassName, "", dwStyle,
- rect.left, rect.top, rect.Width(), rect.Height(), hwndParent, NULL );
- }
- LRESULT CSaverWindow::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
- {
- static int i = 0;
- static PAINTSTRUCT ps = {NULL};
- static HDC hDC = NULL;
- static HBRUSH hBrush = NULL;
- static UINT uTimer = 0;
- static int xpos, ypos;
- static RECT rc;
- static BOOL bHere = FALSE;
- static POINT ptLast;
- POINT ptCursor, ptCheck;
- CRect rectWnd;
- switch ( nMsg )
- {
- case WM_SYSCOMMAND:
- if ( (wParam == SC_SCREENSAVE) || (wParam == SC_CLOSE) )
- return FALSE;
- break;
- case WM_ERASEBKGND:
- GetClientRect(&rectWnd);
- FillRect( (HDC)wParam, &rectWnd, m_hBackgroundBrush );
- break;
- case WM_SETCURSOR:
- if ( ! m_bPreview )
- SetCursor( NULL );
- break;
- case WM_NCACTIVATE:
- if ( ! m_bPreview )
- if ( wParam == FALSE )
- return FALSE;
- break;
- case WM_ACTIVATE:
- case WM_ACTIVATEAPP:
- if ( m_bPreview )
- break;
- if ( wParam != FALSE )
- break;
- // Only fall through if we are losing the focus...
- case WM_MOUSEMOVE:
- if ( m_bPreview )
- break;
- if( ! bHere )
- {
- GetCursorPos( &ptLast );
- bHere = TRUE;
- }
- else
- {
- GetCursorPos( &ptCheck );
- ptCursor.x = ptCheck.x - ptLast.x;
- ptCursor.y = ptCheck.y - ptLast.y;
- if ( ptCursor.x < 0 )
- ptCursor.x *= -1;
- if ( ptCursor.y < 0 )
- ptCursor.y *= -1;
- if ( (ptCursor.x + ptCursor.y) > 5 )
- PostMessage( WM_CLOSE, 0, 0 );
- }
- break;
- case WM_RBUTTONDOWN:
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDOWN:
- if ( m_bPreview )
- break;
- GetCursorPos( &ptCursor );
- ptCursor.x ++;
- ptCursor.y ++;
- SetCursorPos( ptCursor.x, ptCursor.y );
- GetCursorPos( &ptCheck );
- if ( ptCheck.x != ptCursor.x && ptCheck.y != ptCursor.y )
- ptCursor.x -= 2;
- ptCursor.y -= 2;
- SetCursorPos( ptCursor.x, ptCursor.y );
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- if ( m_bPreview )
- break;
- PostMessage(WM_CLOSE, 0, 0l);
- break;
- }
- return CWnd::WindowProc(nMsg, wParam, lParam);
- }
- ///////////////////Back to my own work//////////////////////
- ///////
- int CSaverWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- m_hBackgroundBrush = CreateSolidBrush(RGB(20, 23, 126));
- GetClientRect( &m_rect );
- // m_ae.SetScreen( m_rect );
- return 0;
- }
- void CSaverWindow::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CPoint myPoint;
- myPoint = rect.CenterPoint();
- // TODO: Add your message handler code here
- CDC* pDC = GetDC();
- CSaverWindow scrWnd;
- CRect textRect;
- //textRect.CenterPoint() = rect.CenterPoint();
- textRect.top = (rect.top);
- textRect.left = (rect.left);
- pDC->DrawIcon(myPoint,AfxGetApp()->LoadStandardIcon(IDI_QUESTION));
- pDC->DrawText("This will show on all monitors!",textRect,NULL);
- // Do not call CWnd::OnPaint() for painting messages
- }