コード例 #1
0
ファイル: winmain.cpp プロジェクト: cpzhang/zen
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR lpstrCmdLine, int nCmdShow)
{
	createGlobal();
	FrameWindow mw;
	mw.CreateEx();
	mw.ShowWindow(SW_MAXIMIZE);
	mw.UpdateWindow();
	MSG m;
	::ZeroMemory(&m, sizeof(m));
	for (;;)
	{
		::ZeroMemory(&m, sizeof(m));
		if (::PeekMessage(&m, NULL, 0, 0, PM_NOREMOVE))
		{
			::GetMessage(&m, NULL, 0, 0);
			if (m.message == WM_QUIT)
			{
				break;
			}
			::TranslateMessage(&m);
			::DispatchMessage(&m);
		}
		else
		{
			mw.onIdle();
		}
	}
	destroyGlobal();
	return 0;
}
コード例 #2
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX ctls;
    ctls.dwSize = sizeof(INITCOMMONCONTROLSEX);
    ctls.dwICC = ICC_BAR_CLASSES;

    InitCommonControlsEx(&ctls);

    CreateDeveloperConsole();


    if (!LoadConfigFile("settings.cfg", g_options))
    {
        MessageBox(NULL, L"Could not load config file", L"Error", MB_OK);
        return 0;
    }

    RECT rct;

    rct.left = 0;
    rct.top = 0;
    rct.right = stoi(g_options["window_width"]);
    rct.bottom = stoi(g_options["window_height"]);

    AdjustWindowRectEx(&rct, WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, TRUE, WS_EX_OVERLAPPEDWINDOW);

    FrameWindow frameWindow;

    bool res = frameWindow.CreateEx(WS_EX_OVERLAPPEDWINDOW,
                                    g_mainWinClassName,
                                    L"WP Lab 3",
                                    WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                                    CW_USEDEFAULT, 0,
                                    rct.right - rct.left, rct.bottom - rct.top,
                                    NULL, NULL,
                                    hInstance);
    

    if (!res)
    {
        MessageBox(NULL, L"Could not create the window!", L"Error!", MB_OK|MB_ICONERROR);
        return 0;
    }

    frameWindow.Show(nCmdShow);
    frameWindow.Update();

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}
コード例 #3
0
ファイル: winmain.cpp プロジェクト: cpzhang/zen
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR lpstrCmdLine, int nCmdShow)
{
	createGlobal();
	FrameWindow mw;
	mw.CreateEx();
	mw.ShowWindow(SW_SHOWMAXIMIZED);
	mw.UpdateWindow();
	MSG m;
	::ZeroMemory(&m, sizeof(m));
	float life = 0.0f;
	float frame = 0.0f;
	float fps = 0.0f;
	const size_t tDuration = 1000;
	const size_t tInterval = 1000/65;
	float inter = tInterval;
	for (;;)
	{
		::ZeroMemory(&m, sizeof(m));
		if (::PeekMessage(&m, NULL, 0, 0, PM_NOREMOVE))
		{
			::GetMessage(&m, NULL, 0, 0);
			if (m.message == WM_QUIT)
			{
				break;
			}
			::TranslateMessage(&m);
			::DispatchMessage(&m);
		}
		else
		{
			// GetTickCount only has a guaranteed resolution of 1/18th of a second, which is pretty horrible for game timing
			//Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.
			float beforeRun = ::timeGetTime();
			mw.onIdle(inter);
			float afterRun = ::timeGetTime();
			float timeRun = afterRun - beforeRun;
			if (timeRun > tInterval)
			{
				inter = timeRun;
			}
			else
			{
				inter = tInterval;
			}
			++frame;
			float timeSleep = tInterval - timeRun;
			//¼ÆËãFPS
			life += inter;
			if (life >= tDuration)
			{
				fps = 1000.0f * frame / life;
				mw.setFPS(fps);
				life = 0.0f;
				frame = 0.0f;
			}
			//ÏÞÖ¡
			while(timeSleep >= 1.0f)
			{
				Sleep(1);
				--timeSleep;
			}
		}
	}
	destroyGlobal();

	return 0;
}