Right, recently i have been learning c++ because i would like to make a game. So what i did, i started of by making a c++ window however at the end of making it i came up with a problem that i cannot fix. On the line where it says wc.lpszClassName = L"ZakariyaTV's Class"; i get a red line underneath the equals. I spent soo much time trying to figure it out but i cant. If you know how to fix it it would really appreciated. Thank you.
Here is my code:
#include<Windows.h>
HWND windowHandle;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE preInstance, PSTR cmdLine, int showCmd)
{
// Step 1
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIconSm = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName = L"ZakariyaTV's Class";
wc.lpszMenuName = 0;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
// Step 2
RegisterClassEx(&wc);
// Step 3
windowHandle = CreateWindowEx(WS_EX_ACCEPTFILES, L"ZakariyaTV's Class", L"Game!",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 800, 600, 0, 0, hInstance, 0);
// Step 4
if (windowHandle == 0)
MessageBoxA(0, "Create window failed", "Error Message", 0);
// Step 5
ShowWindow(windowHandle, showCmd);
// Step 6
UpdateWindow(windowHandle);
MSG msg;
SecureZeroMemory(&msg, sizeof(MSG));
int returnValue = 0;
while ((returnValue = GetMessage(&msg, 0, 0, 0)) != 0)
{
if (returnValue == -1)
{
MessageBoxA(windowHandle, "GetMessage Failed!", "Error Message", 0);
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
Visual Studio 2015 use Multi-Byte Character Set for default when you create a new project, but the L in L"ZakariyaTV's Class" is tell the compiler that the string should be compiled as Unicode, so you should change the Character Set for your project: right click project in VS 2015, then choose Properties->General->Character set under Project Defaults, finally change your previous "Use Multi-Byte Character Set" to "Use Unicode Character Set".