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

Comment on each line of code to express the intent of this line of code. LRESULT

ID: 3829336 • Letter: C

Question

Comment on each line of code to express the intent of this line of code.

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, 800, 640 };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );

HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Text 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 );

D3DTextDemo 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

CODE:-

#include<Windows.h> //window .h directive is being included with predefined functions

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // WndProc function is declared

//wWinMains function are defined with parameters

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
{ // start of the function
   UNREFERENCED_PARAMETER(prevInstance);// the previously defined instance variable has been passed as //an argument to UNREFERENCED_PARAMETER() method  

UNREFERENCED_PARAMETER(cmdLine); // cmdLine is passed as an argument to the method .

   WNDCLASSEX wndClass = { 0 }; //wndClass is being declared and initialized to zero
   wndClass.cbSize = sizeof(WNDCLASSEX);// cbSize is defined from the wndClass with the sizeof operator

wndClass.style = CS_HREDRAW | CS_VREDRAW;// style is accessd from //wndClass and then the variable cs_hredraw | cs_vredraw is assigned to it

   wndClass.lpfnWndProc = WndProc; // lpfnWndProc is being accessed from //wndClass and the variable WndProc is assigned to it.


   wndClass.hInstance = hInstance; // hInstance is being accessed from wndClass and the variable hInstance is assigned to it .


   wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); // hCursor is being //accessed from wndClass and then variable LoadCursor(NULL, IDC_ARROW) //is assigned to it.
   wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);// hbrBackground is being accessed from wndClass and then the variable (HBRUSH)(COLOR_WINDOW + 1) is assigned to it
   wndClass.lpszMenuName = NULL; // lpszMenuName is being accessed from wndClass and then the variable NULL is assigned to it.
   wndClass.lpszClassName = "DX11BookWindowClass"; // lpszClassName is being accessed from the wndClass and then the variable DX11BookWindowClass //is assigned to it

   if (!RegisterClassEx(&wndClass)) /* loop is defined to verify "wndClass" as referenced with "&" and the particular data is passed as an argument to RegisterClassEx()

the   variable returns -1 if the function is not equal to the variable otherwise the remaining statement is being executed.*/

   return -1;

   RECT rc = { 0, 0, 640, 480 }; // rc variable is initialized to set of values


   AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE); // passing the value of rc is passed in order to pass the function AdjustWindowRect().

   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); // the parameters are passed to the function //AdjustWindowRect() and the the value that is returned will be stored in the hwnd

// if (!hwnd)//the return value will be -1 if the hwnd is false     

return -1;

   ShowWindow(hwnd, cmdShow);// parameters are passed to the functionShowWindow()

   // Demo Initialize

   MSG msg = { 0 }; //message is initialized to zero

   while (msg.message != WM_QUIT)//verify that msg.message is not equal to "wm_quit".
   {
       if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))//if PeekMessage() all values true then goes to next
       {
           TranslateMessage(&msg);//passing &msg to TranslateMessage()

DispatchMessage(&msg);//Passed $ messaged to the function DispatchMessage()
       }
       else //otherwise executed, updated and methods are drawn

       {
          // Update
           // Draw

       }
   }

   // Shutdown

   return static_cast<int>(msg.wParam); // static_cast<int>(msg.wParam) is being returned
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)// Function WndProc() is defined with return type CALLBACK
   PAINTSTRUCT paintStruct; //variable painstruct is declared
   HDC hDC;//variable hDC is declared

   switch (message) //switch case loop is defined with message as a parameter
   {
   case WM_PAINT: // case 1is defined
       hDC = BeginPaint(hwnd, &paintStruct);// function BeginPaint() is assigned


       EndPaint(hwnd, &paintStruct); //function EndPaint() is executed
       break; //break statement to exit the loop

   case WM_DESTROY:// case 2 is defined
       PostQuitMessage(0); //Function PostQuitMessage() is assigned
       break;//break statement to exit the loop

   default: //default statement      
   }

   return 0; //returns zero
}