www.gusucode.com > 超酷的VC++屏幕作图(电子画笔)程序源码程序 > 超酷的VC++屏幕作图(电子画笔)程序源码程序\code\Class\MyWnd.cpp

    //*****************************************************************
//
//                 主程序
//                          李建湘制作
//                        2002.12.12
//
//*****************************************************************
// Download by http://www.NewXing.com          			  //
// MyWnd.cpp: implementation of the CMyWnd class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyWnd.h"
#include "..\Page.h"
#include "..\PageDlg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMyWnd::CMyWnd()
{
	
}

CMyWnd::~CMyWnd()
{
	
}
BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
//{{AFX_MSG_MAP(CTransparentWnd)
	ON_WM_RBUTTONDOWN()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_COMMAND(IDC_EXIT,OnExit)
	ON_COMMAND(IDC_SET,OnSet)
	ON_COMMAND(IDC_REFRESH,OnRefresh)
	ON_COMMAND(IDC_EXIT_ALL,OnExitAll)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

 

void CMyWnd::CreateMyWnd(LPCTSTR pTitle,RECT &rect)
{   
	//建立窗口
	CreateEx(WS_EX_TRANSPARENT,  //透明
		AfxRegisterWndClass(0,AfxGetApp()->LoadCursor(IDC_PEN)),
		pTitle,
		WS_POPUP,
		rect,
		NULL,
		NULL,
		NULL ); 
}

void CMyWnd::OnRButtonDown(UINT nFlags, CPoint point)
{  
	CMenu m_menu;
	m_menu.LoadMenu(IDR_MENU1);	
	
	ClientToScreen(&point);
	CMenu *psub = (CMenu *)m_menu.GetSubMenu(1); 
	psub->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this);
	m_menu.DestroyMenu();

	CWnd::OnRButtonDown(nFlags, point);
}

void CMyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{	
	m_pt=point;		
	CWnd::OnLButtonDown(nFlags, point);	
}


void CMyWnd::OnMouseMove(UINT nFlags, CPoint point) 
{	
	if(nFlags & MK_LBUTTON)
	{		
		CClientDC dc(this);
		
		CPen pen(
					((CPageDlg*)AfxGetMainWnd())->m_page1.m_nPenStyle,
					((CPageDlg*)AfxGetMainWnd())->m_page1.m_nPenWidth,
					((CPageDlg*)AfxGetMainWnd())->m_page1.m_PenColor
				);
		CPen* pOldPen=dc.SelectObject (&pen);

		dc.MoveTo (m_pt.x,m_pt.y);
		dc.LineTo (point.x,point.y);

		m_pt=point;
		dc.SelectObject (pOldPen);
	}
	
	CWnd::OnMouseMove(nFlags, point);
}



void CMyWnd::OnExit()	//结束画图
{  	
	::SendMessage(GetSafeHwnd(),WM_CLOSE,0,0);
	((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd =NULL;
	delete ((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd;

	AfxGetMainWnd()->ShowWindow( 
		((CPageDlg*)AfxGetMainWnd())->m_page1.m_bMinimized? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
}

void CMyWnd::OnSet()    //设置
{
	::SendMessage(GetSafeHwnd(),WM_CLOSE,0,0);
	((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd =NULL;
	delete ((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd;
	AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL);
	
}

void CMyWnd::OnRefresh()	//重新开始
{
	if(((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd !=NULL)
	{
		((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd->ShowWindow(SW_HIDE);
		((CPageDlg*)AfxGetMainWnd())->m_page1.pWnd->ShowWindow(SW_SHOWNORMAL);
	}
}

void CMyWnd::OnExitAll()  //退出程序
{
	if(MessageBox("确实要退出吗?","屏幕作图",MB_YESNO|MB_ICONQUESTION)==IDYES)
		AfxGetMainWnd()->SendMessage(WM_CLOSE,0,0);
}