Не могу разобратся с препроцесорными константами в многофайловых проектах
23.01.2016, 01:39. Показов 351. Ответов 1
Проблема следующая: значение константы, созданной препроцесором, различная в разных фаилах многофаилового проекта, вот код:
Фаил main.cpp
C++ | 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
| #include "Creater.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hProgInst, HINSTANCE hPrevInstance, LPSTR nCmdLine, int nCmdShow)
{
try
{
MSG msg;
Creater Program(hProgInst);
Program.CreateClass(WndProc);
Program.CreateAndShowWindows(nCmdShow);
while(GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
catch(LPCSTR ErrorMessage)
{
MessageBox(NULL, ErrorMessage, "ERROR(Ошибка)!", MB_OK);
return 0;
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hMainWindow, UINT MessageValue, WPARAM wMessageParam, LPARAM lMessageParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(MessageValue)
{
case WM_CREATE:
break;
case WM_PAINT:
hdc = BeginPaint(hMainWindow, &ps);
GetClientRect(hMainWindow, &rect);
EndPaint(hMainWindow, &ps);
break;
case WM_COMMAND:
break;
case WM_CLOSE:
break;
case WM_DESTROY:
break;
case WM_QUIT:
break;
default:
return DefWindowProc(hMainWindow, MessageValue, wMessageParam, lMessageParam);
}
} |
|
Фаил creater.cpp
C++ | 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
120
121
122
123
124
125
126
127
128
| #include "Creater.h"
#if (DoAllInCreater == 1)
Creater::Creater(HINSTANCE hInst, int nCmdShow, LRESULT(CALLBACK*WindowsProcedure)(HWND, UINT, WPARAM, LPARAM), LPCSTR ClassName)
{
hMainProgInst = hInst;
WCEX.cbClsExtra = NULL;
WCEX.cbSize = sizeof(&WCEX);
WCEX.cbWndExtra = NULL;
WCEX.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
WCEX.hCursor = LoadCursor(NULL, IDC_ARROW);
WCEX.hIcon = LoadIcon(NULL, IDI_WINLOGO);
WCEX.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
WCEX.hInstance = hInst;
WCEX.lpfnWndProc = WindowsProcedure;
WCEX.lpszClassName = ClassName;
WCEX.lpszMenuName = NULL;
WCEX.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClassEx(&WCEX))
{
#if (UserTry == 1)
throw "Error width class registration(ошибка в регистрации класса).";
#else
#endif
}
hMainWindowProg = CreateWindowEx(NULL,
MainProgrammClassName,
"",
WS_SYSMENU | WS_MAXIMIZEBOX,
CW_USEDEFAULT, NULL,
CW_USEDEFAULT, NULL,
NULL,
NULL,
hMainProgInst,
NULL);
if(!hMainProgInst)
{
#if (UseTry == 1)
throw "Error width window creating(ошибка в создании окна).";
#else
#endif
}
ShowWindow(hMainWindowProg, nCmdShow);
while(GetMessage(&MainProgramMessageStruct, NULL, NULL, NULL))
{
TranslateMessage(&MainProgramMessageStruct);
DispatchMessage(&MainProgramMessageStruct);
}
}
#elif (DoAllInCreater == 0)
Creater::Creater(HINSTANCE hInst)
{
hMainProgInst = hInst;
}
void Creater::CreateClass(LRESULT(CALLBACK*WindowsProcedure)(HWND, UINT, WPARAM, LPARAM), LPCSTR ClassName)
{
WCEX.cbClsExtra = NULL;
WCEX.cbSize = sizeof(&WCEX);
WCEX.cbWndExtra = NULL;
WCEX.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
WCEX.hCursor = LoadCursor(NULL, IDC_ARROW);
WCEX.hIcon = LoadIcon(NULL, IDI_WINLOGO);
WCEX.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
WCEX.hInstance = hMainProgInst;
WCEX.lpfnWndProc = WindowsProcedure;
WCEX.lpszClassName = MainProgrammClassName = ClassName;
WCEX.lpszMenuName = NULL;
WCEX.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClassEx(&WCEX))
{
#if (UserTry == 1)
throw "Error width class registration(ошибка в регистрации класса).";}
#else
#endif
}
}
void Creater::CreateAndShowWindows(int nCmdShow)
{
hMainWindowProg = CreateWindowEx(NULL,
MainProgrammClassName,
"",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, NULL,
CW_USEDEFAULT, NULL,
NULL,
NULL,
hMainProgInst,
NULL);
if(!hMainProgInst)
{
#if (UseTry == 1)
throw "Error width window creating(ошибка в создании окна).";
#else
#endif
}
ShowWindow(hMainWindowProg, nCmdShow);
}
#if (UseCycleInFuncion == 1)
void Creater::StartCycl()
{
while(GetMessage(&MainProgramMessageStruct, NULL, NULL, NULL))
{
TranslateMessage(&MainProgramMessageStruct);
DispatchMessage(&MainProgramMessageStruct);
}
}
#elif (UseCycleInFuncion == 0)
HWND Creater::GetHWND()
{
return hMainWindowProg;
}
#endif
Creater::~Creater()
{
} |
|
Фаил creater.h
C++ | 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
| #if !defined(CREATER_H)
#define CREATER_H
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
/**
Primary program configuration(первичная конфинурация программы)
@param DefaultClassName Set default name of registered class(установка имени класса окна по-умолчанию)
@param UseTry Use throw functions from error processing(Использование функции throw для обработки исключений)
@param DoAllInCreater Do all method in Creater(использование конструктора для обеспечения работы всей WinMain)
**/
#if !defined(DefaultClassName)
#define DefaultClassName "DefaultWindowClassNameFromCreaterClass"
#endif
#if !defined(UseTry)
#define UseTry 1
#endif
#if !defined(DoAllInCreater)
#define DoAllInCreater 0
#endif
#if !defined(UseCycleInFuncion)
#define UseCycleInFuncion 0
#endif
class Creater
{
private:
HINSTANCE hMainProgInst;
LPCSTR MainProgrammClassName;
WNDCLASSEX WCEX;
HWND hMainWindowProg;
MSG MainProgramMessageStruct;
public:
#if (DoAllInCreater == 1)
Creater(HINSTANCE, int, LRESULT(CALLBACK*)(HWND, UINT, WPARAM, LPARAM), LPCSTR ClassName = DefaultClassName);
#elif (DoAllInCreater == 0)
Creater(HINSTANCE);
void CreateClass(LRESULT(CALLBACK*)(HWND, UINT, WPARAM, LPARAM), LPCSTR ClassName = DefaultClassName);
void CreateAndShowWindows(int);
#if (UseCycleInFuncion == 1)
void StartCycl();
#elif (UseCycleInFuncion == 0)
HWND GetHWND();
#endif
#endif
~Creater();
};
#endif |
|
0
|