-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
284 lines (213 loc) · 8.55 KB
/
main.cpp
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
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <windows.h>
#include <tchar.h>
#include <stdlib.h>
#include <string.h>
#include "IDS.h"
#define WM_SIZE 0x0005
HINSTANCE g_hInst;
/* Declaración del procedimiento de ventana */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
// Datos de la aplicación
typedef struct stDatos {
int ValorH;
int ValorV;
char Texto[80];
} DATOS;
/*
HWND CreateScrollbar(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,
const RECT& rc,const int id)
{
dwStyle|=WS_CHILD|WS_VISIBLE;
return CreateWindowEx(0, //extended styles
_T("scrollbar"), //control 'class' name
0, //control caption
dwStyle, //control style
rc.left, //position: left
rc.top, //position: top
rc.right, //width
rc.bottom, //height
hParent, //parent window handle
//control's ID
reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
hInst, //application instance
0); //user defined info
}
*/
/* Esta función es invocada por la función DispatchMessage() */
LRESULT CALLBACK OnEvent(HWND Handle, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;
static DATOS Datos;
static DATOS *Datoss;
/* Botón */
HWND hwndButton;
HWND hwndScrollBarH;
switch (msg) /* manipulador del mensaje */
{
case WM_CREATE:
{
Datoss = (DATOS*)lParam;
hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
Datos.ValorH = 10;
Datos.ValorV = 32;
// Crear botón
hwndButton = CreateWindowEx(0, /* more or ''extended'' styles */
TEXT("BUTTON"), /* GUI ''class'' to create */
TEXT("Horacio"), /* GUI caption */
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, /* control styles separated by | */
100, /* LEFT POSITION (Position from left) */
10, /* TOP POSITION (Position from Top) */
200, /* WIDTH OF CONTROL */
30, /* HEIGHT OF CONTROL */
Handle, /* Parent window handle */
(HMENU)ID_BUTTON, /* control''s ID for WM_COMMAND */
g_hInst, /* application instance */
NULL);
// Crear Scrollbar Horizontal
//RECT rh={(64*2+22+5),(720-15),(1024-(64*2+20+27)),15};
//CreateScrollbar(Handle,hInstance,SBS_HORZ,rh,ID_SCROLLHH);
// Crear Scrollbar Vertical
//RECT rv={(1024-20),0,15,(748-20-23)};
//CreateScrollbar(Handle,hInstance,SBS_VERT,rv,ID_SCROLLVV);
break;
}
case WM_SIZE:
{
std::cout << "RESIZE" << std::endl;
/*
AQUI QUIERO PODER HACER UN REDRAW DE SFMLView1
*/
}
case WM_COMMAND:
{
// Menu Archivo --> Abrir diálogo
if(LOWORD(wParam) == CM_DIALOGO)
{
DialogBoxParam(hInstance, "DialogoPrueba", Handle, DlgProc, (LPARAM)&Datos);
}
// Menu Archivo --> Abrir diálogo
if(LOWORD(wParam) == CM_CLOSE)
{
PostQuitMessage(0);
}
// Menu Ver --> 1440x900
if(LOWORD(wParam) == CM_SIZEA)
{
SetWindowPos(Handle,HWND_TOP,0,0,1440,900,SWP_NOMOVE);
}
// Menu Ver --> 1680x1050
if(LOWORD(wParam) == CM_SIZEB)
{
SetWindowPos(Handle,HWND_TOP,0,0,1680,1050,SWP_NOMOVE);
}
// Menu Ver --> 1920x1080
if(LOWORD(wParam) == CM_SIZEC)
{
SetWindowPos(Handle,HWND_TOP,0,0,1920,1080,SWP_NOMOVE);
}
break;
}
case WM_DESTROY:
PostQuitMessage(0); /* envía un mensaje WM_QUIT a la cola de mensajes */
break;
default: /* para los mensajes de los que no nos ocupamos */
return DefWindowProc(Handle, msg, wParam, lParam);
}
return 0;
}
BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static DATOS *Datos;
switch (msg) /* manipulador del mensaje */
{
case WM_INITDIALOG:
Datos = (DATOS*)lParam;
SetScrollRange(GetDlgItem(hDlg, ID_SCROLLH), SB_CTL,
0, 100, TRUE);
SetScrollPos(GetDlgItem(hDlg, ID_SCROLLH), SB_CTL,
Datos->ValorH, TRUE);
SetDlgItemInt(hDlg, ID_EDITH, (UINT)Datos->ValorH, FALSE);
SendDlgItemMessage(hDlg, ID_SCROLLV, SBM_SETRANGE,
(WPARAM)0, (LPARAM)50);
SendDlgItemMessage(hDlg, ID_SCROLLV, SBM_SETPOS,
(WPARAM)Datos->ValorV, (LPARAM)TRUE);
SetDlgItemInt(hDlg, ID_EDITV, (UINT)Datos->ValorV, FALSE);
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hDlg, FALSE);
return TRUE;
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
}
return TRUE;
}
return FALSE;
}
INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT)
{
// Define a class for our main window
WNDCLASS WindowClass;
WindowClass.style = 0;
WindowClass.lpfnWndProc = &OnEvent;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = Instance;
WindowClass.hIcon = NULL;
WindowClass.hCursor = 0;
WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
WindowClass.lpszMenuName = "Menu";
WindowClass.lpszClassName = "SFML App";
RegisterClass(&WindowClass);
// Let's create the main window
//HWND Window = CreateWindow("SFML App", "SFML Win32", WS_SYSMENU | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, 0, 0, 800, 600, NULL, NULL, Instance, NULL);
HWND Window = CreateWindow("SFML App", "SFML Win32", WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPEDWINDOW, 0, 0, 1680, 1050, NULL, NULL, Instance, NULL);
// Let's create two SFML views
HWND View1 = CreateWindow("STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 0, 0, 64*2+22, 748, Window, NULL, Instance, NULL);
HWND View2 = CreateWindow("STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 64*2+22+5, 0, (1024-(64*2+20+27)), (748-20-23), Window, NULL, Instance, NULL);
sf::RenderWindow SFMLView1(View1);
sf::RenderWindow SFMLView2(View2);
// Cargar imgs
sf::Texture Image1, Image2;
if (!Image1.LoadFromFile("images/sprites/image1.png") || !Image2.LoadFromFile("images/sprites/image2.png"))
return EXIT_FAILURE;
sf::Sprite Sprite1(Image1);
sf::Sprite Sprite2(Image2);
// Loop until a WM_QUIT message is received
MSG Message;
Message.message = ~WM_QUIT;
while (Message.message != WM_QUIT)
{
if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
{
// If a message was waiting in the message queue, process it
TranslateMessage(&Message);
DispatchMessage(&Message);
}
else
{
// Clear views
SFMLView1.Clear();
SFMLView2.Clear();
// Draw sprite 1 on view 1
SFMLView1.Draw(Sprite1);
// Draw sprite 2 on view 2
SFMLView2.Draw(Sprite2);
// Display each view on screen
SFMLView1.Display();
SFMLView2.Display();
}
}
// Destroy the main window
DestroyWindow(Window);
// Don't forget to unregister the window class
UnregisterClass("SFML App", Instance);
return EXIT_SUCCESS;
}