[WinApp] Fixed missing initialization of m_MsgFn array in ctor.

Rewrote the C-style array to std::array while at it.
This commit is contained in:
Thomas Roß 2024-05-19 13:23:15 +02:00
parent 56e61275ce
commit 5e580b3f6c
2 changed files with 19 additions and 29 deletions

View File

@ -80,7 +80,7 @@
#ifndef WIN32APP_H
#define WIN32APP_H
#define MAX_MSG_FUNCTIONS 64
#include <array>
/* Basic Application Win32 data types */
typedef unsigned int HWnd;
@ -139,12 +139,11 @@ private:
#endif
bool m_WasCreated; // Tells us if this app created the window handle or not.
int m_NumMsgFn; // Number of message functions.
struct { // assign functions to messages.
struct MessageFunction { // assign functions to messages.
unsigned msg;
tOEWin32MsgCallback fn;
} m_MsgFn[MAX_MSG_FUNCTIONS];
};
std::array<MessageFunction, 64> m_MsgFn;
bool m_NTFlag; // Are we in NT?

View File

@ -201,7 +201,7 @@ bool oeWin32Application::first_time = true;
LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, UINT wParam, LPARAM lParam);
// Creates the window handle and instance
oeWin32Application::oeWin32Application(const char *name, unsigned flags, HInstance hinst) : oeApplication() {
oeWin32Application::oeWin32Application(const char *name, unsigned flags, HInstance hinst) : oeApplication(), m_MsgFn{} {
WNDCLASS wc;
RECT rect;
@ -544,18 +544,15 @@ int oeWin32Application::WndProc(HWnd hwnd, unsigned msg, unsigned wParam, long l
// These functions allow you to add message handlers.
bool oeWin32Application::add_handler(unsigned msg, tOEWin32MsgCallback fn) {
int i = 0;
// search for redundant callbacks.
for (i = 0; i < MAX_MSG_FUNCTIONS; i++) {
if (m_MsgFn[i].msg == msg && m_MsgFn[i].fn == fn)
for (const MessageFunction &rMsgFn : m_MsgFn)
if (rMsgFn.msg == msg && rMsgFn.fn == fn)
return true;
}
for (i = 0; i < MAX_MSG_FUNCTIONS; i++) {
if (m_MsgFn[i].fn == NULL) {
m_MsgFn[i].msg = msg;
m_MsgFn[i].fn = fn;
for (MessageFunction &rMsgFn : m_MsgFn) {
if (rMsgFn.fn == nullptr) {
rMsgFn.msg = msg;
rMsgFn.fn = fn;
return true;
}
}
@ -567,14 +564,12 @@ bool oeWin32Application::add_handler(unsigned msg, tOEWin32MsgCallback fn) {
// These functions remove a handler
bool oeWin32Application::remove_handler(unsigned msg, tOEWin32MsgCallback fn) {
int i;
if (!fn)
DebugBreak();
for (i = 0; i < MAX_MSG_FUNCTIONS; i++) {
if (msg == m_MsgFn[i].msg && m_MsgFn[i].fn == fn) {
m_MsgFn[i].fn = NULL;
for (MessageFunction &rMsgFn : m_MsgFn) {
if (msg == rMsgFn.msg && rMsgFn.fn == fn) {
rMsgFn.fn = nullptr;
return true;
}
}
@ -584,23 +579,19 @@ bool oeWin32Application::remove_handler(unsigned msg, tOEWin32MsgCallback fn) {
// Run handler for message (added by add_handler)
bool oeWin32Application::run_handler(HWnd wnd, unsigned msg, unsigned wParam, long lParam) {
int j;
// run user-defined message handlers
// the guess here is that any callback that returns a 0, will not want to handle the window's WndProc function.
for (j = 0; j < MAX_MSG_FUNCTIONS; j++)
if (msg == m_MsgFn[j].msg && m_MsgFn[j].fn) {
if (!(*m_MsgFn[j].fn)(wnd, msg, wParam, lParam))
for (const MessageFunction &rMsgFn : m_MsgFn)
if (msg == rMsgFn.msg && rMsgFn.fn)
if (!(*rMsgFn.fn)(wnd, msg, wParam, lParam))
return false;
}
return true;
}
void oeWin32Application::clear_handlers() {
int j;
for (j = 0; j < MAX_MSG_FUNCTIONS; j++)
m_MsgFn[j].fn = NULL;
for (MessageFunction &rMsgFn : m_MsgFn)
rMsgFn.fn = nullptr;
}
void oeWin32Application::delay(float secs) {