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
|
#ifndef __WINOBJ_H__
#define __WINOBJ_H__
#include "error.h"
#include <windows.h>
#include <assert.h>
#define END_DEFINE_WINDOW_OBJECT \
HWND win_handle;\
};\
WNDCLASSA class_##OBJECT_NAME## = {0};\
long proc_##OBJECT_NAME##(HWND window, unsigned int msg, WPARAM par1, LPARAM par2);\
extern CREATESTRUCTA *pre_make();\
extern struct OBJECT_NAME##_s *make_##OBJECT_NAME##_s();\
extern void pre_destroy();\
HWND parent, menu;\
const char *wndclass_name = #OBJECT_NAME;\
void initclass_##OBJECT_NAME##() {\
static init = 0;\
assert(init != 1);\
class_##OBJECT_NAME##.style = WCLASS_STYLES##;\
class_##OBJECT_NAME##.lpfnWndProc = (WNDPROC)proc_##OBJECT_NAME##;\
class_##OBJECT_NAME##.cbClsExtra = 0;\
class_##OBJECT_NAME##.cbWndExtra = 4;\
class_##OBJECT_NAME##.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));\
class_##OBJECT_NAME##.hbrBackground = NULL;\
class_##OBJECT_NAME##.lpszClassName = wndclass_name;\
printf("wndclass_name: %s\n", wndclass_name);\
if(RegisterClassA(&class_##OBJECT_NAME##) == 0)\
ErrorExit();\
init = 1;\
}\
HWND get_parent() {\
return parent;\
}\
HWND get_menu() {\
return menu;\
}\
struct OBJECT_NAME##_s *make_##OBJECT_NAME##_s() {\
struct OBJECT_NAME##_s *t;\
CREATESTRUCTA cr, *cr2;\
t = malloc(sizeof(struct OBJECT_NAME##_s##));\
cr2 = pre_make(&cr, t);\
SetClassLongA(t->win_handle = CreateWindowExA(WINEXT_STYLES, wndclass_name, WINDOW_NAME, WIN_STYLES,\
0, 0, 0, 0, NULL, NULL, get_app_handle(), cr2), 0, (LONG)t);\
return t;\
}\
struct OBJECT_NAME##_s destroy_##OBJECT_NAME##_s(struct OBJECT_NAME##_s *t) {\
pre_destroy(t);\
DestroyWindow(t->win_handle);\
free(t);\
}
#define DEFINE_WINDOW_OBJECT(_OBJECT_NAME, _WINDOW_NAME, _WIN_STYLES, _WINEXT_STYLES, _WCLASS_STYLES) \
#define OBJECT_NAME _OBJECT_NAME\
#define WINDOW_NAME _WINDOW_NAME\
#define WIN_STYLES _WIN_STYLES\
#define WCLASS_STYLES _WCLASS_STYLES\
struct OBJECT_NAME##_s {
#endif
|