File: MdiTest.h

package info (click to toggle)
devil 1.6.7-5%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 11,536 kB
  • ctags: 7,441
  • sloc: ansic: 35,573; sh: 8,075; cpp: 7,465; pascal: 792; makefile: 399; python: 47
file content (200 lines) | stat: -rw-r--r-- 3,664 bytes parent folder | download | duplicates (5)
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
#ifndef MDITEST_H
#define MDITEST_H

#include <windows.h>
#include <il\il.h>
#include <list>
#include <vector>
using namespace std;



HINSTANCE hInstance;
int CmdShow;
HWND MainHWnd, CurChildWnd;


#define TITLE		"OpenIL Windows Test"
#define CHILD		"OpenIL Child Window"


class cWindow
{
public:
	cWindow()
	{
		Width = 0;
		Height = 0;
		WinWidth = 0;
		WinHeight = 0;
		hWnd = 0;
		Bitmap = 0;
		hDC = 0;
		hMemDC = 0;
		sprintf(Title, "OpenIL Windows Test");
		return;
	}

	~cWindow()
	{
		return;
	}

	bool LoadImage(char *FileName)
	{
		Images.resize(1);

		ilGenImages(1, Images.begin());
		ilBindImage(Images[0]);
		if (!ilLoadImage(FileName)) {
			ilDeleteImages(1, Images.begin());
			return false;
		}

		Width = ilGetInteger(IL_IMAGE_WIDTH);
		Height = ilGetInteger(IL_IMAGE_HEIGHT);

		Create(FileName, 100, 100, Width + 8, Height + 23, MainHWnd);

		ILuint i = ilCloneCurImage();
		ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
		Bitmap = ilutConvertToHBitmap(hDC);
		ilDeleteImages(1, &i);
		SelectObject(hMemDC, Bitmap);

		sprintf(Title, FileName);
		SetWindowText(hWnd, Title);

		return true;
	}


	bool Create(char *Name, int x, int y, int width, int height, HWND Parent)
	{
		if (Parent) {
			hWnd = CreateWindow(CHILD, Name, WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS,
						x, y, width, height, Parent, NULL, hInstance, NULL);
		}
		else {
			hWnd = CreateWindow(TITLE, Name, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
						x, y, width, height, Parent, NULL, hInstance, NULL);
		}

		if (Parent == NULL)
			MainHWnd = hWnd;
		if (hWnd == NULL)
			return false;

		WinWidth = Width;
		WinHeight = Height;
		XPos = x;
		YPos = y;

		ShowWindow(hWnd, CmdShow);
		UpdateWindow(hWnd);
		InvalidateRect(hWnd, NULL, false);

		SetForegroundWindow(hWnd);
		SetFocus(hWnd);
		BringWindowToTop(hWnd);
		ShowWindow(hWnd, SW_SHOWNORMAL);

		CurChildWnd = hWnd;

		hDC = GetDC(hWnd);
		hMemDC = CreateCompatibleDC(hDC);

		return true;
	}

	void Destroy(void)
	{
		Width = 0;
		Height = 0;
		WinWidth = 0;
		WinHeight = 0;
		if (Bitmap)
			DeleteObject(Bitmap);
		if (hMemDC)
			DeleteDC(hMemDC);
		if (hDC && hWnd) {
			ReleaseDC(hWnd, hDC);
			DeleteDC(hDC);
		}
		if (hWnd)
			DestroyWindow(hWnd);
		if (Images.size()) {
			ilDeleteImages(Images.size(), Images.begin());
			Images.clear();
		}
		return;
	}

	HWND GetHWnd(void)
	{
		return hWnd;
	}

	void Paint(void)
	{
		if (!hWnd)
			return;
		PAINTSTRUCT ps;

		/*hDC = */BeginPaint(hWnd, &ps);
		BitBlt(hDC, 0, 0, (WORD)Width, (WORD)Height, hMemDC, 0, 0, SRCCOPY);
		EndPaint(hWnd, &ps);
		ValidateRect(hWnd, NULL);
		ShowWindow(hWnd, SW_SHOW);

		return;
	}

	void BindImage()
	{
		if (Images.size()) {
			ilBindImage(*(Images.begin() + Images.size() - 1));
		}
		return;
	}

	void SetTitle(char *Name)
	{
		sprintf(Title, Name);
		SetWindowText(hWnd, Title);
	}


protected:
	ILuint	XPos, YPos, Width, Height;
	ILuint	WinWidth, WinHeight;
	char	Title[512];

	vector <ILuint> Images;
	ILuint	UndoSize;

	HWND	hWnd;
	HBITMAP	Bitmap;
	HDC		hDC, hMemDC;

};


cWindow	MainWindow;
list <cWindow> WindowList;


cWindow *GetWinClass(HWND hWnd);
void AddNewWindow(char *FileName);
void DestroyWindows(void);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY AboutDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam);
BOOL APIENTRY FilterDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
BOOL APIENTRY ResizeDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
void GenFilterString(char *Out, char **Strings);
void ResizeWin(void);
void CreateGDI(void);
bool IsOpenable(char *FileName);


#endif//MDITEST_H