📄 global.hpp
字号:
#ifndef GLOBAL_HPP
#define GLOBAL_HPP
// This header file requires windows.h, of course
// $Id: global.hpp 2.2 1995/10/27 20:05:26 tsurace Beta $
// $Log: global.hpp $// Revision 2.2 1995/10/27 20:05:26 tsurace// Added GetchLoop to allow getch() simulation.// Added accelerators.//
// Revision 2.1 1995/10/24 15:52:51 tsurace
// Roll.
//
// Revision 1.3 1995/10/18 23:54:23 tsurace
// Added version string.
//
// Revision 1.2 1995/10/18 22:13:15 tsurace
// Added BlockingHook function so that the program won't suck when
// blocking calls are made. :>
//
// Revision 1.1 1995/10/11 21:01:02 tsurace
// Initial revision
//
// (end of Log)
#include <stdlib.h>
// Global class
class Global
{
public:
static void Init(HINSTANCE _hInstance, HINSTANCE _hPrevInstance);
static HINSTANCE Instance();
static int MessageLoop();
static int GetchLoop();
static void PostOutOfMemoryMessage();
static HINSTANCE PrevInstance();
// Called as the wndproc for all windows
static LRESULT CALLBACK _export
WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
// Called during blocking sockets calls
static BOOL CALLBACK BlockingHook();
private:
static HINSTANCE _hInstance; // Application instance
static HINSTANCE _hPrevInstance;
static const char * VersionInfo; // Class data
static HACCEL _accelerators;
};
// >>>>> Inline functions <<<<<
inline HINSTANCE Global::Instance()
{
return _hInstance;
};
inline HINSTANCE Global::PrevInstance()
{
return _hPrevInstance;
};
// ------------------------------------
// General purpose functions and macros
// ------------------------------------
// ----------------------------------------------------------------------
// scream_and_die functions - send a message and abort
//
// Parameters:
// class - the type of failure (IE, IDERR_WSAAsyncSelect)
// string_id - the resource id of the message string
//
// Notes:
// Both of these load the class string from a resource, which may fail
// if the system is out of memory.
//
inline void scream_and_die(int msg_class, int string_id)
{
char title[20];
char message[256];
if (LoadString(Global::Instance(), msg_class, title, 20)
&& LoadString(Global::Instance(), string_id, message, 256))
{
MessageBox(NULL,
message,
title,
MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
};
DebugBreak();
exit(EXIT_FAILURE);
};
// scream_and_die for freeform messages
inline void scream_and_die(int msg_class, char * msg)
{
char title[20];
if (LoadString(Global::Instance(), msg_class, title, 20))
MessageBox(NULL, msg, title, MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
DebugBreak();
exit(EXIT_FAILURE);
};
#endif // GLOBAL_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -