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

Build and compile the attached solution files. Comment every line of code to exp

ID: 3826018 • Letter: B

Question

Build and compile the attached solution files. Comment every line of code to express your understanding of what this line of code is intended to do. Make sure the application runs and you're able to see a blank window showing up on screen.

#include<Windows.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", "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);
       }
       else
       {
           // 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;

   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

#include<Windows.h> //here we are including the window.h directive which contains predefined function

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);//this the WndProc function declaration ,its definition will be defined later

/*

wWinMains function with parameters as

hInstance,prevInstance,cmdLine,cmdShow with different data types

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
{
   UNREFERENCED_PARAMETER(prevInstance);// the previous instance variable is passing to UNREFERENCED_PARAMETER() method as an argumtent

   UNREFERENCED_PARAMETER(cmdLine); // the cmdLine variable is passing to UNREFERENCED_PARAMETER() method as an argumtent

   WNDCLASSEX wndClass = { 0 }; //declaring wndClass and initializing it to "0"
   wndClass.cbSize = sizeof(WNDCLASSEX);// defining cbSize from wndClass with sizeof operator as the size is WNDCLASSEX
   wndClass.style = CS_HREDRAW | CS_VREDRAW;//accessing style from wndClass and assigning CS_HREDRAW | CS_VREDRAW variable to it
   wndClass.lpfnWndProc = WndProc; //accessing lpfnWndProc from wndClass and assigning WndProc variable to it
   wndClass.hInstance = hInstance; //accessing hInstance from wndClass and assigning hInstance variable to it
   wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); //accessing hCursor from wndClass and assigning LoadCursor(NULL, IDC_ARROW) variable to it
   wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);//accessing hbrBackground from wndClass and assigning (HBRUSH)(COLOR_WINDOW + 1) variable to it
   wndClass.lpszMenuName = NULL; //accessing lpszMenuName from wndClass and assigning NULL variable to it
   wndClass.lpszClassName = "DX11BookWindowClass"; //accessing lpszClassName from wndClass and assigning DX11BookWindowClass variable to it

   if (!RegisterClassEx(&wndClass)) // in this loop verifying "wndClass" as referencing with "&" and that data is passing as argument to RegisterClassEx()

       return -1;

   RECT rc = { 0, 0, 640, 480 }; // initializing rc variable to set of values
   AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE); // passing the values of rc as passing by reference to AdjustWindowRect() this function

   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); // passing all the parameters to AdjustWindowRect() method and from this function the returned value will be stored in hwnd variable

   if (!hwnd)//if the value of hwnd not true then it return "-1"
       return -1;

   ShowWindow(hwnd, cmdShow);// passing the parameters to ShowWindow() this function

   // Demo Initialize

   MSG msg = { 0 }; //initializing the msg to "0"

   while (msg.message != WM_QUIT)//verifying msg.message not equal to "wm_quit" then it goes to next if loop
   {
       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);//passing &msg to DispatchMessage()
       }
       else //else execute update and draw methods
       {
           // Update
           // Draw
       }
   }

   // Demo Shutdown

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


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)// definition of WndProc() method with CALLBACK as return type
   PAINTSTRUCT paintStruct; //paintStruct variable declaration
   HDC hDC;//hDC variable declaration

   switch (message) //switch case with message as parameter
   {
   case WM_PAINT: // case 1 with WM_PAINT message
       hDC = BeginPaint(hwnd, &paintStruct);//assigning BeginPaint() method retrun type to hDC variable
       EndPaint(hwnd, &paintStruct); //executing EndPaint() method
       break; //break statement

   case WM_DESTROY://// case 2 with WM_DESTROY message
       PostQuitMessage(0); //executing PostQuitMessage() method
       break;////break statement

   default: //default statement that returns DefWindowProc() value
       return DefWindowProc(hwnd, message, wParam, lParam);
   }

   return 0; //returns "0"
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote