This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
/
main.cpp
119 lines (92 loc) · 2.89 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <precomp.h>
#include <api/apiinit.h>
#include <api/service/svcmgr.h>
#include <api/application/version.h>
#include "app.h"
DECLARE_MODULE_SVCMGR;
extern const char *appname;
extern const char *strfilever;
extern const GUID *pappguid; // filled in by app.cpp
OSMODULEHANDLE wasabiAppOSModuleHandle; // WinMain fills in
extern TList<OSWINDOWHANDLE> dlglist;
int exitpump = 0;
void doMessagePump() {
exitpump = 0;
// Despite appearances, this is portable
MSG msg;
while (!exitpump && GetMessage( &msg, INVALIDOSWINDOWHANDLE, 0, 0 ) ) {
#ifdef WIN32
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x20A
#endif
// umm... win32 click-to-mousewheel sucks. let's suck less. -BU
if (msg.message == WM_MOUSEWHEEL) {
HWND h = WindowFromPoint(msg.pt);
SendMessage(h, WM_MOUSEWHEEL, msg.wParam, msg.lParam);// NOT Post ;)
continue;
}
int isd=0;
for (int i = 0; i < dlglist.getNumItems(); i++) {
if (IsDialogMessage(dlglist[i], &msg)) {
isd = 1;
break;
}
}
if (!isd)
#endif
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}
int APIENTRY WinMain(OSMODULEHANDLE hInstance,
OSMODULEHANDLE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
ASSERTPR(appname != NULL, "need to include app.cpp and fill out appname");
ASSERTPR(pappguid != NULL, "need to include app.cpp and fill out appguid");
ASSERTPR(*pappguid != INVALID_GUID, "need to include app.cpp and fill out appguid");
wasabiAppOSModuleHandle = hInstance;
WasabiVersion::setAppName(appname);
WasabiVersion::setBuildNumber(WasabiVersion::versionStringToInt(strfilever));
#ifdef WASABI_COMPILE_WND
// the windowing API will automatically create a toplevel wnd for you
OSWINDOWHANDLE parentwnd = WASABI_API_WND->wnd_getMainWnd()
#else
// not using windowing API
// create a master parent wnd here if you need/want one
OSWINDOWHANDLE parentwnd = INVALIDOSWINDOWHANDLE;
#endif
ApiInit::init(hInstance, *pappguid, "", parentwnd);
// make windows and things
wasabiAppInit(parentwnd, lpCmdLine);
doMessagePump();
wasabiAppShutdown();
ApiInit::shutdown();
DebugString("shutdown");
return 0;
}
#ifdef WASABI_PLATFORM_POSIX
int main( int argc, char *argv[] ) {
OSMODULEHANDLE hInstance = dlopen( NULL, RTLD_NOW );
int len = 0;
for( int i = 1; i < argc; i++ ) {
len += strlen( argv[i] );
}
if ( argc > 2 )
len += argc - 2; // Spaces
len += 2 * (argc - 1);
char *lpCmdLine = (char *)malloc( len + 1 );
*lpCmdLine = 0;
for ( int i = 1; i < argc; i++ ) {
if ( i > 1 )
strcat( lpCmdLine, " " );
strcat( lpCmdLine, "\"" );
strcat( lpCmdLine, argv[i] );
strcat( lpCmdLine, "\"" );
}
WinMain( hInstance, NULL, lpCmdLine, 0 );
free( lpCmdLine );
}
#endif