22 #ifndef BAGEL_MFC_GLOBAL_FUNCTIONS_H 23 #define BAGEL_MFC_GLOBAL_FUNCTIONS_H 25 #include "common/stream.h" 26 #include "bagel/mfc/afxstr.h" 27 #include "bagel/mfc/minwindef.h" 28 #include "bagel/mfc/winnt.h" 37 #define GMEM_FIXED 0x0000 38 #define GMEM_MOVEABLE 0x0002 39 #define GMEM_NOCOMPACT 0x0010 40 #define GMEM_NODISCARD 0x0020 41 #define GMEM_ZEROINIT 0x0040 42 #define GMEM_MODIFY 0x0080 43 #define GMEM_DISCARDABLE 0x0100 44 #define GMEM_NOT_BANKED 0x1000 45 #define GMEM_SHARE 0x2000 46 #define GMEM_DDESHARE 0x2000 47 #define GMEM_NOTIFY 0x4000 48 #define GMEM_LOWER GMEM_NOT_BANKED 49 #define GMEM_VALID_FLAGS 0x7F72 50 #define GMEM_INVALID_HANDLE 0x8000 52 #define GHND (GMEM_MOVEABLE | GMEM_ZEROINIT) 53 #define GPTR (GMEM_FIXED | GMEM_ZEROINIT) 55 #define MB_ICONHAND 0x00000010L 56 #define MB_ICONQUESTION 0x00000020L 57 #define MB_ICONEXCLAMATION 0x00000030L 58 #define MB_ICONASTERISK 0x00000040L 59 #define MB_ICONINFORMATION MB_ICONASTERISK 60 #define MB_ICONSTOP MB_ICONHAND 62 extern CWinApp *AfxGetApp();
63 extern CWnd *AfxGetMainWnd();
64 extern HINSTANCE AfxGetInstanceHandle();
65 extern int LoadString(HINSTANCE hInstance,
66 unsigned int uID,
char *lpBuffer,
int cchBufferMax);
67 extern HMODULE LoadLibrary(
const char *lpLibFileName);
68 extern void FreeLibrary(HMODULE hModule);
69 extern FARPROC GetProcAddress(HMODULE hModule,
70 const char * lpProcName);
71 extern HMODULE GetModuleHandle(
const char *lpModuleName);
73 extern const char *AFXAPI AfxRegisterWndClass(
unsigned int nClassStyle,
74 HCURSOR hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0);
75 extern bool GetClassInfo(HINSTANCE hInstance,
76 const char *lpClassName, LPWNDCLASS lpWndClass);
77 extern int GetSystemMetrics(
int nIndex);
79 extern HGLOBAL GlobalAlloc(
unsigned int uFlags,
size_t dwBytes);
80 extern void *GlobalLock(HGLOBAL hMem);
81 extern bool GlobalUnlock(HGLOBAL hMem);
82 extern HGLOBAL GlobalFree(HGLOBAL hMem);
83 extern size_t GlobalSize(HGLOBAL hMem);
84 extern size_t GlobalCompact(uint32 dwMinFree);
85 #define LocalAlloc GlobalAlloc 86 #define LocalLock GlobalLock 87 #define LocalUnlock GlobalUnlock 88 #define LocalFree GlobalFree 89 #define LocalCompact GlobalCompact 90 #define GetFreeSpace(w) (0x100000L) 92 extern int MessageBox(HWND hWnd,
const char *lpText,
93 const char *lpCaption,
unsigned int uType);
94 extern int MessageBox(
const char *lpText,
const char *lpCaption,
unsigned int uType = 0);
95 extern int MessageBox(
const char *lpText);
96 extern unsigned int GetPrivateProfileInt(
const char *lpAppName,
97 const char *lpKeyName,
int nDefault,
const char *lpFileName);
98 extern uint32 GetPrivateProfileString(
const char *lpAppName,
99 const char *lpKeyName,
const char *lpDefault,
char * lpReturnedString,
100 uint32 nSize,
const char *lpFileName);
102 extern bool WritePrivateProfileString(
103 const char *lpAppName,
const char *lpKeyName,
104 const char *lpString,
const char *lpFileName);
106 extern HTASK GetCurrentTask();
107 extern FARPROC MakeProcInstance(FARPROC lpProc, HINSTANCE hInstance);
108 extern void FreeProcInstance(FARPROC lpProc);
109 extern HHOOK SetWindowsHookEx(
int idHook,
110 HOOKPROC lpfn, HINSTANCE hmod, HTASK dwThreadId);
111 extern bool UnhookWindowsHookEx(HHOOK hhk);
112 extern LRESULT CallNextHookEx(HHOOK hhk,
int nCode,
113 WPARAM wParam, LPARAM lParam);
114 extern uintptr SetTimer(HWND hWnd, uintptr nIDEvent,
unsigned int nElapse,
115 void (CALLBACK *lpfnTimer)(HWND,
unsigned int, uintptr, uint32) =
nullptr);
116 extern bool KillTimer(HWND hWnd, uintptr nIDEvent);
117 extern void Sleep(
unsigned int milli);
118 extern uint32 GetTickCount();
121 extern bool FileExists(
const char *filename);
122 extern long FileLength(
const char *filename);
124 extern bool PeekMessage(LPMSG lpMsg, HWND hWnd,
125 unsigned int wMsgFilterMin,
unsigned int wMsgFilterMax,
126 unsigned int wRemoveMsg);
127 extern void TranslateMessage(LPMSG lpMsg);
128 extern void DispatchMessage(LPMSG lpMsg);
129 extern bool PostMessage(HWND hWnd,
unsigned int Msg,
130 WPARAM wParam, LPARAM lParam);
131 extern LRESULT SendMessage(HWND hWnd,
unsigned int Msg,
132 WPARAM wParam, LPARAM lParam);
134 extern HINSTANCE AfxGetResourceHandle();
135 extern HINSTANCE AfxFindResourceHandle(
const char *lpszName,
const char *lpszType);
136 extern HRSRC FindResource(HMODULE hModule,
137 const char *lpName,
const char *lpType);
138 extern size_t SizeofResource(HMODULE hModule, HRSRC hResInfo);
139 extern HGLOBAL LoadResource(HMODULE hModule, HRSRC hResInfo);
140 extern void *LockResource(HGLOBAL hResData);
141 extern void UnlockResource(HGLOBAL hResData);
142 extern bool FreeResource(HGLOBAL hResData);
143 extern HFONT CreateFontIndirect(
const LOGFONT *lf);
145 extern bool AfxExtractSubString(CString &rString,
const char *lpszFullString,
146 int iSubString,
char chSep =
'\n');
148 inline char *strUpper(
char *s) {
149 for (
char *curr = s; *curr; ++curr)
150 *curr = toupper(*curr);
154 inline char *strLower(
char *s) {
155 for (
char *curr = s; *curr; ++curr)
156 *curr = tolower(*curr);