ACTIVEBU.CPP
上传用户:zhang8947
上传日期:2007-01-08
资源大小:1910k
文件大小:4k
- // activebu.cpp : implementation file
- //
- #include "stdafx.h"
- #include "cspublic.h"
- #include "resource.h"
- #include "basicwin.h"
- #include "basicbut.h"
- #include "systemse.h"
- #include "menubutt.h"
- #include "activebu.h"
- #include "cswin.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CActiveButton
- CActiveButton::CActiveButton()
- {
- }
- CActiveButton::~CActiveButton()
- {
- }
- //初始化动作按钮
- BOOL CActiveButton::InitButton( LPCSTR lpcsName , //窗口名称
- const RECT &rect , //窗口大小
- CWnd *pParent , //父窗口
- UINT uWinID , //窗口ID
- LPCSTR lpcsExeFileName ) //执行文件名
- {
- if( _fstrlen( lpcsExeFileName ) > MAX_FILE_NAME_LEN )
- return 0 ;
- _fstrcpy( m_sExeFileName , lpcsExeFileName ) ;
- m_hIcon =::ExtractIcon( AfxGetApp()->m_hInstance ,
- lpcsExeFileName , 0 ) ; //得到执行文件的ICON
- m_nLeftButtonStatus =0 ; //初始鼠标左键没有按下
- m_bButtonStatus =1 ; //初始按钮是凸的
- //初始化该按钮
- return CBasicButton::InitButton( lpcsName , rect , pParent , uWinID ) ;
- }
- //得到按钮名称
- void CActiveButton::GetName( LPSTR lpsName )
- {
- _fstrcpy( lpsName , m_sExeFileName ) ;
- }
- BEGIN_MESSAGE_MAP(CActiveButton, CBasicButton)
- //{{AFX_MSG_MAP(CActiveButton)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CActiveButton message handlers
- void CActiveButton::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- ((CCsWin*)GetParent())->ButtonDown( this , point ) ; //开始移动
-
- m_nLeftButtonStatus =1 ;
- m_OldDownPoint =point ;
- m_bButtonStatus =0 ; //凹下
- Invalidate() ;
- UpdateWindow() ;
-
- CBasicButton::OnLButtonDown(nFlags, point);
- }
- void CActiveButton::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if( m_nLeftButtonStatus == 1 ) //鼠标左键按下并且没有移动
- {
- m_bButtonStatus =1 ; //凸起
- Invalidate() ;
- UpdateWindow() ;
- ::WinExec( m_sExeFileName , SW_SHOW ) ; //执行该程序
- }
- ((CCsWin*)GetParent())->ButtonUp() ; //停止移动
- m_nLeftButtonStatus =0 ;
- CBasicButton::OnLButtonUp(nFlags, point);
- }
- void CActiveButton::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- switch( m_nLeftButtonStatus )
- {
- case 0:
- CBasicButton::OnMouseMove(nFlags, point);
- return ;
- case 1: //鼠标左键按下并且没有移动
- if( abs(point.x-m_OldDownPoint.x)<3 &&
- abs(point.y-m_OldDownPoint.y)<3 ) //移动距离过小
- break ;
-
- m_nLeftButtonStatus =2 ;
- m_bButtonStatus =1 ; //凸起
- Invalidate() ;
- UpdateWindow() ;
- case 2:
- //移动窗口
- ((CCsWin*)GetParent())->MoveWindowToNewPos( this , point ) ;
- break ;
- }
- CWnd::OnMouseMove(nFlags, point);
- }
- void CActiveButton::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- RECT rect ;
- GetClientRect( &rect ) ; //得到大小
- rect.right-- ;
- rect.bottom-- ;
- DrawOneLineBox( dc.m_hDC , rect , m_bButtonStatus ,
- RGB(255,255,255),RGB(128,128,128),RGB(192,192,192) ) ; //画上底色
- //画上执行程序的ICON
- CDC MemDC ;
- MemDC.CreateCompatibleDC( &dc ) ;
- CBitmap Bitmap ;
- Bitmap.CreateCompatibleBitmap( &dc , 32 , 32 ) ;
- CBitmap *pOldBitmap =(CBitmap*)(MemDC.SelectObject(
- &Bitmap ) ) ;
- //浅灰刷
- CBrush LowGrayBrush( RGB( 192 , 192 , 192 ) ) ;
- CBrush *pOldBrush =MemDC.SelectObject( &LowGrayBrush ) ;
- MemDC.PatBlt( 0 , 0 , 32 , 32 , PATCOPY ) ; //背景色
- MemDC.SelectObject( pOldBrush ) ;
-
- MemDC.DrawIcon( 0 , 0 , m_hIcon ) ; //把ICON画到内存DC中
-
- dc.StretchBlt( (rect.right-16)/2 , 1 ,
- 16 , 16 ,
- &MemDC , 0 , 0 , 32 , 32 , SRCCOPY ) ;
- MemDC.SelectObject( pOldBitmap ) ;
-
- // Do not call CBasicButton::OnPaint() for painting messages
- }