본문 바로가기
프로그래밍/라이브러리

[Win32 API] WM_PAINT msg를 사용하지 않고..

by 써드아이 2008. 2. 6.
LRESULT DrawBg( void *Data, HDC BGmemDC, HDC MemDC )
{
HRESULT hr = S_OK;
HBITMAP hOldBitmap = NULL;
PImgInfo pImg = &pAgent->pImg[IMG_ANTENA];
PUserType pUserType = (PUserType) Data;

hOldBitmap = (HBITMAP) SelectObject( MemDC, pImg->bmpImg[pImg->nCurrentImg] );

// TransparentImage( BGmemDC, pImg->Pos.x, pImg->Pos.y, pImg->info.bmWidth, pImg->info.bmHeight,
// MemDC, 0, 0, pImg->info.bmWidth, pImg->info.bmHeight, TRANSPARENT_COLOR );

BitBlt( BGmemDC, pImg->Pos.x, pImg->Pos.y, pImg->info.bmWidth, pImg->info.bmHeight, MemDC, 0, 0, SRCCOPY );

SelectObject( MemDC, hOldBitmap );

return hr;
}

LRESULT DrawTitleImages( void *Data, HDC BGmemDC, HDC MemDC )
{
HRESULT hr = S_OK;
HBITMAP hOldBitmap = NULL;
PImgInfo pImg = &pAgent->pImg[IMG_ANTENA];
PUserType pUserType = (PUserType) Data;

hOldBitmap = (HBITMAP) SelectObject( MemDC, pImg->bmpImg[pImg->nCurrentImg] );

// TransparentImage( BGmemDC, pImg->Pos.x, pImg->Pos.y, pImg->info.bmWidth, pImg->info.bmHeight,
// MemDC, 0, 0, pImg->info.bmWidth, pImg->info.bmHeight, TRANSPARENT_COLOR );

BitBlt( BGmemDC, pImg->Pos.x, pImg->Pos.y, pImg->info.bmWidth, pImg->info.bmHeight, MemDC, 0, 0, SRCCOPY );

SelectObject( MemDC, hOldBitmap );

return hr;
}

LRESULT PaintScreen( void *data, int *func, int nSize )
{
LRESULT hr = S_OK;
HDC hdc;
PAINTSTRUCT ps;
HDC MemDC;

HDC BGmemDC;
HBITMAP hOldBitmap = NULL;
HBITMAP BgBuffer = NULL;

PUserType pUserType = (PUserType) Data;

// 기본 DC 생성
hdc = BeginPaint( hWnd, &ps );
MemDC = CreateCompatibleDC( hdc );

// Double Buffering을 위한 DC 생성
BGmemDC = CreateCompatibleDC( hdc );
BgBuffer = CreateCompatibleBitmap( hdc, pUserType.MaxScreen.x, pUserType.MaxScreen.y );
hOldBitmap = (HBITMAP) SelectObject( BGmemDC, BgBuffer );

for ( int i = 0; i < nSize; i++ )
(*func[i])( data, BGmemDC, MemDC );

// Double Buffering을 위해 생성한 DC를 화면에 출력
BitBlt( hdc, 0, 0, pUserType.MaxScreen.x, pUserType.MaxScreen.y, BGmemDC, 0, 0, SRCCOPY );

// Double Buffering을 위한 DC의 release
SelectObject( BGmemDC, hOldBitmap );
DeleteObject( BgBuffer );
DeleteDC( BGmemDC );

// 기본 DC의 release
DeleteDC( MemDC );
EndPaint( hWnd, &ps );

return hr;
}

이렇게 만들고 각 메세지 처리에서 UI에 적용되어야 하는 부분이 있을 경우
다음과 같이 불러주면 되지 않을까?

func[0] = DrawBg;
func[1] = DrawTitleImages;
func[2] = DrawSomethings;

PaintScreen( (void*) &UserData, func, 3 );

이렇게 하면 WM_PAINT msg의 처리가 거의 필요 없어질 듯 하다.
물론.. 예상이지만...

조만간 실험해봐야지..

지금 생각해보니까 PaintScreen() 함수를 WM_PAINT msg 처리 부분에서 호출하는 것도 괜찮을 듯..