Пример #1
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
	if(!DefineWindow(
		APP_CLASS_NAME, 
		hInstance, 
		ParentMessageProcessingHandler, 
		LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_TALK)),
		LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_TALK)),
		HBRUSH(COLOR_3DSHADOW),
		MAKEINTRESOURCE(IDR_APPMENU),
		LoadCursor(NULL, IDC_ARROW)))
	{
		ShowError("Error", NULL);
		return 0;
	}

	int screenWidth = GetSystemMetrics(SM_CXSCREEN);
	int screenHeight = GetSystemMetrics(SM_CYSCREEN);

	int x = screenWidth - APP_X_WDT;
	int height = screenHeight - 2 * APP_Y_SPC;
	
	if(!InstantiateWindow(
		APP_CLASS_NAME,
		hInstance,
		APP_NAME,
		x,
		APP_Y_SPC,
		APP_X_WDT,
		height,
		NULL,
		nCmdShow))
	{
		ShowError("Error", NULL);
		return 0;
	}

	int winMainRetValue;

	winMainRetValue = DoMessageLoop();

	return winMainRetValue;
}
Пример #2
0
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WindowDetails* details = DefineWindow(hInstance, nShowCmd);
	MSG msg;

	int rows = details->Height / gCellSize + 2;
	int columns = details->Width / gCellSize + 2;
	int prevCellSize = gCellSize;

	int* sim = createSimulationMatrix(rows, columns, gBoundary);
	populateSimulation(gSimulationMode, sim, rows, columns, 0.35);
	clock_t prevTime = clock();

	while (running)
	{
		while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessageW(&msg);
		}

		if (prevCellSize != gCellSize)
		{
			fitWindow(gCellSize, prevCellSize, details);
			prevCellSize = gCellSize;
		}

		switch (ButtonMessage)
		{
		case 1:
			free(sim);
			sim = createSimulationMatrix(rows, columns, gBoundary);
			populateSimulation(gSimulationMode, sim, rows, columns, 0.35);
			generation = 0;
			break;
		case 2:
			gSimulationMode++;
			if (gSimulationMode > 2)
				gSimulationMode = 0;

			free(sim);
			sim = createSimulationMatrix(rows, columns, gBoundary);
			populateSimulation(gSimulationMode, sim, rows, columns, 0.35);

			generation = 0;
			break;
		case 3:
			gBoundary = !gBoundary;
			break;
		}
		ButtonMessage = 0;

		clock_t curTime = clock();
		if (((double)(curTime - prevTime) / CLOCKS_PER_SEC) >= gStepsPerSecond && !paused)
		{
			prevTime = curTime;
			generation++;
			swprintf_s(title, 256, titleFormat, generation, gSimulationMode, gBoundary, (int)(1 / gStepsPerSecond));
			SetWindowTextW(details->Window, title);

			int* newSim = stepSimulation(gSimulationMode, details->BackBuffer, details->Width, sim, rows, columns, gBoundary, gCellSize);
			sim = newSim;

			StretchDIBits(details->DC,
				0, 0, details->Width, details->Height,
				0, 0, details->BitMapInfo.bmiHeader.biWidth, Abs(details->BitMapInfo.bmiHeader.biHeight),
				details->BackBuffer, &details->BitMapInfo,
				DIB_RGB_COLORS, SRCCOPY);
		}
	}

	ReleaseDC(NULL, details->DC);
	free(details->BackBuffer);
	free(details);

	return EXIT_SUCCESS;
}