Ik ben een soort paint aan het maken met API calls, nu lukt alleen de repaint niet echt na het resizen/minimizen van een scherm. Hij blijft volledig leeg. Ik sla bij het creeeren het scherm op in een bitmap en roep die telkens weer aan na bij WM_PAINT. Probleem is ik weet niet hoe ik moet aangeven dat die bij resizen de bende opnieuw moet opslaan in die bitmap.
Please help
Please help
code:
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
| #include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdarg.h>
#include "resource.h"
#define HOOFD_VENSTER_KLASSENAAM "hoofdvensterklassenaam"
int mbox_printf(char *format, ...);
void mbox_lasterror(char *title);
void RegistreerHoofdVensterKlasse();
LRESULT CALLBACK HoofdVensterProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
bool CALLBACK LijndikteDialogFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ;
bool CALLBACK FiguurDialogFunction(HWND hdWnd, UINT message, WPARAM wParam, LPARAM lParam) ;
HPEN hRedpen, hGreenpen, hBluepen, hCurrentpen;
HBITMAP hbit ;
int iItem=0;
int endpoints=0,pendown=0,x=0,y=0,startX,startY,iLijndikte=1,iDialogFout, maxX,maxY;
HWND hDlg=0;
struct
{
HINSTANCE hInstance;
HWND hwHoofdVenster,hwClientVenster;
} globals;
int APIENTRY WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msgDeMessage;
globals.hInstance = hInstance;
RegistreerHoofdVensterKlasse();
// CreeerHoofdVenster
globals.hwHoofdVenster =globals.hwClientVenster = CreateWindow(HOOFD_VENSTER_KLASSENAAM,
"Practicum opdracht 3 Winnt1. Door Ruald Ordelman",
WS_OVERLAPPEDWINDOW, // Het is en normaal venster
CW_USEDEFAULT, 0, // Windows kiest zelf de locatie maar
800, 600, // deze afmetingen passen in iedere monitor
NULL, NULL, // geen menu, geen parent
globals.hInstance, NULL); // geen creation-data
ShowWindow(globals.hwHoofdVenster, nCmdShow); // maak venster zichtbaar
UpdateWindow( globals.hwHoofdVenster ); // zorg ervoor dat de inhoud nu getekend wordt
while (GetMessage(&msgDeMessage, NULL, 0, 0))
{
if(!hDlg || !IsDialogMessage(hDlg, &msgDeMessage)){
DispatchMessage(&msgDeMessage);
}
}
return 0;
}
void RegistreerHoofdVensterKlasse()
{
WNDCLASS wcMijnKlasse;
wcMijnKlasse.style = CS_HREDRAW | CS_VREDRAW;
wcMijnKlasse.lpfnWndProc = (WNDPROC)HoofdVensterProcedure;
wcMijnKlasse.cbClsExtra = 0;
wcMijnKlasse.cbWndExtra = 0;
wcMijnKlasse.hInstance = globals.hInstance;
wcMijnKlasse.hIcon = LoadIcon( NULL, IDI_APPLICATION ); // standaard icoontje dat door Windows wordt aangeboden
wcMijnKlasse.hCursor = LoadCursor(NULL, IDC_ARROW ); // standaard pijltje
wcMijnKlasse.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcMijnKlasse.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); // geen menu
wcMijnKlasse.lpszClassName = HOOFD_VENSTER_KLASSENAAM;
RegisterClass(&wcMijnKlasse);
}
LRESULT CALLBACK HoofdVensterProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc,memdc;
PAINTSTRUCT ps;
HBRUSH hbrush;
switch (message)
{
case WM_CREATE:
maxX = GetSystemMetrics(SM_CXSCREEN);
maxY = GetSystemMetrics(SM_CYSCREEN);
hdc = GetDC(hWnd);
memdc= CreateCompatibleDC(hdc);
hbit = CreateCompatibleBitmap(hdc, maxX, maxY);
SelectObject(memdc, hbit);
hbrush = (HBRUSH) GetStockObject(WHITE_BRUSH);
SelectObject(memdc, hbrush);
PatBlt(memdc, 0, 0, maxX, maxY, PATCOPY);
hRedpen = CreatePen(PS_SOLID, iLijndikte, RGB(255,0,0));
hGreenpen = CreatePen(PS_SOLID, iLijndikte, RGB(0,255,0));
hBluepen = CreatePen(PS_SOLID, iLijndikte, RGB(0,0,255));
ReleaseDC(hWnd, hdc);
break;
case WM_COMMAND:
switch (wParam){
case MENU_EXIT:
PostQuitMessage(0);
break;
case MENU_NEW:
ShowWindow(globals.hwClientVenster, 2); // maak venster zichtbaar
UpdateWindow( globals.hwClientVenster );
case MENU_LIJNDIKTE:
DialogBox(globals.hInstance,MAKEINTRESOURCE(DIALOG_LIJNDIKTE), hWnd, (DLGPROC)LijndikteDialogFunction);
break;
case MENU_ROOD:
hCurrentpen = hRedpen;
break;
case MENU_PAARS:
hCurrentpen = hBluepen;
break;
case MENU_ORANJE:
hCurrentpen = hGreenpen;
break;
case MENU_WIS:
InvalidateRect(hWnd, NULL,1);
break;
case MENU_CIRKEL:
iItem = 1;
break;
case MENU_VIERKANT:
iItem = 2;
break;
case MENU_LIJN:
iItem = 0;
break;
case MENU_FIGUUR:
hDlg = CreateDialog(globals.hInstance,MAKEINTRESOURCE(DIALOG_FIGUUR), hWnd, (DLGPROC)FiguurDialogFunction);
break;
}
case WM_LBUTTONUP:
if (pendown){
hdc=GetDC(hWnd);
if (iItem == 0){
SelectObject(hdc, hCurrentpen);
MoveToEx(hdc, x,y,NULL);
int stopX = x = LOWORD(lParam);
int stopY = y = HIWORD(lParam);
LineTo(hdc, stopX, stopY);
}
else if (iItem==2){
MoveToEx(hdc, x,y,NULL);
int stopX = x = LOWORD(lParam);
int stopY = y = HIWORD(lParam);
SelectObject(hdc,hCurrentpen);
Rectangle(hdc, startX,startY ,stopX,stopY);
}
else if (iItem==1){
MoveToEx(hdc, x,y,NULL);
int stopX = x = LOWORD(lParam);
int stopY = y = HIWORD(lParam);
SelectObject(hdc,hCurrentpen);
Ellipse(hdc,startX,startY, stopX, stopY);
//
}
ReleaseDC(hWnd,hdc);
}
pendown = 0;
break;
case WM_LBUTTONDOWN:
pendown = 1;
startX = x = LOWORD(lParam);
startY = y = HIWORD(lParam);
break;
case WM_MOUSEMOVE:
break;
case WM_CLOSE:
DestroyWindow(hWnd);
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
SelectObject(memdc, hbit);
BitBlt(hdc,0,0,maxX,maxY,memdc,0,0,SRCCOPY);
EndPaint(hWnd,&ps);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
bool CALLBACK LijndikteDialogFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_INITDIALOG:
SetDlgItemInt(hWnd, EDIT_LIJNDIKTE,iLijndikte,FALSE);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hWnd,0);
return 1;
case IDOK:
iLijndikte = GetDlgItemInt(hWnd,EDIT_LIJNDIKTE, &iDialogFout,false);
hRedpen = CreatePen(PS_SOLID, iLijndikte, RGB(255,0,0));
hGreenpen = CreatePen(PS_SOLID, iLijndikte, RGB(0,255,0));
hBluepen = CreatePen(PS_SOLID, iLijndikte, RGB(0,0,255));
hCurrentpen = hRedpen;
EndDialog(hWnd,0);
}
break;
default:
return FALSE;
}
return TRUE;
}
bool CALLBACK FiguurDialogFunction(HWND hdWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCELSET:
DestroyWindow(hdWnd);
hDlg=0;
return 1;
case IDOKSET:
if (SendDlgItemMessage(hdWnd, IDCIRKEL, BM_GETCHECK,0,0) == BST_CHECKED)
iItem = 1;
if (SendDlgItemMessage(hdWnd, IDVIERKANT, BM_GETCHECK,0,0) == BST_CHECKED)
iItem = 2;
if (SendDlgItemMessage(hdWnd, IDLIJN, BM_GETCHECK,0,0) == BST_CHECKED)
iItem = 0;
EndDialog(hdWnd,0);
}
break;
default:
return FALSE;
}
return TRUE;
}
/* Gebruik mbox_printf() op precies dezelfde manier als gewoon printf().
De text veschijnt nu echter in een MessageBox
*/
int mbox_printf(char *format, ...)
{
static char buffer[2000];
va_list rest;
va_start(rest, format);
_vsnprintf(buffer,2000, format, rest);
va_end(rest);
return MessageBox( NULL, buffer, "", MB_OK | MB_ICONINFORMATION );
}
/* Gebruik deze functie op precies dezelfde manier als perror() onder Linux.
De text veschijnt nu echter in een MessageBox
*/
void mbox_lasterror(char *title)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, title, MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
} |