#include <Windows.h>
#include <MMSystem.h>
#include <iostream>
#include "resource.h"
HWND mainWnd;
HMENU hMenu;
LRESULT CALLBACK
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
float lastTime = (float)timeGetTime();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd)
{
LOGBRUSH lb;
lb.lbColor = RGB(200,0,0);
lb.lbStyle = BS_HATCHED;
lb.lbHatch = HS_BDIAGONAL;
HBRUSH t = CreateBrushIndirect(&lb);
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = t;
wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "mainWnd";
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW | CS_VREDRAW;
hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
RegisterClass(&wc);
mainWnd = CreateWindow("mainWnd", "windowName", WS_OVERLAPPEDWINDOW, 0,0, 500, 500, 0, hMenu, hInstance, 0);
char error[260];
sprintf_s(error, "ERROR WINDOW FAIL: %d", GetLastError());
if(mainWnd == 0)
{
MessageBox(0, error, "ERror", MB_OK);
return -1;
}
ShowWindow(mainWnd, showCmd);
UpdateWindow(mainWnd);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, 0,0,0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
float currTime = (float)timeGetTime();
float deltaTime = (currTime - lastTime)*0.001f;
lastTime = currTime;
}
}
}
void fps(float deltaTime)
{
static int frames = 0;
static float timeElapsed = 0.f;
static char buffer[256];
++frames;
timeElapsed += deltaTime;
sprintf_s(buffer, "FPS = %d", frames);
if(timeElapsed >= 1.0f)
{
SetWindowText(mainWnd, buffer);
}
}
thanks,
Dartos
This post has been edited by dartoscoder: 17 January 2012 - 07:10 PM

New Topic/Question
Reply




MultiQuote










|