But it's complete... There is only functions ex. displaying fps on window caption etc.
#include "Main.h"
#define WIN32_LEAN_AND_MEAN
sf::RenderWindow *Render;
int mouse_x, mouse_y;
//FPS and Delta Time
int FPS_Frames;
float DeltaTime;
sf::Clock FPS_Timer;
float FPS_Number, FPS_Time;
int FPS;
//zmienne okienka
HWND hWindow, Render_Window;
MSG Msg;
// nazwa klasy okna
std::string WindowClass = "Window";
std::string WindowCaption = " ";
b2AABB WorldSize;
b2Vec2 gravity(0.0f, 0.0f);
bool doSleep = true;
//zasoby
//obrazki
sf::Image Img_Button[2];
//fonty
sf::Font Fnt_Arial, Fnt_Times_New_Roman;
void Display_FPS();
LRESULT CALLBACK WindowEventProc(HWND hWindow, UINT uMsg,WPARAM wParam, LPARAM lParam);
//----------------------- funkcja WinMain()----------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
WNDCLASSEX KlasaOkna;
ZeroMemory (&KlasaOkna, sizeof(WNDCLASSEX));
KlasaOkna.cbSize = sizeof(WNDCLASSEX);
KlasaOkna.hInstance = hInstance;
KlasaOkna.lpfnWndProc = WindowEventProc;
KlasaOkna.lpszClassName = WindowClass.c_str();
KlasaOkna.hCursor = LoadCursor(NULL, IDC_ARROW);
KlasaOkna.hIcon = LoadIcon(NULL, IDI_APPLICATION);
KlasaOkna.hbrBackground = (HBRUSH) COLOR_WINDOW;
RegisterClassEx (&KlasaOkna);
// tworzymy okno funkcją CreateWindowEx
hWindow = CreateWindowEx(NULL, // rozszerzony styl
WindowClass.c_str(), // klasa okna
WindowCaption.c_str(), // tekst na p. tytułu
WS_SYSMENU, // styl okna
CW_USEDEFAULT, // współrzędna X
CW_USEDEFAULT, // współrzędna Y
800, // szerokość
600, // wysokość
NULL, // okno nadrzędne
NULL, // menu
hInstance, // instancjs aplikacji
NULL); // dodatkowe dane
// pokazujemy nasze okno
DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
HWND Render_Window = CreateWindow("STATIC", NULL, Style, 0, 0, 800, 600, hWindow, NULL, hInstance, NULL);
sf::RenderWindow View01(Render_Window);
Render = &View01;
ShowWindow (hWindow, SW_SHOW);
while (Msg.message != WM_QUIT)
{
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&Msg);
DispatchMessage (&Msg);
}
else
{
sf::Event Event;
while (Render->GetEvent(Event))
{
// Process event
}
Display_FPS();
Render->Clear(sf::Color(255, 255, 255));
//some display functions
Button.Display(Render, DeltaTime);
Render->Display();
}
}
return static_cast<int>(Msg.wParam);// zwracamy kod wyjścia
}
LRESULT CALLBACK WindowEventProc(HWND hWindow, UINT uMsg,WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
break;
case WM_DESTROY: // kończymy program
PostQuitMessage (0);
return 0;
break;
//mouse move by winapi
case WM_MOUSEMOVE:
{
mouse_x = LOWORD(lParam);
mouse_y = HIWORD(lParam);
}
break;
}
return DefWindowProc(hWindow, uMsg, wParam, lParam);
}
void Display_FPS()
{
//delta time calculate
DeltaTime = FPS_Timer.GetElapsedTime();
FPS_Timer.Reset();
//FPS calculate
++FPS_Frames;//add frame
FPS_Time += DeltaTime;//time of generating one frame
if (FPS_Time >= 1.0f) // czy minęła sekunda?
{
FPS_Number = FPS_Frames / FPS_Time;//calculate fps
FPS_Frames = 0;//reset frame number
FPS_Time = 0.0f;//reset time
}
std::string tmp, tmp2, tmp3; // brzydkie rozwiązanie
itoa((int)FPS_Number, (char*)tmp.c_str(), 10);
std::string Caption;
Caption += tmp.c_str();
char Buffer[255];
int Mouse_X = Render->GetInput().GetMouseX(), Mouse_Y = Render->GetInput().GetMouseY();
//sprintf( Buffer, " MouseX: %d MouseY: %d", Mouse_X, Mouse_Y); - currently using Winapi input
sprintf( Buffer, " MouseX: %d MouseY: %d Button %d", mouse_x, mouse_y, Button.State);
Caption += Buffer;
SetWindowText(hWindow, Caption.c_str());
}