当前位置: 首页>>代码示例>>C++>>正文


C++ Ball::Attach方法代码示例

本文整理汇总了C++中Ball::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ Ball::Attach方法的具体用法?C++ Ball::Attach怎么用?C++ Ball::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ball的用法示例。


在下文中一共展示了Ball::Attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WndProc

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static DWORD st = 0;
	static DWORD dt = 0;
	static DWORD update_dt = 0;
	static DWORD update_delay = 10;

	static HDC hMainDC = NULL;
	static HDC hMemDC = NULL;
	static HBITMAP hMemBitmap = NULL;
	static HBITMAP hOldMemBitmap = NULL;

	static Point ptStart;
	static Point ptEnd;
	static bool bDrawLine = false;

	static std::list<Ball*> marble;
	static const int quantity = 4;

	if (uMsg == WM_CREATE)
	{
		Rect rc;
		::GetClientRect(hWnd, &rc);

		hMainDC = ::GetDC(hWnd);
		hMemDC = ::CreateCompatibleDC(hMainDC);
		hMemBitmap = ::CreateCompatibleBitmap(hMainDC, rc.width(), rc.height());
		hOldMemBitmap = ::Select(hMemDC, hMemBitmap);
				
		for (int i = 0; i < quantity; i++)
		{
			Ball* pBall = new Ball;
			pBall->Attach(hWnd);
			pBall->SetSize(15);

			if (i == Ball::white)
			{
				pBall->SetPosition(Point((rc.right - rc.left)/8 * 1, (rc.bottom - rc.top)/2));
				pBall->SetColor(RGB(255,255,255));
			}
			else if (i == Ball::red1)
			{
				pBall->SetPosition(Point((rc.right - rc.left)/8 * 2, (rc.bottom - rc.top)/2));
				pBall->SetColor(RGB(255,0,0));
			}
			else if (i == Ball::red2)
			{
				pBall->SetPosition(Point((rc.right - rc.left)/8 * 6, (rc.bottom - rc.top)/2));
				pBall->SetColor(RGB(255,0,0));
			}			
			else if (i == Ball::yellow)
			{
				pBall->SetPosition(Point((rc.right - rc.left)/8 * 6, (rc.bottom - rc.top)/6 * 2));
				pBall->SetColor(RGB(255,255,0));
			}

			marble.push_back(pBall);
		} // for (int i = 0; i < quantity; i++)

		st = ::GetTickCount();
		::SetTimer(hWnd, 0, 10, NULL);

		return 0;
	}
	else if (uMsg == WM_DESTROY)
	{
		std::list<Ball*>::iterator it;
		for (it = marble.begin(); it != marble.end();)
		{
			delete *it;
			it = marble.erase(it);
		}

		::KillTimer(hWnd, 0);

		::Select(hMemDC, hOldMemBitmap);
		::DeleteObject(hMemBitmap);
		::DeleteDC(hMemDC);
		::ReleaseDC(hWnd, hMainDC);

		::PostQuitMessage(0);

		return 0;
	}
	else if (uMsg == WM_PAINT)
	{
		Rect rc;
		::GetClientRect(hWnd, &rc);

		PAINTSTRUCT ps;
		HDC hdc = ::BeginPaint(hWnd, &ps);

		::SetDCBrushColor(hMemDC, RGB(80,181,53));
		::FillRect(hMemDC, &rc, (HBRUSH)::GetStockObject(DC_BRUSH));

		if (bDrawLine)
		{
			::MoveToEx(hMemDC, ptStart.x, ptStart.y, NULL);
			::LineTo(hMemDC, ptEnd.x, ptEnd.y);
		}
//.........这里部分代码省略.........
开发者ID:brobambi,项目名称:Homework,代码行数:101,代码来源:winproc.cpp

示例2: WndProc

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static DWORD st = 0;
	static DWORD dt = 0;
	static DWORD update_dt = 0;
	static DWORD update_delay = 20;
	static HDC hMainDC = NULL;
	static HDC hMemDC = NULL;
	static HBITMAP hMemBitmap = NULL;
	static HBITMAP hOldMemBitmap = NULL;

	static bool bDrawLine = false;
	static Point ptStart;
	static Point ptEnd;

	if (uMsg == WM_CREATE)
	{
		Rect rc;
		::GetClientRect(hWnd, &rc);

		hMainDC = ::GetDC(hWnd);
		hMemDC = ::CreateCompatibleDC(hMainDC);
		hMemBitmap = ::CreateCompatibleBitmap(hMainDC, rc.width(), rc.height());
		hOldMemBitmap = ::Select(hMemDC, hMemBitmap);

		BallDepot.Attach(hWnd);

		st = ::GetTickCount();
		::SetTimer(hWnd, 1, 10, NULL);
		return 0;
	}
	else if (uMsg == WM_DESTROY)
	{
		BallDepot.clear();

		::KillTimer(hWnd, 1);

		::Select(hMemDC, hOldMemBitmap);
		::DeleteObject(hMemBitmap);
		::DeleteDC(hMemDC);
		::ReleaseDC(hWnd, hMainDC);

		::PostQuitMessage(0);
		return 0;
	}
	else if (uMsg == WM_PAINT)
	{
		Rect rc;
		::GetClientRect(hWnd, &rc);

		PAINTSTRUCT ps;
		HDC hdc = ::BeginPaint(hWnd, &ps);

		// TODO
		::SetDCBrushColor(hMemDC, RGB(100,100,150));
		::FillRect(hMemDC, &rc, (HBRUSH)::GetStockObject(DC_BRUSH));

		if (bDrawLine)
		{
			::MoveToEx(hMemDC, ptStart.x, ptStart.y, NULL);
			::LineTo(hMemDC, ptEnd.x, ptEnd.y);
		}

		BallDepot.Draw(hMemDC);

		::BitBlt(hdc, 0, 0, rc.width(), rc.height(),
			hMemDC, 0, 0, SRCCOPY);

		::EndPaint(hWnd, &ps);
		return 0;
	}
	else if (uMsg == WM_ERASEBKGND)
	{
		return 1;
	}
	else if (uMsg == WM_LBUTTONDOWN)
	{
		::GetCursorPos(&ptStart);
		ptStart = ptStart.ToClient(hWnd);
		ptEnd = ptStart;

		bDrawLine = true;

		return 0;
	}
	else if (uMsg == WM_MOUSEMOVE)
	{
		if (bDrawLine)
		{
			::GetCursorPos(&ptEnd);
			ptEnd = ptEnd.ToClient(hWnd);

			Rect rc;
			::GetClientRect(hWnd, &rc);
			::InvalidateRect(hWnd, &rc, TRUE);
		}

		return 0;
	}
	else if (uMsg == WM_LBUTTONUP)
//.........这里部分代码省略.........
开发者ID:soulpaper,项目名称:SGA48.3,代码行数:101,代码来源:winproc.cpp


注:本文中的Ball::Attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。