-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.cpp
executable file
·121 lines (100 loc) · 3.3 KB
/
try.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
#include <windows.h>
#include <stdio.h>
// USAGE:
// 1) save the instance and get a context from the window handle
// extern global_hdc = GetDC(hWnd);
// extern global_instance = hInstance;
//
// 2) Create the window
// makeWindow(posX,posY,width,height);
//
// 3) Render the Bitmap
//
// drawBitmap(file);
//
// This part of the program can be tested by compiling it
// g++ -DSTANDALONE -o bdisplay bisplay.cpp -lgdi32
#ifdef STANDALONE
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
ATOM MyRegisterClass(HINSTANCE);
#endif
void newWindow(int x, int y, int w, int h); // to replace InitInstance
void DrawBitmap(char*); // Give it the filename of bitmap
HDC global_hdc;
HWND global_bwnd;
HINSTANCE global_instance;
void makeWindow(int x, int y, int w, int h)
{
MyRegisterClass(global_instance);
global_bwnd = CreateWindow(
"FFT", //window class
"Bird Count", //title bar
WS_OVERLAPPEDWINDOW, //window style
x, y, w, h, //height of the window
NULL, //parent window
NULL, //menu
global_instance, //application instance
NULL); //window parameters
if (!global_bwnd) return;
global_hdc = GetDC(global_bwnd);
ShowWindow(global_bwnd, SW_RESTORE);
UpdateWindow(global_bwnd);
}
void drawBitmap(char *filename)
{
HBITMAP image;
image = (HBITMAP)LoadImage(0,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
BITMAP bm;
GetObject(image, sizeof(BITMAP), &bm); // get bitmap properties
HDC hdcMem = CreateCompatibleDC(global_hdc); //create device context
SelectObject(hdcMem, image);
BitBlt(global_hdc, // destination device context
0, 0, // x,y location on destination
bm.bmWidth, bm.bmHeight, // width,height of source bitmap
hdcMem, // source bitmap device context
0, 0, // start x,y on source bitmap
SRCCOPY ); // blit method
DeleteDC(hdcMem);
DeleteObject((HBITMAP)image);
}
#ifdef STANDALONE
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "FFT";
wc.hIconSm = NULL;
return RegisterClassEx(&wc);
}
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP,LPSTR c, int f)
{
char file[32];
global_instance = hI;
makeWindow(600,300,300,240); // Create the window
for (int i=0; i<8; i++)
{
sprintf(file, "budgie%d.bmp", i);
drawBitmap(file); // Render the Bitmap
Sleep(1000 + i*500);
}
}
#endif