Hi there,
I have the following code:
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
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);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Test",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
Msg.message = static_cast<UINT>(~WM_QUIT);
SE::Engine engine(hwnd);
//For finding delta time
sf::Clock deltaClock;
sf::Time lastUpdate = sf::Time::Zero;
//60fps max
sf::Time timePerFrame = sf::seconds(1.f / 60.f);
while (Msg.message != WM_QUIT)
{
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
// If a message was waiting in the message queue, process it
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
while (engine.running())
{
lastUpdate += deltaClock.restart();
while (lastUpdate > timePerFrame)
{
lastUpdate -= timePerFrame;
engine.update(timePerFrame);
engine.render();
}
}
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return Msg.wParam;
}
And engine.update(timePerFrame) is basically along the lines of this:
sf::Event evt;
while (SceneManager::getWindow().pollEvent(evt))
m_input_manager.update(dt, evt);
}
I tried referencing several posts and the integrating SFML 1.6 into Win32, but they're dated and I can't seem to get it to work. If anyone has any ideas I would be extremely grateful.
Thanks