API 더블 버퍼링
글쓴이: nathaniel7687 / 작성시간: 월, 2012/01/30 - 6:32오후
코드가 좀 생략 됬어요 필수적인 것만 적어놓음 ㅎㅎ
=========================================== main.cpp =========================================== //글로벌(exturn 변수로 사용) HWND hWnd; HINSTANCE hInst; HDC hdc; HDC MemDC, StaDC; HBITMAP MyBit; int Cha_x, Cha_y; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 메뉴의 선택 영역을 구문 분석합니다. switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: onCreate(hWnd,wParam,lParam); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); onPaint(wParam,lParam); EndPaint(hWnd, &ps); break; case WM_TIMER: onTimer(wParam,lParam); break; case WM_MOUSEMOVE: onMouseMove(wParam,lParam); break; case WM_LBUTTONDOWN: onLButtonDown(wParam,lParam); break; case WM_LBUTTONUP: onLButtonUp(wParam,lParam); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } =========================================== onCreate.cpp =========================================== void onCreate(HWND hWnd,WPARAM wParam, LPARAM lParam) { srand(time(NULL)); SetTimer(hWnd, 1, 10, NULL); MyBit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)); } =========================================== onTimer.cpp =========================================== void onTimer(WPARAM wParam, LPARAM lParam) { InvalidateRect(hWnd, NULL, FALSE); } =========================================== onTimer.cpp =========================================== exturn void DrawBitmap(int x, int y, HBITMAP Bit); HBITMAP OldBit; HPEN MyPen, OldPen; HBRUSH MyBrush, OldBrush; void onPaint(WPARAM wParam, LPARAM lParam) { RECT crt; hdc = GetDC(hWnd); //글씨 및 그리기를 할 도화지 GetClientRect(hWnd, &crt); FillRect(MemDC, &crt, GetSysColorBrush(COLOR_WINDOW)); FillRect(StaDC, &crt, GetSysColorBrush(COLOR_WINDOW)); // hdc에 그려 주기 위해 필요한 MemDC MemDC = CreateCompatibleDC( hdc ); StaDC = CreateCompatibleDC( hdc ); //onCreate에서 명령 >> MyBit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)); OldBit = (HBITMAP)SelectObject(StaDC, MyBit); BitBlt(MemDC, Cha_x, Cha_y, 25, 25, StaDC, 0, 0, SRCCOPY); DrawBitmap(0, 0, MyBit); SelectObject(hdc, OldBit); DeleteDC( StaDC ); DeleteDC( MemDC ); ReleaseDC(hWnd, hdc); } void DrawBitmap(int x, int y, HBITMAP Bit) { HBITMAP OldBitmap; BITMAP bit; int bx, by; //MemDC = CreateCompatibleDC( hdc ); OldBitmap = (HBITMAP)SelectObject( MemDC, Bit ); GetObject( Bit, sizeof(BITMAP), &bit ); bx = bit.bmWidth; by = bit.bmHeight; BitBlt( hdc, x, y, bx, by, MemDC, 0, 0, SRCCOPY ); SelectObject( MemDC, OldBitmap ); DeleteDC( MemDC ); ReleaseDC( hWnd, hdc ); }
제가 의도 한것은
1. 우선 My Bit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));로드 한다음
2. FillRect로 흰색 배경을 StaDC랑 MemDC에 만든뒤
3. StaDC에 특정 부위에만 그림을 그린다.
4. 그리고 흰색으로 칠해진 MemDC에 StaDC를 뿌린다.
5. 그러면 화면에 표현하고자 깔끔하게 정리된 상태인 MemDC를 DrawBitmap함수를 이용해 hdc에 뿌린다.
그런데 ...... 적용이 안되네요 ㅠㅠ
Forums:
댓글 달기