2024-04-20 15:57:49 +00:00
|
|
|
/*
|
|
|
|
* Descent 3
|
|
|
|
* Copyright (C) 2024 Parallax Software
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2024-05-06 15:12:44 +00:00
|
|
|
--- HISTORICAL COMMENTS FOLLOW ---
|
|
|
|
|
2024-04-16 03:43:29 +00:00
|
|
|
* $Logfile: /DescentIII/Main/Lib/Win/win32app.h $
|
|
|
|
* $Revision: 15 $
|
|
|
|
* $Date: 5/02/99 3:06p $
|
|
|
|
* $Author: Samir $
|
|
|
|
*
|
|
|
|
* Application object for Win32
|
|
|
|
*
|
|
|
|
* $Log: /DescentIII/Main/Lib/Win/win32app.h $
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 15 5/02/99 3:06p Samir
|
|
|
|
* added handling for power management messages.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 14 4/27/99 2:06p Samir
|
|
|
|
* added function to get system info.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 13 4/06/99 8:30p Samir
|
|
|
|
* organized defer code so delay procedure doesn't stall on idle.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 12 10/16/98 11:07a Samir
|
|
|
|
* new OS version check stuff.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 11 10/08/98 7:26p Samir
|
|
|
|
* changed the prototype for the defer handler callback.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 10 6/29/98 6:45p Samir
|
|
|
|
* callback system repaired.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 9 3/23/98 8:04p Samir
|
|
|
|
* defer handler now returns a bool.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 8 2/23/98 5:07p Samir
|
|
|
|
* Modified init somewhat.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 7 2/23/98 4:30p Samir
|
|
|
|
* added init function to oeApplication.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 6 11/17/97 4:57p Samir
|
|
|
|
* Fixed up winapp data structures.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 5 10/16/97 2:30p Samir
|
|
|
|
* Added Idle processing.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 4 9/16/97 1:04p Samir
|
|
|
|
* Added delay function.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 3 8/01/97 7:30p Samir
|
|
|
|
* Better messaging support and NT support.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 2 7/28/97 3:46p Samir
|
|
|
|
* Added Topmost window optional support and NT detection.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 2 6/11/97 2:39p Samir
|
|
|
|
* Added destructors.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 1 6/10/97 4:54p Samir
|
|
|
|
* Win32 Application object conversion from old osWinObject.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* $NoKeywords: $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WIN32APP_H
|
|
|
|
#define WIN32APP_H
|
|
|
|
|
2024-05-19 11:23:15 +00:00
|
|
|
#include <array>
|
2024-05-15 17:52:01 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
/* Basic Application Win32 data types, to prevent include of windows.h */
|
|
|
|
typedef uintptr_t HWnd;
|
|
|
|
typedef uintptr_t HInstance;
|
|
|
|
typedef uintptr_t WParam;
|
|
|
|
typedef intptr_t LParam;
|
|
|
|
typedef intptr_t LResult;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// This structure is used to retrieve and set
|
2024-05-30 07:35:17 +00:00
|
|
|
struct tWin32AppInfo {
|
2024-04-16 18:56:40 +00:00
|
|
|
unsigned flags; // Application Flags
|
|
|
|
HWnd hwnd; // Window Handle
|
|
|
|
HInstance hinst; // Window Instance
|
|
|
|
int wnd_x, wnd_y, wnd_w, wnd_h; // Window dimensions
|
2024-05-30 07:35:17 +00:00
|
|
|
};
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-05-30 07:35:17 +00:00
|
|
|
enum tWin32OS { NoWin32, Win9x, WinNT, WinCE };
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
/* Win32 Application Object
|
2024-04-16 18:56:40 +00:00
|
|
|
This object entails initialization and cleanup of all operating system
|
|
|
|
elements, as well as data that libraries may need to initialize their
|
|
|
|
systems.
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
The Win32 Application object creates the application window and housekeeps
|
|
|
|
the window and instance handle for the application.
|
|
|
|
|
|
|
|
We also allow the option of setting these handles from outside the Application object.
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
tOEWin32MsgCallback:
|
2024-04-16 18:56:40 +00:00
|
|
|
Callbacks return a 0 if we don't want to call the default action for the message, otherwise return 1
|
|
|
|
Callbacks are executed in the Window's message procedure, so the calling program need not manually run
|
|
|
|
the handler (although, I give you a function to do just that, if you can't depend on the WndProc).
|
|
|
|
NOTE: the callbacks are executed in the window's root procedure and not in the inherited WndProc function.
|
|
|
|
This means, that callbacks have priority over the application defined WndProc.
|
|
|
|
|
|
|
|
General priority of message handling.
|
|
|
|
Outrage Window Procedure:
|
|
|
|
takes care of window creation, destruction and system menus.
|
|
|
|
if message's window not registered then
|
|
|
|
calls Win32 Window Procedure
|
|
|
|
else
|
|
|
|
runs OEWin32MsgCallbacks for that message
|
|
|
|
if OEWin32MsgCallback functions return 0 then
|
|
|
|
leave Outrage Window Procedure
|
|
|
|
|
|
|
|
calls oeWin32Application->WndProc hierarchy which
|
|
|
|
optionally calls Win32 Window Procedure.
|
|
|
|
endif
|
2024-04-16 03:43:29 +00:00
|
|
|
*/
|
|
|
|
|
2024-05-15 17:52:01 +00:00
|
|
|
typedef int (*tOEWin32MsgCallback)(HWnd, unsigned, WParam, LParam);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
class oeWin32Application : public oeApplication {
|
2024-04-16 03:43:29 +00:00
|
|
|
#if defined(OEAPP_INTERNAL_MODULE)
|
|
|
|
public:
|
|
|
|
#else
|
|
|
|
private:
|
|
|
|
#endif
|
2024-06-07 06:17:04 +00:00
|
|
|
bool m_WasCreated{}; // Tells us if this app created the window handle or not.
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-05-19 11:23:15 +00:00
|
|
|
struct MessageFunction { // assign functions to messages.
|
2024-04-16 18:56:40 +00:00
|
|
|
unsigned msg;
|
|
|
|
tOEWin32MsgCallback fn;
|
2024-05-19 11:23:15 +00:00
|
|
|
};
|
2024-06-07 06:17:04 +00:00
|
|
|
std::array<MessageFunction, 64> m_MsgFn{};
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-06-07 06:17:04 +00:00
|
|
|
bool m_NTFlag{}; // Are we in NT?
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-06-07 06:17:04 +00:00
|
|
|
void (*m_DeferFunc)(bool){}; // function to call when deffering to OS (OnIdle for instance)
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-06-07 06:17:04 +00:00
|
|
|
char m_WndName[64]{}; // name of window.
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
static bool os_initialized; // is the OS check initialized?
|
|
|
|
static bool first_time; // first time init?
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
private:
|
2024-04-16 18:56:40 +00:00
|
|
|
int defer_block(); // real defer code.
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
public:
|
2024-04-16 18:56:40 +00:00
|
|
|
// Creates the window handle
|
|
|
|
oeWin32Application(const char *name, unsigned flags, HInstance hinst);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// Create object with a premade window handle/instance
|
|
|
|
// we just give it the window handle, instance handle and flags
|
|
|
|
oeWin32Application(tWin32AppInfo *appinfo);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
virtual ~oeWin32Application();
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// initializes the object
|
|
|
|
virtual void init();
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// Function to retrieve information from object through a platform defined structure.
|
|
|
|
virtual void get_info(void *appinfo);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
virtual int flags(void) const;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// defer returns some flags. essentially this function defers program control to OS.
|
|
|
|
virtual unsigned defer();
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// set a function to run when deferring to OS.
|
|
|
|
virtual void set_defer_handler(void (*func)(bool));
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// delays app for a certain amount of time
|
|
|
|
virtual void delay(float secs);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// Sizes the displayable region of the app (the window)
|
|
|
|
void set_sizepos(int x, int y, int w, int h);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// returns -1 if we pass to default window handler.
|
2024-05-15 17:52:01 +00:00
|
|
|
virtual LResult WndProc(HWnd hwnd, unsigned msg, WParam wParam, LParam lParam);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// These functions allow you to add message handlers.
|
|
|
|
bool add_handler(unsigned msg, tOEWin32MsgCallback fn);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// These functions remove a handler
|
|
|
|
bool remove_handler(unsigned msg, tOEWin32MsgCallback fn);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// Run handler for message (added by add_handler)
|
2024-05-15 17:52:01 +00:00
|
|
|
bool run_handler(HWnd wnd, unsigned msg, WParam wParam, LParam lParam);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// clears handler list
|
|
|
|
void clear_handlers();
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// tells us if we're in NT
|
|
|
|
bool NT() const { return m_NTFlag; }
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// retreive full version information
|
|
|
|
static tWin32OS version(int *major, int *minor, int *build = NULL, char *desc = NULL);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// detect if application can handle what we want of it.
|
|
|
|
static bool GetSystemSpecs(const char *fname);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
public:
|
2024-06-07 06:17:04 +00:00
|
|
|
HWnd m_hWnd{}; // handles created by the system
|
|
|
|
HInstance m_hInstance{};
|
|
|
|
unsigned m_Flags{};
|
|
|
|
int m_X{}, m_Y{}, m_W{}, m_H{}; // window dimensions.
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
private:
|
2024-04-16 18:56:40 +00:00
|
|
|
void os_init(); // initializes OS components.
|
2024-04-16 03:43:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// system mouse info.
|
2024-05-24 03:27:12 +00:00
|
|
|
extern int16_t w32_msewhl_delta; // value of mouse wheel delta for frame
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
#endif
|