title: identifier "hWnd" is undefined
body: <p>I am trying to create a simple Tic-Tac-Toe game for a school project. I don't really know how to work with windows and I just want to work with others' code, using the default "Windows Desktop Application" (C++) in Visual Studio, but it keeps giving me this error message:</p>
  
  <blockquote>
    <p>identifier "hWnd" is undefined</p>
  </blockquote>
  
  <p>I don't really know how to work with this (at school, we work with some basic console application stuff) and I don't know how to define <code>hWnd</code>.</p>
  
  <p>Can somebody help me?</p>
  
  <pre class="lang-c prettyprint-override"><code>// Proba2.cpp : Defines the entry point for the application.
  //
  
  #include &lt;windows.h&gt;
  #include "framework.h"
  #include "Proba2.h"
  
  
  #define MAX_LOADSTRING 100
  
  // Global Variables:
  HINSTANCE hInst;   // current instance
  POINT MousePos;
  WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  
  // Forward declarations of functions included in this code module:
  ATOM                MyRegisterClass(HINSTANCE hInstance);
  BOOL                InitInstance(HINSTANCE, int);
  LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  
  int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                       _In_opt_ HINSTANCE hPrevInstance,
                       _In_ LPWSTR    lpCmdLine,
                       _In_ int       nCmdShow)
  {
      UNREFERENCED_PARAMETER(hPrevInstance);
      UNREFERENCED_PARAMETER(lpCmdLine);
  
      // TODO: Place code here.
  
      // Initialize global strings
      LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
      LoadStringW(hInstance, IDC_PROBA2, szWindowClass, MAX_LOADSTRING);
      MyRegisterClass(hInstance);
  
      // Perform application initialization:
      if (!InitInstance (hInstance, nCmdShow))
      {
          return FALSE;
      }
  
      HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROBA2));
  
      MSG msg;
  
      // Main message loop:
      while (GetMessage(&amp;msg, nullptr, 0, 0))
      {
          if (!TranslateAccelerator(msg.hwnd, hAccelTable, &amp;msg))
          {
              TranslateMessage(&amp;msg);
              DispatchMessage(&amp;msg);
          }
      }
  
      return (int) msg.wParam;
  }
  
  
  
  //
  //  FUNCTION: MyRegisterClass()
  //
  //  PURPOSE: Registers the window class.
  //
  ATOM MyRegisterClass(HINSTANCE hInstance)
  {
      WNDCLASSEXW wcex;
  
      wcex.cbSize = sizeof(WNDCLASSEX);
  
      wcex.style          = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc    = WndProc;
      wcex.cbClsExtra     = 0;
      wcex.cbWndExtra     = 0;
      wcex.hInstance      = hInstance;
      wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PROBA2));
      wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
      wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_PROBA2);
      wcex.lpszClassName  = szWindowClass;
      wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  
      return RegisterClassExW(&amp;wcex);
  }
  
  //
  //   FUNCTION: InitInstance(HINSTANCE, int)
  //
  //   PURPOSE: Saves instance handle and creates main window
  //
  //   COMMENTS:
  //
  //        In this function, we save the instance handle in a global variable and
  //        create and display the main program window.
  //
  BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  {
      HWND hWnd;
     hInst = hInstance; // Store instance handle in our global variable
  
     hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  
     if (!hWnd)
     {
        return FALSE;
     }
  
     ShowWindow(hWnd, nCmdShow);
     UpdateWindow(hWnd);
  
     return TRUE;
  }
  
  //
  //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  int lepeskoz;
  int hatar;
  int tabla[10][10];
  void kattintas(POINT mouse);
  void tabla_kirajzol();
  void init();
  void bejeloles(int x, int y, int azonosito);
  //
  //  PURPOSE: Processes messages for the main window.
  //
  //  WM_COMMAND  - process the application menu
  //  WM_PAINT    - Paint the main window
  //  WM_DESTROY  - post a quit message and return
  //
  //
  LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
  
  
  {
      switch (message)
      {
      case WM_COMMAND:
          {
              int wmId = LOWORD(wParam);
              // Parse the menu selections:
              switch (wmId)
              {
              case IDM_ABOUT:
                  DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                  break;
              case IDM_EXIT:
                  DestroyWindow(hWnd);
                  break;
              default:
                  return DefWindowProc(hWnd, message, wParam, lParam);
              }
          }
          break;
      case WM_CREATE:
          init();
          return 0;
      case WM_LBUTTONDOWN:
          MousePos.x = LOWORD(lParam);
          MousePos.y = HIWORD(lParam);
          kattintas(MousePos);
          return 0;
      case WM_PAINT:
          tabla_kirajzol();
          break;
      case WM_DESTROY:
          PostQuitMessage(0);
          break;
  
  
      default:
          return DefWindowProc(hWnd, message, wParam, lParam);
      }
      return 0;
  }
  
  // Message handler for about box.
  INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  {
      UNREFERENCED_PARAMETER(lParam);
      switch (message)
      {
      case WM_INITDIALOG:
          return (INT_PTR)TRUE;
  
      case WM_COMMAND:
          if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
          {
              EndDialog(hDlg, LOWORD(wParam));
              return (INT_PTR)TRUE;
          }
          break;
      }
      return (INT_PTR)FALSE;
  }
  
  void kattintas(POINT mouse)
  {
      int x_adat = (mouse.x / lepeskoz);
      int y_adat = (mouse.y / lepeskoz);
      if (x_adat &lt; 3 &amp;&amp; y_adat &lt; 3)
      {
          if (tabla[y_adat][x_adat] &gt; 0) return;
      }
  }
  
  void init()
  {
      lepeskoz = (400 - 30) / 3;
      hatar = (4 * lepeskoz) + 5;
  }
  
  void bejeloles(int x, int y, int azonosito)
  {
      tabla[y][x] = azonosito;
      tabla_kirajzol();
  }
  void palya()
  {
      int i;
      PAINTSTRUCT ps;
      HBRUSH hBrush;
      RECT rect;
      HDC hdc2;
      HPEN vonalstilus;
  
      {
          vonalstilus = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
  
          hdc2 = GetDC(hWnd);
          BeginPaint(hWnd, &amp;ps);
          hBrush = CreateSolidBrush(RGB(204, 204, 204));
          SetRect(&amp;rect, 0, 0, 400, 600);
          FillRect(hdc2, &amp;rect, hBrush);
          EndPaint(hWnd, &amp;ps);
  
          SelectObject(hdc2, vonalstilus);
          for (i = 5; i &lt; hatar; i += lepeskoz)
          {
              MoveToEx(hdc2, i, 5, NULL);
              LineTo(hdc2, i, hatar - lepeskoz);
          }
          for (i = 5; i &lt; hatar; i += lepeskoz)
          {
              MoveToEx(hdc2, 5, i, NULL);
              LineTo(hdc2, hatar - lepeskoz, i);
          }
          ReleaseDC(hWnd, hdc2);
          DeleteObject(vonalstilus);
      }
  }
  void tabla_kirajzol()
  {
      int x;
      int y;
      int korx, kory, kor_szelesseg;
  
      PAINTSTRUCT  ps;
      HBRUSH hBrush;
      HDC hdc2;
      HPEN vonalstilus;
  
      vonalstilus = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
      hBrush = CreateSolidBrush(RGB(34, 204, 204));
  
      hdc2 = GetDC(hWnd);
      BeginPaint(hWnd, &amp;ps);
      SelectObject(hdc2, vonalstilus);
  
      palya();
      for (y = 0; y &lt; 10; ++y)
          for (x = 0; x &lt; 10; ++x)
          {
              korx = x * lepeskoz + 5 + (lepeskoz / 2);
              kory = y * lepeskoz + 5 + (lepeskoz / 2);
              kor_szelesseg = (lepeskoz / 2) - 5;
  
              if (tabla[y][x] &gt; 0)
              {
                  if (tabla[y][x] == 1) {
                      hBrush = CreateSolidBrush(RGB(34, 204, 204)); SelectObject(hdc2, hBrush);
                      Ellipse(hdc2, korx - kor_szelesseg, kory - kor_szelesseg, korx + kor_szelesseg, kory + kor_szelesseg);
                  }
                  else if (tabla[y][x] == 2) {
                      hBrush = CreateSolidBrush(RGB(204, 204, 34)); SelectObject(hdc2, hBrush);
                      Rectangle(hdc2, korx - kor_szelesseg, kory - kor_szelesseg, korx + kor_szelesseg, kory + kor_szelesseg);
                  }
  
              }
          }
      EndPaint(hWnd, &amp;ps);
      ReleaseDC(hWnd, hdc2);
      DeleteObject(hBrush);
      DeleteObject(vonalstilus);
  }
  </code></pre>