HoI!
Ik ben bezig met het schrijven van een class om makkelijk windows mee aan te vragen in C++.
Ik krijg wat fouten en heb geeeen idee hoe ze op te lossen zijn.
Dit zijn de fouten:
Zo ziet mijn window_class.cpp eruit:
Zo word er een window aangemaakt:
Nougoed, zoals je ziet is er een static callback functie en een virtual callback functie..
De static functie word aangeroepen voor windows, die zou de pointer van het echte window moeten vinden en dan doorsturen naar de virtual function..
Geen idee ofals dit goed is hoe ik dit bedenk, heb een voorbeeld bekeken die ook een class had om windows te maken en die deed het ook ongeveer zo.
Verder, hoe laat ik mijn windows allemaal apart van elkaar werken ? Ik bedacht een systeem om dit zo te doen:
Is dit een normale/goede denkwijze ? Of word dit totaal anders gedaan..
Ben een newbie in het Win32 programmeren.
HoI! Chris.
Ik ben bezig met het schrijven van een class om makkelijk windows mee aan te vragen in C++.
Ik krijg wat fouten en heb geeeen idee hoe ze op te lossen zijn.
Dit zijn de fouten:
Zo ziet mijn class eruit in mijn header bestand voor de class:--------------------Configuration: Windows Classer - Win32 Debug--------------------
Compiling...
class_window.cpp
Skipping... (no relevant changes detected)
main.cpp
Linking...
main.obj : error LNK2005: "public: bool __thiscall cWindowClass::Build(char *,unsigned long,int,int,int,int,char *)" (?Build@cWindowClass@@QAE_NPADKHHHH0@Z) already defined in class_window.obj
main.obj : error LNK2005: "public: virtual long __stdcall cWindowClass::Win_Proc(struct HWND__ *,unsigned int,unsigned int,long)" (?Win_Proc@cWindowClass@@UAGJPAUHWND__@@IIJ@Z) already defined in class_window.obj
main.obj : error LNK2005: "private: static long __stdcall cWindowClass::stWin_Proc(struct HWND__ *,unsigned int,unsigned int,long)" (?stWin_Proc@cWindowClass@@CGJPAUHWND__@@IIJ@Z) already defined in class_window.obj
Debug/Windows Classer.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Windows Classer.exe - 4 error(s), 0 warning(s)
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
| #ifndef CLASS_WINDOW_H #define CLASS_WINDOW_H #include <windows.h> ///////// LET HIEROP DEZE REGEL ///////// // // Class for windowing // class cWindowClass { private: static LRESULT CALLBACK stWin_Proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); public: bool Build( LPSTR caption, DWORD window_style, int pos_left, int pos_top, int pos_height, int pos_width, LPSTR class_name ); virtual LRESULT CALLBACK Win_Proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); /** * Handle van de window die bij deze class object hoort * * HWND window_handle */ HWND window_handle; /** * Handle naar Process * * @var HINSTANCE h_main_instance */ HINSTANCE h_main_instance; }; // end class cWindowClass #endif // CLASS_WINDOW_H |
Zo ziet mijn window_class.cpp eruit:
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| // // Class en functie prototypen // #include "class_window.h" // // Array met alle window handles // int window_handles[]; /** * Functie die de window class bouwt en alles klaar zet zodat de window kan worden geregistreerd * * @param LPSTR caption De titel van het window * @param INT border Border type * @param INT pos_left Positie links( in pixels ) * @param INT pos_top Positie top( in pixels ) * @param INT pos_height Window hoogte * @param INT pos_width Window breedte * @param LPSTR window_id ID van de window in de array van windows */ bool cWindowClass::Build( LPSTR caption, DWORD window_style, int pos_left, int pos_top, int pos_height, int pos_width, LPSTR class_name ) { WNDCLASSEX wnd_class; HWND hwnd; // Maak het window aan wnd_class.cbSize = sizeof( WNDCLASSEX ); wnd_class.style = 0; wnd_class.lpfnWndProc = stWin_Proc; wnd_class.cbClsExtra = 0; wnd_class.cbWndExtra = 0; wnd_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd_class.hCursor = LoadCursor(NULL, IDC_ARROW); wnd_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wnd_class.lpszMenuName = NULL; wnd_class.lpszClassName = class_name; wnd_class.hInstance = this->h_main_instance; wnd_class.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // Registreer het window RegisterClassEx(&wnd_class); // // Maak het scherm daadwerkelijk aan // hwnd = CreateWindowEx ( NULL, // extended style class_name, // class name waar gegevens van window in staan caption, // titel van het schermpje window_style, pos_left, pos_top, // initial x(left),y(top) pos_width, pos_height, // initial width, height NULL, // handle to parent NULL, // handle to menu cWindowClass::h_main_instance ,// instance of this application NULL ); // end function CreateWindowEx // sla de HWND handle op this->window_handle = hwnd; if( !hwnd ) { return(0); } return 0; } // end function Build( .. ) /** * Virtual functie pointer van de window * * @param HWND Window handle * @param UINT Bericht * @param WPARAM Info over bericht * @param LPARAM Info over bericht * */ LRESULT CALLBACK cWindowClass::Win_Proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch(uMsg) { // Het scherm word gesloten case WM_DESTROY: { // then close it MessageBox( hWnd, "Test berichtje!!", "Sluiten", MB_OK ); // PostQuitMessage( WM_QUIT ); break; } // end case WM_DESTROY default: { // Process the left-over messages return DefWindowProc(hWnd, uMsg, wParam, lParam); } } // end switch uMsg return DefWindowProc( hWnd, uMsg, wParam, lParam ); } /** * Static functie pointer van de window * * @param HWND Window handle * @param UINT Bericht * @param WPARAM Info over bericht * @param LPARAM Info over bericht * */ LRESULT CALLBACK cWindowClass::stWin_Proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { if (uMsg == WM_NCCREATE) { } return DefWindowProc(hWnd, uMsg, wParam, lParam ); } |
Zo word er een window aangemaakt:
C++:
1
2
3
| cWindowClass c_wnd; c_wnd.h_main_instance = hinstance; c_wnd.Build( "Schermpie met menu :D", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 500, 400, "Window1" ); |
Nougoed, zoals je ziet is er een static callback functie en een virtual callback functie..
De static functie word aangeroepen voor windows, die zou de pointer van het echte window moeten vinden en dan doorsturen naar de virtual function..
Geen idee ofals dit goed is hoe ik dit bedenk, heb een voorbeeld bekeken die ook een class had om windows te maken en die deed het ook ongeveer zo.
Verder, hoe laat ik mijn windows allemaal apart van elkaar werken ? Ik bedacht een systeem om dit zo te doen:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
| cWindowClass c_wnd; c_wnd.h_main_instance = hinstance; c_wnd.Build( "Schermpie met menu :D", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 500, 400, "Window1" ); // window word hier gestart, hier kunnen variablen worden ingesteld, knoppen worden aangemaakt enz enz enz c_wnd.OnLoad() { } // window word gesloten, hier kunnen geheugen dingen weer vrij worden gegeven c_wnd.OnClose() { } |
Is dit een normale/goede denkwijze ? Of word dit totaal anders gedaan..
Ben een newbie in het Win32 programmeren.
HoI! Chris.