?? background.cpp
字號:
#include "StdAfx.h"
#include ".\background.h"
BackGround::BackGround(HWND hWnd)
{
m_hWnd = hWnd;
RECT rect;
GetClientRect(hWnd, &rect);
m_iWidth = rect.right - rect.left;
m_iHeight = rect.bottom - rect.top;
for (int i = 0; i < STAR_NUMBER; ++i)
{
m_ptStar[i].x = rand() % m_iWidth;
m_ptStar[i].y = rand() % m_iHeight;
m_cColor[i] = 128;
}
}
BackGround::~BackGround(void)
{
}
void BackGround::Update()
{
for (int i = 0; i < STAR_NUMBER; ++i)
{
if (rand() % TWINKLE_DELAY ==0)
m_cColor[i] = rand() % 256;
if (m_ptStar[i].y > m_iHeight)
m_ptStar[i].y = 0;
else
m_ptStar[i].y += SCROLL_VELOCITY;
}
}
void BackGround::Draw(HWND hWnd, HDC hDC)
{
// RECT rect = {0, 0, m_iWidth, m_iHeight};
RECT rect;
GetClientRect(hWnd, &rect);
// 繪制黑色背景
HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hDC, &rect, hBrush);
DeleteObject(hBrush);
// 繪制星星
for (int i = 0; i < STAR_NUMBER; ++i)
{
SetPixel(hDC, m_ptStar[i].x, m_ptStar[i].y,
RGB(m_cColor[i], m_cColor[i], m_cColor[i]));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -