gzdoom/code/win32/I_main.c

146 lines
3.7 KiB
C
Raw Normal View History

1998-04-07 00:00:00 +00:00
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// $Log:$
//
// DESCRIPTION:
// Main program, simply calls D_DoomMain high level loop.
//
//-----------------------------------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include <stdio.h>
#include <stdarg.h>
#include "m_argv.h"
#include "d_main.h"
#include "i_system.h"
1998-07-14 00:00:00 +00:00
#include "c_consol.h"
1998-12-22 00:00:00 +00:00
#include "z_zone.h"
1999-02-17 00:00:00 +00:00
#include "version.h"
1998-04-07 00:00:00 +00:00
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
// Will this work with something besides VC++?
extern int __argc;
extern char **__argv;
1998-04-07 00:00:00 +00:00
const char WinClassName[] = "ZDOOM WndClass";
1998-04-07 00:00:00 +00:00
HINSTANCE g_hInst;
WNDCLASS WndClass;
HWND Window;
HINSTANCE hInstance;
1998-12-22 00:00:00 +00:00
extern float mb_used;
1998-04-07 00:00:00 +00:00
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int nCmdShow)
{
1999-02-17 00:00:00 +00:00
LONG WinWidth, WinHeight;
int height, width;
1998-04-07 00:00:00 +00:00
RECT cRect;
g_hInst = hInstance;
myargc = __argc;
myargv = __argv;
1998-12-22 00:00:00 +00:00
/*
killough 1/98:
This fixes some problems with exit handling
during abnormal situations.
The old code called I_Quit() to end program,
while now I_Quit() is installed as an exit
handler and exit() is called to exit, either
normally or abnormally.
*/
Z_Init (); // 1/18/98 killough: start up memory stuff first
atexit (I_Quit);
1998-04-07 00:00:00 +00:00
#ifdef USEASM
{
// Disable write-protection of code segment
// (from Win32 Demo Programming FAQ)
DWORD OldRights;
1998-12-22 00:00:00 +00:00
BYTE *pBaseOfImage = (BYTE *)GetModuleHandle(0);
1998-04-07 00:00:00 +00:00
IMAGE_OPTIONAL_HEADER *pHeader = (IMAGE_OPTIONAL_HEADER *)
1998-07-14 00:00:00 +00:00
(pBaseOfImage + ((IMAGE_DOS_HEADER*)pBaseOfImage)->e_lfanew +
sizeof(IMAGE_NT_SIGNATURE) + sizeof(IMAGE_FILE_HEADER));
1998-04-07 00:00:00 +00:00
if (!VirtualProtect(pBaseOfImage+pHeader->BaseOfCode,pHeader->SizeOfCode,PAGE_READWRITE,&OldRights))
I_FatalError ("Could not make code writable\n");
}
#endif
1998-12-22 00:00:00 +00:00
// Figure out what directory the program resides in.
GetModuleFileName (NULL, progdir, 1024);
*(strrchr (progdir, '\\') + 1) = 0;
FixPathSeperator (progdir);
1998-04-07 00:00:00 +00:00
height = GetSystemMetrics (SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics (SM_CYCAPTION) + 12 * 32;
width = GetSystemMetrics (SM_CXFIXEDFRAME) * 2 + 8 * 78;
1999-02-17 00:00:00 +00:00
WndClass.style = 0;
1998-04-07 00:00:00 +00:00
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1));
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
1999-02-17 00:00:00 +00:00
WndClass.hbrBackground = NULL;
1998-04-07 00:00:00 +00:00
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = (LPCTSTR)WinClassName;
/* register this new class with Windoze */
if (!RegisterClass((LPWNDCLASS)&WndClass))
I_FatalError ("Could not register window class");
/* create window */
Window = CreateWindow((LPCTSTR)WinClassName,
1998-04-07 00:00:00 +00:00
(LPCTSTR) "ZDOOM (" __DATE__ ")",
1998-12-22 00:00:00 +00:00
WS_CAPTION | WS_OVERLAPPED,
1998-04-07 00:00:00 +00:00
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
(HWND) NULL,
(HMENU) NULL,
(HANDLE) hInstance,
NULL);
if (!Window)
I_FatalError ("Could not open window");
GetClientRect (Window, &cRect);
WinWidth = cRect.right;
WinHeight = cRect.bottom;
1999-02-17 00:00:00 +00:00
C_InitConsole (((WinWidth / 8) + 2) * 8, (WinHeight / 12) * 8, false);
1998-04-07 00:00:00 +00:00
1999-02-17 00:00:00 +00:00
Printf (PRINT_HIGH, "Heapsize: %g megabytes\n", mb_used);
1998-12-22 00:00:00 +00:00
1998-04-07 00:00:00 +00:00
D_DoomMain ();
return 0;
}