• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

在屏幕上作图

发布: 2007-7-01 20:40 | 作者: admin | 来源: | 查看: 21次 | 进入软件测试论坛讨论

领测软件测试网

建立一个透明的窗体:

class CMyWnd : public CWnd 
{
public:
 void CreateMyWnd(LPCTSTR pTitle,RECT &rect);
 CMyWnd();
public:
// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CTransparentWnd)
 public:
 //}}AFX_VIRTUAL
  
  // Implementation
 public:
  afx_msg void OnRefresh();
  
  virtual ~CMyWnd();
 protected:
  // Generated message map functions
protected:
 //{{AFX_MSG(CTransparentWnd)
    afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
 afx_msg void OnExit();

 afx_msg void OnSet();
 afx_msg void OnExitAll();
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()

private:
 CPoint m_pt;
};

#endif // !defined(AFX_MYWND_H__9C4F7859_0D5B_4801_9FE3_401BBC31591C__INCLUDED_)

#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

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);
}

开始:

void CPage1::OnStart()
{
 AfxGetMainWnd()->ShowWindow(SW_HIDE);
 
 UpdateData(); //更新变量,以便在CMyWnd中使用

 pWnd = new CMyWnd;
 CRect rect(0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CXFULLSCREEN));
 pWnd->CreateMyWnd("", rect);       
 pWnd->ShowWindow(SW_SHOW);
 pWnd->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
 
}

具体内容请参考源代码。

 


文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网