19 #ifndef WIN32_LEAN_AND_MEAN
20 #define WIN32_LEAN_AND_MEAN 1
24 static const char *toplevel_class_name =
"pstats";
31 toplevel_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
45 return DefWindowProc(hwnd, msg, wparam, lparam);
53 create_toplevel_window(HINSTANCE application) {
56 ZeroMemory(&wc,
sizeof(WNDCLASS));
57 wc.lpfnWndProc = (WNDPROC)toplevel_window_proc;
58 wc.hInstance = application;
59 wc.lpszClassName = toplevel_class_name;
61 if (!RegisterClass(&wc)) {
62 nout <<
"Could not register window class!\n";
66 DWORD window_style = WS_POPUP | WS_SYSMENU | WS_ICONIC;
68 std::ostringstream strm;
69 strm <<
"PStats " << pstats_port;
70 std::string window_name = strm.str();
72 HWND toplevel_window =
73 CreateWindow(toplevel_class_name, window_name.c_str(), window_style,
74 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
75 nullptr,
nullptr, application, 0);
76 if (!toplevel_window) {
77 nout <<
"Could not create toplevel window!\n";
81 return toplevel_window;
84 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR,
int) {
85 HINSTANCE application = GetModuleHandle(
nullptr);
86 HWND toplevel_window = create_toplevel_window(application);
88 ShowWindow(toplevel_window, SW_SHOWMINIMIZED);
93 std::ostringstream stream;
95 <<
"Unable to open port " << pstats_port
96 <<
". Try specifying a different\n"
97 <<
"port number using pstats-port in your Config file.";
98 std::string str = stream.str();
99 MessageBox(toplevel_window, str.c_str(),
"PStats error",
100 MB_OK | MB_ICONEXCLAMATION);
105 SetTimer(toplevel_window, 1, 200,
nullptr);
110 retval = GetMessage(&msg,
nullptr, 0, 0);
111 while (retval != 0) {
113 nout <<
"Error processing message queue.\n";
116 TranslateMessage(&msg);
117 DispatchMessage(&msg);
118 retval = GetMessage(&msg,
nullptr, 0, 0);
128 int main(
int argc,
char *argv[]) {
129 return WinMain(
nullptr,
nullptr,
nullptr, 0);
void poll()
Checks for any network activity and handles it, if appropriate, and then returns.
bool listen(int port=-1)
Establishes a port number that the manager will listen on for TCP connections.
The class that owns the main loop, waiting for client connections.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.