Sign in to follow this  
Roberts91

Nothing wrong with code, but wont compile?

Recommended Posts

1>------ Build started: Project: 01 - Windows, Configuration: Debug Win32 ------ 1>Compiling... 1>winmain.cpp 1>c:\users\administrator\documents\visual studio 2008\projects\01 - windows\01 - windows\winmain.cpp(18) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\users\administrator\documents\visual studio 2008\projects\01 - windows\01 - windows\winmain.cpp(37) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>Build log was saved at "file://c:\Users\Administrator\Documents\Visual Studio 2008\Projects\01 - Windows\01 - Windows\Debug\BuildLog.htm" 1>01 - Windows - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include <windows.h>

LRESULT CALLBACK WindowEvent(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevhinstance, LPSTR commandline, int showstyle)
{
	WNDCLASSEX wc;

	wc.cbClsExtra = 0;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance = hinstance;
	wc.lpfnWndProc = WindowEvent;
	wc.lpszClassName = "MyClass";
	wc.lpszMenuName = NULL;
	wc.style = CS_VREDRAW | CS_HREDRAW;

	RegisterClassEx(&wc);

	HWND hwnd;
	hwnd = CreateWindowEx(
				NULL,
				"MyClass",
				"My Window",
				WS_OVERLAPPEDWINDOW | WS_VISIBLE,
				0,
				0,
				1024,
				768,
				NULL,
				NULL,
				hinstance,
				NULL);

	if (!hwnd)
		return 0;
	
	UpdateWindow(hwnd);

	MSG msg;
	while (true)
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message = WM_QUIT)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		//Process game here
	}
	
	
	return (int)msg.wParam;
}

LRESULT CALLBACK WindowEvent(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	}
	return DefWindowProc(hwnd,msg,wparam,lparam);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this