1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <Windows.h>
#include <tchar.h>
#include <Library.h>
LRESULT CALLBACK WndProc( HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam );
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE
prevInstance, LPWSTR cmdLine, int cmdShow) {
UNREFERENCED_PARAMETER( prevInstance );
UNREFERENCED_PARAMETER( cmdLine );
WNDCLASSEX wndClass = { 0 };
wndClass.cbSize = sizeof( WNDCLASSEX );
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = hInstance;
wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndClass.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = L"DX11BOOKWINDOWCLASS";
if( !RegisterClassEx( &wndClass ) )
return -1;
RECT rc = { 0, 0, 640, 480 };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Blank Win32 Window",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
rc.bottom - rc.top, NULL, NULL, hInstance, NULL );
if( !hwnd )
return -1;
ShowWindow( hwnd, cmdShow );
//Demo Initialize
MSG msg = { 0 };
while( msg.message !=WM_QUIT );
{
if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage ( &msg );
}
//UPDATE
//DRAW
}
//Demo Shutdown
return static_cast<int>( msg.wParam );
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT paintStruct;
HDC hDC;
BITMAP bm;
HDC device = GetDC(hwnd);
HBITMAP image = (HBITMAP)LoadImage(0, L"image2.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if (!image)
DWORD err = GetLastError();
GetObject(image, sizeof(BITMAP), &bm);
switch ( message )
{
case WM_PAINT:
{
RECT rt;
GetClientRect( hwnd, &rt );
hDC = BeginPaint( hwnd, &paintStruct );
HDC hdcImage = CreateCompatibleDC( device );
SelectObject( hdcImage, image );
BitBlt(device, rt.left, rt.top, bm.bmWidth, bm.bmHeight,
hdcImage, 0, 0, SRCCOPY);
DeleteDC(hdcImage);
EndPaint( hwnd, &paintStruct );
break;
}
case WM_DESTROY:
DeleteObject((HBITMAP)image);
ReleaseDC(hwnd, device);
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
|