source: abuse/branches/win32/Abuse32/Abuse32.cpp @ 658

Last change on this file since 658 was 100, checked in by Sam Hocevar, 15 years ago
  • Importing an old Win32 port by Jeremy "Marauder" Scott.
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1//-----------------------------------------------------------------------------
2// File: DDEx1.CPP
3//
4// Desc: Direct Draw example program 1.  Creates a Direct Draw
5//       object and then a primary surface with a back buffer.
6//       Slowly flips between the primary surface and the back
7//       buffer.  Press F12 to terminate the program.
8//
9// Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
10//-----------------------------------------------------------------------------
11
12//-----------------------------------------------------------------------------
13// Include files
14//-----------------------------------------------------------------------------
15#include <windows.h>
16#include "Abuse32.h"
17#include <stdio.h>
18#include <stdarg.h>
19#include "game.hpp"
20#include "event.hpp"
21#include "jwindow.hpp"
22
23//-----------------------------------------------------------------------------
24// Local definitions
25//-----------------------------------------------------------------------------
26#define NAME                "Abuse"
27#define TITLE               "Abuse"
28
29HWND hWnd;
30HINSTANCE g_hInstance;
31
32extern int HaveFocus;
33//-----------------------------------------------------------------------------
34// Name: WindowProc()
35// Desc: The Main Window Procedure
36//-----------------------------------------------------------------------------
37long FAR PASCAL
38WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
39{
40    static int focused = 0;
41    switch (message) {
42        case WM_DESTROY:
43            // Clean up and close the app
44            PostQuitMessage(0);
45            return 0L;
46
47        case WM_SETCURSOR:
48            // Turn off the cursor since this is a full-screen app
49            SetCursor(NULL);
50            return 0;
51
52        case WM_SHOWWINDOW:
53            WriteErr(wParam, "Going away");
54            return 0;
55
56        case WM_ACTIVATEAPP:
57            if (wParam == FALSE) {
58                SetDIAcquire = DI_UNACQUIRE_STATE;
59                focused = 0;
60            }
61            else {
62                if (wm && !focused)
63                    wm->push_event(new event(EV_SCREEN_REFRESH));
64                focused = 1;
65                SetDIAcquire = DI_ACQUIRE_STATE;
66            }
67            return 0;
68        case WM_QUIT:
69            PostQuitMessage(wParam);
70            break;
71    }
72    return DefWindowProc(hWnd, message, wParam, lParam);
73}
74
75//-----------------------------------------------------------------------------
76// Name: InitApp()
77// Desc: Do work required for every instance of the application:
78//          Create the window, initialize data
79//-----------------------------------------------------------------------------
80static HRESULT
81InitApp(HINSTANCE hInstance, int nCmdShow)
82{
83    WNDCLASS                    wc;
84
85    // Set up and register window class
86    wc.style = CS_HREDRAW | CS_VREDRAW;
87    wc.lpfnWndProc = WindowProc;
88    wc.cbClsExtra = 0;
89    wc.cbWndExtra = 0;
90    wc.hInstance = hInstance;
91    wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ABUSE32));
92    wc.hCursor = NULL;
93    wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);
94    wc.lpszMenuName = NAME;
95    wc.lpszClassName = NAME;
96    RegisterClass(&wc);
97
98    // Create a window
99    hWnd = CreateWindowEx(WS_EX_TOPMOST,
100                          NAME,
101                          TITLE,
102                          WS_POPUP,
103                          0,
104                          0,
105                          320,
106                          200,
107                          NULL,
108                          NULL,
109                          hInstance,
110                          NULL);
111    if (!hWnd)
112        return FALSE;
113    ShowWindow(hWnd, nCmdShow);
114    UpdateWindow(hWnd);
115    SetFocus(hWnd);
116    SetCursor(NULL);
117    return 1;
118}
119
120int AbuseFinished = 0;
121int _make_argv(char *p, char ***argv);
122extern char** _argv;
123extern int _argc;
124char ExeName[2048];
125
126//-----------------------------------------------------------------------------
127unsigned long __stdcall AbuseThread(void* Data)
128{
129    start_abuse(_argc, _argv);
130    AbuseFinished = 1;
131    PostMessage(hWnd, WM_QUIT, 0, 0);
132    PostQuitMessage(0);
133    ExitThread(0);
134    return 0;
135}
136
137extern int ErrCode;
138extern char* QuitMessage;
139//-----------------------------------------------------------------------------
140// Name: WinMain()
141// Desc: Initialization, message loop
142//-----------------------------------------------------------------------------
143int PASCAL
144WinMain(HINSTANCE hInstance,
145        HINSTANCE hPrevInstance,
146        LPSTR lpCmdLine,
147        int nCmdShow)
148{
149    DWORD AbuseThreadID = 0;
150    if (!InitApp(hInstance, nCmdShow))
151        return FALSE;
152    GetModuleFileName(NULL, ExeName, 2048);
153    g_hInstance = hInstance;
154    _argv = (char**) malloc(2 * sizeof(char*));
155        _argv[0] = ExeName;     /* fill in program name */
156        _argc = _make_argv(lpCmdLine, &_argv);
157        _argv[_argc] = NULL;
158   
159    set_mode(19, _argc, _argv); // Set the video mode
160
161//    start_abuse(_argc, _argv);
162    CreateThread(NULL, NULL, AbuseThread, NULL, NULL, &AbuseThreadID);
163   
164        MSG msg;
165        HACCEL hAccelTable;
166        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR) IDC_ABUSE32);
167
168    while (GetMessage(&msg, NULL, 0, 0) && !AbuseFinished) {
169        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
170                        TranslateMessage(&msg);
171                        DispatchMessage(&msg);
172                }
173        }
174    WaitForSingleObject((HANDLE) AbuseThreadID, INFINITE);  /**/
175    if (AbuseFinished)
176        Sleep(100); // Give other threads time to exit; ugly, but it'll work for now
177    set_dprinter(NULL);
178    KillDInput();
179    close_graphics();
180    if (ErrCode)
181        MessageBox(NULL, QuitMessage, "Error in Abuse engine", MB_OK);
182
183        ExitProcess(0);
184    return 0;
185}
Note: See TracBrowser for help on using the repository browser.