배경화면에서 텍스트가 위에서 아래로 이동하기
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc, memdc; PAINTSTRUCT ps; static HBITMAP hBit, oldBit; static RECT rectView; static int yPos; TCHAR word[] = _T("대한민국화이팅");
switch (iMsg) { case WM_CREATE: yPos = -30; GetClientRect(hwnd, &rectView); SetTimer(hwnd, 1, 10, NULL); hBit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2)); break; case WM_TIMER: yPos += 1; if (yPos > rectView.bottom) yPos = -30; InvalidateRgn(hwnd, NULL, TRUE); return 0; case WM_PAINT: GetClientRect(hwnd, &rectView); hdc = BeginPaint(hwnd, &ps); memdc = CreateCompatibleDC(hdc); oldBit = (HBITMAP)SelectObject(memdc, hBit); BitBlt(hdc, 0, 0, 1024, 768, memdc, 0, 0, SRCCOPY); SelectObject(memdc, oldBit); DeleteDC(memdc); TextOut(hdc, 200, yPos, word, _tcslen(word)); EndPaint(hwnd, &ps); break; case WM_DESTROY: DeleteObject(hBit); KillTimer(hwnd, 1); PostQuitMessage(0); break; } return DefWindowProc(hwnd, iMsg, wParam, lParam); } |
실행 결과]
더블 버퍼링을 이용하여 배경화면에 움직이는 텍스트 만들기
void TextPrint(HDC hdc, int x, int y, TCHAR text[]) { int i, j; SetTextColor(hdc, RGB(255, 255, 255)); for (i = -1; i <= 1; i++) for (j = -1; j <= 1; j++) TextOut(hdc, x + i, y + j, text, _tcslen(text)); SetTextColor(hdc, RGB(0, 0, 0)); TextOut(hdc, x, y, text, _tcslen(text)); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static HDC hdc, mem1dc, mem2dc; PAINTSTRUCT ps; static HBITMAP hBit1, hBit2, oldBit1, oldBit2; static RECT rectView; static int yPos; TCHAR word[] = _T("대한민국화이팅");
switch (iMsg) { case WM_CREATE: yPos = -30; GetClientRect(hwnd, &rectView); SetTimer(hwnd, 1, 70, NULL); hBit2 = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2)); break; case WM_TIMER: yPos += 5; if (yPos > rectView.bottom) yPos = -30; InvalidateRgn(hwnd, NULL, TRUE); return 0; case WM_PAINT: GetClientRect(hwnd, &rectView); hdc = BeginPaint(hwnd, &ps); mem1dc = CreateCompatibleDC(hdc); mem2dc = CreateCompatibleDC(mem1dc); if (hBit1 == NULL) hBit1 = CreateCompatibleBitmap(hdc, 530, 530); oldBit1 = (HBITMAP)SelectObject(mem1dc, hBit1); oldBit2 = (HBITMAP)SelectObject(mem2dc, hBit2); BitBlt(mem1dc, 0, 0, 530, 530, mem2dc, 0, 0, SRCCOPY); SetBkMode(mem1dc, TRANSPARENT); TextPrint(mem1dc, 200, yPos, word); BitBlt(hdc, 0, 0, 530, 530, mem1dc, 0, 0, SRCCOPY); SelectObject(mem1dc, oldBit1); SelectObject(mem2dc, oldBit2); DeleteDC(mem2dc); DeleteDC(mem1dc); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: if (hBit1) DeleteObject(hBit1); DeleteObject(hBit2); KillTimer(hwnd, 1); PostQuitMessage(0); break; } return DefWindowProc(hwnd, iMsg, wParam, lParam); } |
실행 결과]
'프로그램언어 > C++' 카테고리의 다른 글
대화상자만들기 (0) | 2020.12.23 |
---|---|
ROP모드로 이미지 마스크 설정 (0) | 2020.12.22 |
API 비트맵 (0) | 2020.09.28 |
API 단축키 (0) | 2020.09.28 |
공용 대화상자 사용하기2 (0) | 2020.09.25 |