Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Comment every line of code to express your understanding of what this line of co

ID: 3835152 • Letter: C

Question

Comment every line of code to express your understanding of what this line of code is intended to do

#include<windows.h>
#include<memory>
#include"KeyboardDemo.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 = "DX11BookWindowClass";

if( !RegisterClassEx( &wndClass ) )
return -1;

RECT rc = { 0, 0, 640, 480 };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );

HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Keyboards in Direct3D 11", 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 );

KeyboardDemo demo;

// Demo Initialize
bool result = demo.Initialize( hInstance, hwnd );

if( result == false )
return -1;

MSG msg = { 0 };

while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

// Update and Draw
demo.Update( 0.0f );
demo.Render( );
}

// Demo Shutdown
demo.Shutdown( );

return static_cast<int>( msg.wParam );
}


LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT paintStruct;
HDC hDC;

switch( message )
{
case WM_PAINT:
hDC = BeginPaint( hwnd, &paintStruct );
EndPaint( hwnd, &paintStruct );
break;

case WM_DESTROY:
PostQuitMessage( 0 );
break;

default:
return DefWindowProc( hwnd, message, wParam, lParam );
}

return 0;
}

Explanation / Answer

-----------------------------------

//Header files

#include<windows.h> // contains declarations for all of the functions in the Windows API
#include<memory> // utilities to manage dynamic memory
#include"KeyboardDemo.h" // used for KeyboardDeno application

---------------------------------------------------------------------------

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );

// LRESULT resolves to long . CALLBACK resolves to _stdcall, so function return a long.

//WndProc receive all input from secreen

// HWND hwnd to create window from window class

//UINT message recive messgae from window

// WPARAM is an unsigned int and LPARAM is a long. wParam and lParam are variables of message recived from window


int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow ) // Main function
{
UNREFERENCED_PARAMETER( prevInstance );
UNREFERENCED_PARAMETER( cmdLine );

// above are windows macro which help us to help with warnings in program

WNDCLASSEX wndClass = { 0 }; //structure is initialized
wndClass.cbSize = sizeof( WNDCLASSEX ) ; // count size in byte of class WNDCLASSEX

wndClass.style = CS_HREDRAW | CS_VREDRAW; // it redraw size if window width and height is changed


wndClass.lpfnWndProc = WndProc; // points to windows procedure output or running situations
wndClass.hInstance = hInstance; //handels instance of windows procedure class
wndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); // handle class's cursor
wndClass.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 ); //handle to class background brush
wndClass.lpszMenuName = NULL; // Pointer to a null-terminated character string that specifies the resource name of the class menu,
wndClass.lpszClassName = "DX11BookWindowClass"; //its pointer to a null-terminated string or is an atom

  

if ( !RegisterClassEx( &wndClass ) )
return -1;

RECT rc = { 0, 0, 640, 480 }; // defines co-ordinates of rectangel

AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); //current and result windows are matched

HWND hwnd = CreateWindowA( "DX11BookWindowClass", //create instance of window cclass

  "Keyboards in Direct3D 11", WS_OVERLAPPEDWINDOW, //matches the resultmnt window for perfect gaming window
CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,

rc.bottom - rc.top,
NULL, NULL, hInstance, NULL );

if( !hwnd )
return -1;

ShowWindow( hwnd, cmdShow );

KeyboardDemo demo;

// Demo Initialize
bool result = demo.Initialize( hInstance, hwnd );

if( result == false )
return -1;

MSG msg = { 0 };

while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

// Update and Draw
demo.Update( 0.0f );
demo.Render( );
}

// Demo Shutdown
demo.Shutdown( );

return static_cast<int>( msg.wParam );
}


LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT paintStruct; //ceate instance of paintstructure
HDC hDC;

switch( message )
{
case WM_PAINT:
hDC = BeginPaint( hwnd, &paintStruct ) // paint the window as co-ordination and data given
EndPaint( hwnd, &paintStruct );
break;

case WM_DESTROY:
PostQuitMessage( 0 ); //prints quit
break;

default:
return DefWindowProc( hwnd, message, wParam, lParam ) //if above cases wont work thn it set to all thing to default
}

return 0;
}