mythread.cpp

来自「这个是我们学校用的VC++教案」· C++ 代码 · 共 67 行

CPP
67
字号
// MyThread.cpp : implementation file
//

#include "stdafx.h"
#include "TestThread.h"
#include "MyThread.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyThread

IMPLEMENT_DYNCREATE(CMyThread, CWinThread)

CMyThread::CMyThread()
{
}

CMyThread::~CMyThread()
{
}

int xyPos=-100;  // 窗口左上角坐标
BOOL CMyThread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	int i,increment=0;
	xyPos=xyPos+100; // 窗口坐标,使启动的每个用户界面线程窗口处于不同位置
	CRect ThrRect;  // 用户区域
	CRect WndRect(xyPos,xyPos,300+xyPos,320+xyPos);  // 窗口区域
	CFrameWnd* pFrameWnd= new CFrameWnd();
	pFrameWnd->Create(NULL,"Thread Window",WS_OVERLAPPEDWINDOW,WndRect);
	pFrameWnd->ShowWindow(SW_SHOW);
	pFrameWnd->UpdateWindow();
	pFrameWnd->GetClientRect(ThrRect);  // 得到用户区域
	CClientDC ClientDC(pFrameWnd);  // 获取当前窗口用户区域的设备环境
	for(i=0;i<1000;i++)
	{
		increment++;
		if(increment>ThrRect.bottom/2)
			increment=0;
		ClientDC.Ellipse(ThrRect.right/2-increment, ThrRect.bottom/2-increment,
						   ThrRect.right/2+increment, ThrRect.bottom/2+increment);
		Sleep(50);
	}
	return TRUE;
}

int CMyThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
	//{{AFX_MSG_MAP(CMyThread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyThread message handlers

⌨️ 快捷键说明

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