示例#1
0
LRESULT CALLBACK MessageHandler(HWND window,
	UINT message,
	WPARAM wParam,
	LPARAM lParam)
{
	LRESULT result = 0;

	switch (message)
	{

	case WM_CLOSE:
	{
		globalRunning = false;
	}break;

	case WM_DESTROY:
	{
		globalRunning = false;
	}break;

	case WM_PAINT:
	{
		PAINTSTRUCT paint;
		HDC deviceContext = BeginPaint(window, &paint);
		Dimension windowDim = getWindowDimension(window);
		drawBufferToScreen(deviceContext, &buffer, windowDim.width, windowDim.height);
		EndPaint(window, &paint);

	}break;
	
	default:
	{
		result = DefWindowProc(window, message, wParam, lParam);
	}break;
	}

	return result;
}
示例#2
0
int window_get_height() { return getWindowDimension(3); }
示例#3
0
int window_get_width()  { return getWindowDimension(2); }
示例#4
0
int CALLBACK
WinMain(HINSTANCE instance,
	HINSTANCE prevInstance,
	LPSTR     cmdLine,
	int       showCode)
{
	WNDCLASS windowClass = {};

	// makes the entire client rect part of the window redraw whenever
	// moved horizontally or veritcally
	windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	windowClass.lpfnWndProc = MessageHandler;
	windowClass.hInstance = instance;
	windowClass.lpszClassName = L"Gradient Renderer";

	if (RegisterClass(&windowClass))
	{
		HWND window = CreateWindowEx(
			0,
			windowClass.lpszClassName,
			L"GradientRenderer",
			WS_OVERLAPPEDWINDOW | WS_VISIBLE, //window with border and title. also shows up visible by default
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			0,
			0,
			instance,
			0);

		if (window)
		{
			HDC deviceContext = GetDC(window);
			uint8 xOffset = 0;
			uint8 yOffset = 0;

			initBuffer(&buffer, 1280, 720);

			globalRunning = true;
			while (globalRunning)
			{
				MSG message;
				while (PeekMessage(&message, 0, 0, 0, PM_REMOVE))
				{
					if (message.message == WM_QUIT)
					{
						globalRunning = false;
					}

					TranslateMessage(&message);
					DispatchMessage(&message);
				}

				renderGradient(&buffer, 255, xOffset, yOffset);
				xOffset++;
				yOffset++;


				Dimension windowDimension = getWindowDimension(window);
				drawBufferToScreen(deviceContext, &buffer, windowDimension.width, windowDimension.height);
			}


		}
	}

	return 0;
}
示例#5
0
int window_get_y()      { return getWindowDimension(1); }
示例#6
0
//Getters
int window_get_x()      { return getWindowDimension(0); }