Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (71 loc) · 2.11 KB
/
Copy pathmain.cpp
File metadata and controls
88 lines (71 loc) · 2.11 KB
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
#include <windows.h>
#include "sound.h"
using namespace std;
Sound sound;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) {
switch (message) {
case WM_LBUTTONDOWN: {
int x = (short)LOWORD(lParam);
int y = (short)LOWORD(lParam);
RECT rect;
GetWindowRect(hWnd, &rect);
int winWidth = rect.right - rect.left;
int winHeight = rect.bottom - rect.top;
sound.play(x, y, winWidth, winHeight);
} break;
case WM_LBUTTONUP: {
sound.pause();
} break;
case WM_MOUSEMOVE: {
if (wParam & MK_LBUTTON) {
int x = (short)LOWORD(lParam);
int y = (short)LOWORD(lParam);
RECT rect;
GetWindowRect(hWnd, &rect);
int winWidth = rect.right - rect.left;
int winHeight = rect.bottom - rect.top;
sound.play(x, y, winWidth, winHeight);
}
} break;
case WM_DESTROY:
sound.destroy();
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam,lParam);
}
return 0;
}
// "main function for windows application"
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hprevInstance,
LPSTR lpCmdLine, int nCmdShow) {
// windows class
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = L"SoundWindowClass";
wcex.hIconSm = 0;
// register the window class
RegisterClassEx(&wcex);
HWND hWnd = CreateWindow(
L"SoundWindowClass", L"Orquesta", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
// display window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}