1. 화면 확대( CreateDC, StretchBlt )
2. Cards.dll 에서 그림 꺼내오기~
3. 내가 만든 Resource DLL 에서 문자열 빼오기
4. 더블버퍼링의 기초( Timer를 사용하여 키보드로 사각형 움직이기 BitBlt 복사위치만 +x , +y 해주면 된다. )
more..
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_LBUTTONDOWN:
SetCapture(hwnd);
return 0;
case WM_LBUTTONUP:
if( GetCapture() == hwnd )
ReleaseCapture();
return 0;
case WM_MOUSEMOVE:
{
//POINTS pt = MAKEPOINTS( lParam );
POINT pt;
GetCursorPos( &pt );
HDC scr = CreateDC( "DISPLAY", 0, 0, 0 );
HDC hdc = GetDC(hwnd);
StretchBlt( hdc, 0, 0, 500, 500,
scr, pt.x, pt.y, 100, 100,
SRCCOPY );
// BitBlt( hdc, 0, 0, 500, 500, // Dest dc
// scr, 0, 0, // Source dc
// SRCCOPY ); // Raster Code
ReleaseDC( hwnd, hdc );
DeleteDC( scr );
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}
{
switch( msg )
{
case WM_LBUTTONDOWN:
SetCapture(hwnd);
return 0;
case WM_LBUTTONUP:
if( GetCapture() == hwnd )
ReleaseCapture();
return 0;
case WM_MOUSEMOVE:
{
//POINTS pt = MAKEPOINTS( lParam );
POINT pt;
GetCursorPos( &pt );
HDC scr = CreateDC( "DISPLAY", 0, 0, 0 );
HDC hdc = GetDC(hwnd);
StretchBlt( hdc, 0, 0, 500, 500,
scr, pt.x, pt.y, 100, 100,
SRCCOPY );
// BitBlt( hdc, 0, 0, 500, 500, // Dest dc
// scr, 0, 0, // Source dc
// SRCCOPY ); // Raster Code
ReleaseDC( hwnd, hdc );
DeleteDC( scr );
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}
2. Cards.dll 에서 그림 꺼내오기~
more..
// 카드 DLL를 Load 한다.
HMODULE hDll = LoadLibrary( "Cards.dll" );
if( hDll == 0 )
{
MessageBox( 0, "Dll을 Load 할 수 없습니다.", "", MB_OK );
return 0;
}
// DLL에서 카드 그림을 꺼낸다.
HBITMAP hBitmap = (HBITMAP)LoadBitmap( hDll, MAKEINTRESOURCE(3) );
HBRUSH brush = CreatePatternBrush( hBitmap );
DeleteObject( hBitmap );
wc.hbrBackground = brush; //(HBRUSH)GetStockObject( WHITE_BRUSH );
HMODULE hDll = LoadLibrary( "Cards.dll" );
if( hDll == 0 )
{
MessageBox( 0, "Dll을 Load 할 수 없습니다.", "", MB_OK );
return 0;
}
// DLL에서 카드 그림을 꺼낸다.
HBITMAP hBitmap = (HBITMAP)LoadBitmap( hDll, MAKEINTRESOURCE(3) );
HBRUSH brush = CreatePatternBrush( hBitmap );
DeleteObject( hBitmap );
wc.hbrBackground = brush; //(HBRUSH)GetStockObject( WHITE_BRUSH );
3. 내가 만든 Resource DLL 에서 문자열 빼오기
more..
// 리소스 DLL을 Load해서 필요한 문자열을 얻어온다.
HMODULE hDll = LoadLibrary("DllResource.dll");
char buf[256];
LoadString(hDll, 102, buf, 256);
HMODULE hDll = LoadLibrary("DllResource.dll");
char buf[256];
LoadString(hDll, 102, buf, 256);
4. 더블버퍼링의 기초( Timer를 사용하여 키보드로 사각형 움직이기 BitBlt 복사위치만 +x , +y 해주면 된다. )
more..
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hBitmap;
static int x, y;
switch( msg )
{
case WM_CREATE:
{
// 가상화면을 사용 할 비트맵을 만든다.
HDC hdc = GetDC( hwnd );
hBitmap = CreateCompatibleBitmap( hdc, 1280, 1024 );
ReleaseDC( hwnd, hdc );
HDC mem = CreateCompatibleDC( 0 );
HBITMAP old = (HBITMAP)SelectObject( mem, hBitmap );
// 흰색으로 채워놓는다.
PatBlt( mem, 0, 0, 1280, 1024, WHITENESS );
SelectObject( mem, old );
DeleteObject( mem );
SetTimer( hwnd, 1, 50, 0 );
}
return 0;
case WM_TIMER:
if ( wParam == 1 )
{
if ( GetAsyncKeyState( VK_UP) < 0 )
{
y += 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
if ( GetAsyncKeyState( VK_DOWN) < 0 )
{
y -= 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
if ( GetAsyncKeyState( VK_LEFT) < 0 )
{
x += 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
if ( GetAsyncKeyState( VK_RIGHT) < 0 )
{
x -= 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
}
return 0;
/*
case WM_KEYDOWN:
switch( wParam )
{
case VK_UP: y += 4; break;
case VK_DOWN: y -= 4; break;
case VK_LEFT: x += 4; break;
case VK_RIGHT: x -= 4; break;
default: return 0;
}
InvalidateRect( hwnd, 0, FALSE );
return 0;
*/
case WM_LBUTTONDOWN:
{
POINTS pt = MAKEPOINTS( lParam );
HDC hdc = GetDC( hwnd );
Rectangle( hdc, pt.x, pt.y, pt.x + 50, pt.y + 50 );
ReleaseDC( hwnd, hdc );
// 다시 그리기 위해 좌표를 저장한다.
HDC mem = CreateCompatibleDC( 0 );
HBITMAP old = (HBITMAP)SelectObject( mem, hBitmap );
Rectangle( mem, pt.x, pt.y, pt.x + 50, pt.y + 50 );
SelectObject( mem, old );
DeleteObject( mem );
}
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwnd, &ps );
// 비트맵을 출력한다.
HDC mem = CreateCompatibleDC( 0 );
HBITMAP old = (HBITMAP)SelectObject( mem, hBitmap );
RECT rc = ps.rcPaint;
BitBlt( hdc, rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top, mem, rc.left+x, rc.top+y, SRCCOPY );
SelectObject( mem, old );
DeleteObject( mem );
//////////////////////////////////////////////////////////////////////////
EndPaint( hwnd, &ps );
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}
{
static HBITMAP hBitmap;
static int x, y;
switch( msg )
{
case WM_CREATE:
{
// 가상화면을 사용 할 비트맵을 만든다.
HDC hdc = GetDC( hwnd );
hBitmap = CreateCompatibleBitmap( hdc, 1280, 1024 );
ReleaseDC( hwnd, hdc );
HDC mem = CreateCompatibleDC( 0 );
HBITMAP old = (HBITMAP)SelectObject( mem, hBitmap );
// 흰색으로 채워놓는다.
PatBlt( mem, 0, 0, 1280, 1024, WHITENESS );
SelectObject( mem, old );
DeleteObject( mem );
SetTimer( hwnd, 1, 50, 0 );
}
return 0;
case WM_TIMER:
if ( wParam == 1 )
{
if ( GetAsyncKeyState( VK_UP) < 0 )
{
y += 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
if ( GetAsyncKeyState( VK_DOWN) < 0 )
{
y -= 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
if ( GetAsyncKeyState( VK_LEFT) < 0 )
{
x += 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
if ( GetAsyncKeyState( VK_RIGHT) < 0 )
{
x -= 4; InvalidateRect(hwnd, 0, FALSE);
InvalidateRect(hwnd, 0, FALSE );
}
}
return 0;
/*
case WM_KEYDOWN:
switch( wParam )
{
case VK_UP: y += 4; break;
case VK_DOWN: y -= 4; break;
case VK_LEFT: x += 4; break;
case VK_RIGHT: x -= 4; break;
default: return 0;
}
InvalidateRect( hwnd, 0, FALSE );
return 0;
*/
case WM_LBUTTONDOWN:
{
POINTS pt = MAKEPOINTS( lParam );
HDC hdc = GetDC( hwnd );
Rectangle( hdc, pt.x, pt.y, pt.x + 50, pt.y + 50 );
ReleaseDC( hwnd, hdc );
// 다시 그리기 위해 좌표를 저장한다.
HDC mem = CreateCompatibleDC( 0 );
HBITMAP old = (HBITMAP)SelectObject( mem, hBitmap );
Rectangle( mem, pt.x, pt.y, pt.x + 50, pt.y + 50 );
SelectObject( mem, old );
DeleteObject( mem );
}
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwnd, &ps );
// 비트맵을 출력한다.
HDC mem = CreateCompatibleDC( 0 );
HBITMAP old = (HBITMAP)SelectObject( mem, hBitmap );
RECT rc = ps.rcPaint;
BitBlt( hdc, rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top, mem, rc.left+x, rc.top+y, SRCCOPY );
SelectObject( mem, old );
DeleteObject( mem );
//////////////////////////////////////////////////////////////////////////
EndPaint( hwnd, &ps );
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}