Skip to content

Commit

Permalink
#15 Windows: Alt+Enter switches betwen window and fullscreen modes, w…
Browse files Browse the repository at this point in the history
…in32 console mode only for DEBUG configuration
  • Loading branch information
XProger committed Oct 5, 2016
1 parent 95f5794 commit 7c1c3f1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
Binary file modified bin/OpenLara.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions src/win/OpenLara.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>STB_VORBIS_NO_STDIO;NOMINMAX;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MINIMAL;STB_VORBIS_NO_STDIO;NOMINMAX;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -86,8 +86,8 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>wcrt.lib;opengl32.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
47 changes: 35 additions & 12 deletions src/win/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#ifdef _DEBUG
#include "crtdbg.h"
#endif
/* // VS2015 ?
#include <stdint.h>

void __cdecl operator delete(void *ptr, unsigned int size) {
//
}
*/
#ifdef MINIMAL
#if _MSC_VER == 1900 // VS2015
#include <malloc.h>
void __cdecl operator delete(void *ptr, unsigned int size) { free(ptr); }
// add "/d2noftol3" to compiler additional options
// add define _NO_CRT_STDIO_INLINE
#endif
#endif

#include "game.h"

DWORD getTime() {
Expand Down Expand Up @@ -177,10 +180,29 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
PostQuitMessage(0);
break;
// keyboard
case WM_CHAR :
case WM_SYSCHAR :
break;
case WM_KEYDOWN :
case WM_KEYUP :
case WM_SYSKEYDOWN :
case WM_SYSKEYUP :
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
if (msg == WM_SYSKEYDOWN && wParam == VK_RETURN) { // switch to fullscreen or window
static WINDOWPLACEMENT pLast;
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
if (style & WS_OVERLAPPEDWINDOW) {
MONITORINFO mInfo = { sizeof(mInfo) };
if (GetWindowPlacement(hWnd, &pLast) && GetMonitorInfo(MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY), &mInfo)) {
RECT &r = mInfo.rcMonitor;
SetWindowLong(hWnd, GWL_STYLE, style & ~WS_OVERLAPPEDWINDOW);
MoveWindow(hWnd, r.left, r.top, r.right - r.left, r.bottom - r.top, FALSE);
}
} else {
SetWindowLong(hWnd, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);
SetWindowPlacement(hWnd, &pLast);
}
break;
}
Input::setDown(keyToInputKey(wParam), msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN);
break;
// mouse
Expand Down Expand Up @@ -240,9 +262,10 @@ void freeGL(HGLRC hRC) {
wglDeleteContext(hRC);
}


#ifndef _DEBUG
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#else
int main() {
#ifdef _DEBUG
_CrtMemState _ms;
_CrtMemCheckpoint(&_ms);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
Expand All @@ -263,7 +286,7 @@ int main() {
SetWindowLong(hWnd, GWL_WNDPROC, (LONG)&WndProc);
ShowWindow(hWnd, SW_SHOWDEFAULT);

DWORD time, lastTime = getTime(), fpsTime = lastTime + 1000, fps = 0;
DWORD lastTime = getTime(), fpsTime = lastTime + 1000, fps = 0;
MSG msg;

do {
Expand All @@ -273,7 +296,7 @@ int main() {
} else {
joyUpdate();

time = getTime();
DWORD time = getTime();
if (time <= lastTime)
continue;

Expand Down

0 comments on commit 7c1c3f1

Please sign in to comment.