#include #include #include #include #pragma comment( lib, "user32.lib" ) #pragma comment( lib, "gdi32.lib" ) #define SCRW 640 #define SCRH 480 uint32_t scrbuf[ SCRW * SCRH ]; LRESULT window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { if( msg == WM_CLOSE ) { DestroyWindow( hwnd ); } else if( msg == WM_DESTROY ) { PostQuitMessage( 0 ); } return DefWindowProc( hwnd, msg, wparam, lparam ); }; int main( int argc, char* argv[] ) { // register window class WNDCLASS wc = { CS_CLASSDC, window_proc }; wc.lpszClassName = TEXT( "MyClassName" ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); RegisterClass( &wc ); // create window HWND hwnd = CreateWindow( wc.lpszClassName, TEXT( "Window Title" ), WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, SCRW, SCRH, NULL, NULL, NULL, NULL ); // make sure we update at least every 16ms SetTimer( NULL, 0, 16, NULL ); bool exit = false; while( !exit ) { // windows message handling MSG msg; while( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) { if( msg.message == WM_QUIT ) exit = true; TranslateMessage( &msg ); DispatchMessage( &msg ); } // display our screenbuffer BITMAPINFOHEADER bmi = { sizeof( bmi ), SCRW, -SCRH, 1, 32 }; HDC dc = GetDC( hwnd ); SetDIBitsToDevice( dc, 0, 0, SCRW, SCRH, 0, 0, 0u, SCRH, scrbuf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS ); ReleaseDC( hwnd, dc ); // plot random pixels in our buffer int x = rand() % SCRW; int y = rand() % SCRH; uint32_t c = ( rand() << 15 ) | rand(); // random rgb color scrbuf[ x + y * SCRW ] = c; } return 0; }