   Win32 API: WinHandle can't be used error. Got lots of developer's block
  Here's the code:#include <windows.h>#include <stdio.h>#include <stdlib.h>//HINSTANCE hInstance;HWND WinHandle;const int SCREEN_WIDTH = 640;const int SCREEN_HEIGHT = 480;bool InitWindow(HINSTANCE hInstance, int width, int height);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){MessageBox(NULL, L"This is a test.", L"Project", MB_OK);if (!InitWindow(hInstance, SCREEN_WIDTH, SCREEN_HEIGHT) == true){return 2;}MSG message = {NULL}; //WindowHandle is null.while (WM_QUIT != message.message){while(PeekMessage(&message, NULL, 0, 0, PM_REMOVE) == true){TranslateMessage(&message);DispatchMessage(&message);}}return (int) message.wParam;}bool InitWindow(HINSTANCE hInstance, int width, int height){WNDCLASSEX WindowClass;WindowClass.cbClsExtra = 0;WindowClass.cbSize = sizeof(WNDCLASSEX);WindowClass.cbWndExtra = 0;WindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOWFRAME);WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);WindowClass.hIcon = 0;WindowClass.hIconSm = 0;WindowClass.hInstance = hInstance;WindowClass.lpfnWndProc = (WNDPROC)WndProc;WindowClass.lpszClassName = TEXT("Test Project");WindowClass.lpszMenuName = NULL;WindowClass.style = CS_HREDRAW | CS_VREDRAW;RegisterClassEx(&WindowClass);RECT rect = {0, 0, width, height};AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);WinHandle = CreateWindowW(TEXT("Sample"), TEXT("Sample2"),    WS_OVERLAPPEDWINDOW,    CW_USEDEFAULT,    CW_USEDEFAULT,    rect.right - rect.left,   rect.bottom - rect.top,    NULL,    NULL,    hInstance,    NULL   );if (!WinHandle){return false;}ShowWindow(WinHandle, SW_SHOW);UpdateWindow(WinHandle);return true;}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wideParam, LPARAM longParam){switch(message){case WM_KEYDOWN:switch(wideParam){case VK_ESCAPE:PostQuitMessage(0);break;}case WM_DESTROY:PostQuitMessage(1);break;}return DefWindowProc(hWnd, message, wideParam, longParam);}It's the You-Know Tutorial of the basic window. The problem resides in the global variable "WinHandle".I can't seem to get the program to set something to the "WinHandle" variable.I'm confused on what I should do about it...Everything seems to be normal and etc. And because of that, the program exits prematurely. I was expecting it to show up a window with the predefined width and height, but it didn't.   
  Your CreateWindow is wrong.  You need to give it a class to use.  The first parameter is where you put this.  Try replacing TEXT("Sample") with TEXT("Test Project").[edit]Also you can remove the W at the end of CreateWindowW, CreateWindow is a macro that will default to which ever mode your compiler is using (basically the same as what the TEXT() macros do).   ;Quote:Original post by RattrapYour CreateWindow is wrong.  You need to give it a class to use.  The first parameter is where you put this.  Try replacing TEXT("Sample") with TEXT("Test Project").[edit]Also you can remove the W at the end of CreateWindowW, CreateWindow is a macro that will default to which ever mode your compiler is using (basically the same as what the TEXT() macros do).Oh wow. So, the first parameter of the CreateWindow() function goes along with the lpszClassName member of the WindowClass class. That fixes everything. And the capital W was an accident. Thanks for the hints. :)