/* **********************************************************************************************************************
   Included Header Files
   **********************************************************************************************************************/

#include "VDWindow.h"



/* **********************************************************************************************************************
   Constructor
   **********************************************************************************************************************/

VDWindow::VDWindow() {
    SecureZeroMemory(&windowClassStructure, sizeof(windowClassStructure));
    window = NULL;
};



/* **********************************************************************************************************************
   Destructor
   **********************************************************************************************************************/

VDWindow::~VDWindow() {
};



/* **********************************************************************************************************************
   WindowProcedure
   ---------------
   Processes messages for the main window.
   **********************************************************************************************************************/

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
    return DefWindowProc(hWnd, Msg, wParam, lParam);
};



/* **********************************************************************************************************************
   CreateMyWindow
   --------------
   Creates a new window.
   #param  instance         Instance of the application.
   #param  applicationName  Name of the window.
   #param  width            Width of the window.
   #param  height           Height of the window.
   **********************************************************************************************************************/

void VDWindow::CreateMyWindow(HINSTANCE instance, LPCSTR windowName, int width, int height) {
    // window class information
    windowClassStructure.cbClsExtra = 0;                                   // number of extra bytes to allocate following the window-class structure
    windowClassStructure.cbSize = sizeof(WNDCLASSEX);                      // size of the structure (in bytes)
    windowClassStructure.cbWndExtra = 0;                                   // number of extra bytes to allocate following the window instance
    windowClassStructure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);  // background brush
    windowClassStructure.hCursor = LoadCursor(NULL, IDC_ARROW);            // cursor
    windowClassStructure.hIcon = NULL;                                     // icon
    windowClassStructure.hIconSm = LoadIcon(NULL, IDI_APPLICATION);        // small icon
    windowClassStructure.hInstance = instance;                             // instance that has the window procedure
    windowClassStructure.lpfnWndProc = WindowProcedure;                    // window procedure
    windowClassStructure.lpszClassName = windowName;                       // class name
    windowClassStructure.lpszMenuName = NULL;                              // menu resource name
    windowClassStructure.style = NULL;                                     // style

    // register the window class
    ATOM registerClassEx = RegisterClassEx(&windowClassStructure);
    if (registerClassEx == 0) {
        VDError("Failed to register the window class.", __FILE__, __LINE__);
    };

    // create a window
    window = CreateWindowEx(NULL,                   // extended window styles
                            windowName,             // class name
                            windowName,             // window name
                            WS_POPUP | WS_VISIBLE,  // window styles
                            0,                      // x coordinate (0 = left)
                            0,                      // y coordinate (0 = top)
                            width,                  // width
                            height,                 // height
                            NULL,                   // parent/owner window
                            NULL,                   // menu
                            instance,               // instance
                            NULL);                  // used for CREATESTRUCT structure
    if (window == NULL) {
        VDError("Failed to create the window.", __FILE__, __LINE__);
    };
};



/* **********************************************************************************************************************
   Accessors and Modifiers
   **********************************************************************************************************************/

HWND VDWindow::GetWindow() {
    return window;
};