⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 childviewrx.cpp

📁 本文件包包含了大量用VC++开发的应用程序界面
💻 CPP
字号:
// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "Redraw.h"
#include "ChildViewRx.h"

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

#define		ONESECOND		1000
#define		ONEMINUTE		(60 * ONESECOND)

CSemaphore	g_sem (1, 1, "JAMSA MEDIA");

const char *szFileEvent = {"JAMSA"};
const char *szMemFile = {"JAMSAFILE"};

struct THREADPARMS
	{
	HANDLE	hevMemFile;
	HANDLE	hevDieMoFo;
	CChildView	*Papa;
	};
THREADPARMS parms;


/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
{
	m_dwThread = 0;
	m_hevDieMoFo = CreateEvent (NULL, TRUE, FALSE, NULL);
	m_hevMemFile = OpenEvent (EVENT_ALL_ACCESS, TRUE, szFileEvent);
	if (m_hevDieMoFo == NULL)
		AfxMessageBox ("Terminate event is NULL");
	if (m_hevMemFile == NULL)
		AfxMessageBox ("MemFile event is NULL");
	parms.hevDieMoFo = m_hevDieMoFo;
	parms.hevMemFile = m_hevMemFile;
	parms.Papa = this;
	::CreateThread (NULL, 0, StartUpdateThread, (LPVOID) &parms, 0, &m_dwThread);
}

CChildView::~CChildView()
{
}

BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	ON_WM_DESTROY()
	ON_MESSAGE(WM_USER+40, OnUser)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CWnd::OnPaint() for painting messages
}

void CChildView::OnDestroy() 
{
	CWnd ::OnDestroy();
	SetEvent (m_hevDieMoFo);
}

DWORD WINAPI CChildView::StartUpdateThread(void *pParam)
{
HANDLE	hWaitFor [2];
DWORD	dwSignal;
THREADPARMS parms;

	memcpy (&parms, (THREADPARMS *) pParam, sizeof (THREADPARMS));
	hWaitFor [0] = parms.hevMemFile;
	hWaitFor [1] = parms.hevDieMoFo;
	if (hWaitFor[0] == NULL)
	{
		AfxMessageBox ("hevMemFile is null");
		return (-1);
	}
	if (hWaitFor[1] == NULL)
	{
		AfxMessageBox ("hevDieMoFo is null");
		return (-1);
	}
	for (;;)
	{
		dwSignal = WaitForMultipleObjects (2, hWaitFor, FALSE, INFINITE);
		switch (dwSignal)
		{
			case WAIT_OBJECT_0:			// Memory file event
				::SendMessage (parms.Papa->m_hWnd, WM_USER+40, (WPARAM) (WM_USER+40), (LPARAM) 0);
				break;
			case WAIT_OBJECT_0 + 1:		// Terminate
				return (0);
			case WAIT_TIMEOUT:
				continue;
		}
	}
	return (0);
}

void CChildView::OnUser(WPARAM wparam, LPARAM lparam)
{
BYTE	*b;

	CSingleLock semLock (&g_sem);
	semLock.Lock();
	m_hMap = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, szMemFile);
	if (m_hMap != NULL)
		m_sfBuf = (BYTE *) MapViewOfFile (m_hMap, FILE_MAP_READ, 0, 0, 0);
	else
		m_sfBuf = NULL;
	if (m_sfBuf == NULL)
	{
		AfxMessageBox ("File mapping failed");
		return;
	}
	b = m_sfBuf;
	CWindowDC dc(this);
	int nPoints = (int) *b;

	b += sizeof (int);
	POINT ptStart = (POINT) (*((POINT*)b));
	for (int i = 1; i < nPoints; ++i)
	{
	POINT pt;

		pt = (POINT) (*((POINT*)b));
		dc.SetPixel (pt, (COLORREF) 0);
		b += sizeof (POINT);
		DoMouseLine (dc, ptStart, pt);
		ptStart = pt;
	}
	semLock.Unlock ();
}

void CChildView::DoMouseLine(CWindowDC &dc, POINT &ptLineStart, POINT &ptLineEnd)
{
CPen    *penOld, Pen;

    Pen.CreatePen (PS_SOLID, 2, (COLORREF) 0x00ffffff);
    int nOldMode = dc.SetROP2 (R2_XORPEN);// R2_NOT);
    dc.MoveTo (ptLineStart);
    penOld = dc.SelectObject (&Pen);
    dc.LineTo (ptLineEnd);
    dc.SetROP2 (nOldMode);
    dc.SelectObject (penOld);
    Pen.DeleteObject ();
	Pen.CreatePen (PS_SOLID, 1, (COLORREF) 0x0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -