質問編集履歴

2

ソースコードの変更

2016/12/04 12:09

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,306 @@
1
+ ```#define BMPFILE TEXT("test.bmp")
2
+
3
+
4
+
5
+ #include <windows.h>
6
+
7
+
8
+
9
+ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
10
+
11
+ ATOM InitApp(HINSTANCE);
12
+
13
+ BOOL InitInstance(HINSTANCE, int);
14
+
15
+
16
+
17
+ TCHAR szClassName[] = TEXT("template"); //ウィンドウクラス
18
+
19
+
20
+
21
+
22
+
23
+ #pragma region InitWindow
24
+
25
+
26
+
27
+ int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
28
+
29
+ LPSTR lpsCmdLine, int nCmdShow)
30
+
31
+ {
32
+
33
+ MSG msg;
34
+
35
+ BOOL bRet;
36
+
37
+
38
+
39
+ if (!InitApp(hCurInst))
40
+
41
+ return FALSE;
42
+
43
+ if (!InitInstance(hCurInst, nCmdShow))
44
+
45
+ return FALSE;
46
+
47
+ while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
48
+
49
+ if (bRet == -1) {
50
+
51
+ break;
52
+
53
+ } else {
54
+
55
+ TranslateMessage(&msg);
56
+
57
+ DispatchMessage(&msg);
58
+
59
+ }
60
+
61
+ }
62
+
63
+ return (int)msg.wParam;
64
+
65
+ }
66
+
67
+
68
+
69
+ //ウィンドウ・クラスの登録
70
+
71
+
72
+
73
+ ATOM InitApp(HINSTANCE hInst)
74
+
75
+ {
76
+
77
+ WNDCLASSEX wc;
78
+
79
+ wc.cbSize = sizeof(WNDCLASSEX);
80
+
81
+ wc.style = CS_HREDRAW | CS_VREDRAW;
82
+
83
+ wc.lpfnWndProc = WndProc; //プロシージャ名
84
+
85
+ wc.cbClsExtra = 0;
86
+
87
+ wc.cbWndExtra = 0;
88
+
89
+ wc.hInstance = hInst;//インスタンス
90
+
91
+ wc.hIcon = (HICON)LoadImage(NULL,
92
+
93
+ MAKEINTRESOURCE(IDI_APPLICATION),
94
+
95
+ IMAGE_ICON,
96
+
97
+ 0,
98
+
99
+ 0,
100
+
101
+ LR_DEFAULTSIZE | LR_SHARED);
102
+
103
+ wc.hCursor = (HCURSOR)LoadImage(NULL,
104
+
105
+ MAKEINTRESOURCE(IDC_ARROW),
106
+
107
+ IMAGE_CURSOR,
108
+
109
+ 0,
110
+
111
+ 0,
112
+
113
+ LR_DEFAULTSIZE | LR_SHARED);
114
+
115
+ wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
116
+
117
+ wc.lpszMenuName = NULL; //メニュー名
118
+
119
+ wc.lpszClassName = (LPCTSTR)szClassName;
120
+
121
+ wc.hIconSm = (HICON)LoadImage(NULL,
122
+
123
+ MAKEINTRESOURCE(IDI_APPLICATION),
124
+
125
+ IMAGE_ICON,
126
+
127
+ 0,
128
+
129
+ 0,
130
+
131
+ LR_DEFAULTSIZE | LR_SHARED);
132
+
133
+
134
+
135
+ return (RegisterClassEx(&wc));
136
+
137
+ }
138
+
139
+
140
+
141
+ //ウィンドウの生成
142
+
143
+
144
+
145
+ BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
146
+
147
+ {
148
+
149
+ HWND hWnd;
150
+
151
+
152
+
153
+ hWnd = CreateWindow(szClassName,
154
+
155
+ TEXT("Windowsプログラミング"), //タイトルバーにこの名前が表示されます
156
+
157
+ WS_OVERLAPPEDWINDOW, //ウィンドウの種類
158
+
159
+ CW_USEDEFAULT, //X座標
160
+
161
+ CW_USEDEFAULT, //Y座標
162
+
163
+ CW_USEDEFAULT, //幅
164
+
165
+ CW_USEDEFAULT, //高さ
166
+
167
+ NULL, //親ウィンドウのハンドル、親を作るときはNULL
168
+
169
+ NULL, //メニューハンドル、クラスメニューを使うときはNULL
170
+
171
+ hInst, //インスタンスハンドル
172
+
173
+ NULL);
174
+
175
+ if (!hWnd)
176
+
177
+ return FALSE;
178
+
179
+ ShowWindow(hWnd, nCmdShow);
180
+
181
+ UpdateWindow(hWnd);
182
+
183
+ return TRUE;
184
+
185
+ }
186
+
187
+
188
+
189
+ #pragma endregion
190
+
191
+
192
+
193
+ //ウィンドウプロシージャ
194
+
195
+
196
+
197
+ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
198
+
199
+ {
200
+
201
+ int id;
202
+
203
+
204
+
205
+ HDC hdc; // デバイスコンテキストハンドル(描画の出力先(ディスプレイ)へのハンドル)
206
+
207
+ PAINTSTRUCT ps; // 描画構造体
208
+
209
+ static HDC hMemDC;
210
+
211
+ static HBITMAP hBitmap; // ビットマップハンドル
212
+
213
+ static BITMAP bitmap; // ビットマップ
214
+
215
+
216
+
217
+ switch (msg) {
218
+
219
+ case WM_CREATE:
220
+
221
+ {
222
+
223
+ hMemDC = CreateCompatibleDC(NULL);
224
+
225
+ hBitmap = (HBITMAP)LoadImage(
226
+
227
+ (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
228
+
229
+ BMPFILE,IMAGE_BITMAP,
230
+
231
+ 0,0,LR_LOADFROMFILE);
232
+
233
+
234
+
235
+ SelectObject(hMemDC,hBitmap);
236
+
237
+ GetObject(hBitmap,sizeof(BITMAP),&bitmap);
238
+
239
+ }
240
+
241
+ break;
242
+
243
+ case WM_PAINT:
244
+
245
+ {
246
+
247
+ hdc = BeginPaint(hWnd,&ps);
248
+
249
+ BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hMemDC,0,0,SRCCOPY);
250
+
251
+ EndPaint(hWnd,&ps);
252
+
253
+ }
254
+
255
+ break;
256
+
257
+ case WM_CLOSE:
258
+
259
+ {
260
+
261
+ id = MessageBox(hWnd,
262
+
263
+ TEXT("終了してもよろしいですか"),
264
+
265
+ TEXT("確認"),
266
+
267
+ MB_YESNO | MB_ICONQUESTION);
268
+
269
+ if (id == IDYES)
270
+
271
+ DestroyWindow(hWnd);
272
+
273
+ }
274
+
275
+ break;
276
+
277
+ case WM_DESTROY:
278
+
279
+ {
280
+
281
+ DeleteDC(hMemDC); // デバイスコンテキストの削除
282
+
283
+ DeleteObject(hBitmap); // ビットマップの消去
284
+
285
+ PostQuitMessage(0);
286
+
287
+ }
288
+
289
+ break;
290
+
291
+ default:
292
+
293
+ return (DefWindowProc(hWnd, msg, wp, lp));
294
+
295
+ }
296
+
297
+ return 0;
298
+
299
+ }
300
+
301
+ コード
302
+
1
- [問題のソースコード](http://k3tec.net/neko_wiki/index.php?Win32API%20bmp%A5%D5%A5%A1%A5%A4%A5%EB%C6%C9%A4%DF%B9%FE%A4%DF)
303
+ ```[問題のソースコード](http://k3tec.net/neko_wiki/index.php?Win32API%20bmp%A5%D5%A5%A1%A5%A4%A5%EB%C6%C9%A4%DF%B9%FE%A4%DF)
2
304
 
3
305
 
4
306
 

1

リンクの追加

2016/12/04 12:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,303 +1,5 @@
1
- 以下のコードをVisualStudio2015で実行したところプリコンパイルヘッダーを検索中に不明なEOFが見つかりました。#include "stdafx.h"をソースに追加しましたか?というエラーが出ました。どうすればビルドできるようになるでしょうか?
1
+ [問題ソースコード](http://k3tec.net/neko_wiki/index.php?Win32API%20bmp%A5%D5%A5%A1%A5%A4%A5%EB%C6%C9%A4%DF%B9%FE%A4%DF)
2
2
 
3
3
 
4
4
 
5
- #define BMPFILE TEXT("test.bmp")
6
-
7
-
8
-
9
- #include <windows.h>
10
-
11
-
12
-
13
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
14
-
15
- ATOM InitApp(HINSTANCE);
16
-
17
- BOOL InitInstance(HINSTANCE, int);
18
-
19
-
20
-
21
- TCHAR szClassName[] = TEXT("template"); //ウィンウクラス
5
+ このサイトのソースコードをVisualStudio2015で実行したところプリコンパイルヘッダーを検索中に不明なEOFが見つかりました。#include "stdafx.h"をソースに追加しましたか?というエラーが出ました。どうすればビルできるようになるでしょうか?
22
-
23
-
24
-
25
-
26
-
27
- #pragma region InitWindow
28
-
29
-
30
-
31
- int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
32
-
33
- LPSTR lpsCmdLine, int nCmdShow)
34
-
35
- {
36
-
37
- MSG msg;
38
-
39
- BOOL bRet;
40
-
41
-
42
-
43
- if (!InitApp(hCurInst))
44
-
45
- return FALSE;
46
-
47
- if (!InitInstance(hCurInst, nCmdShow))
48
-
49
- return FALSE;
50
-
51
- while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
52
-
53
- if (bRet == -1) {
54
-
55
- break;
56
-
57
- } else {
58
-
59
- TranslateMessage(&msg);
60
-
61
- DispatchMessage(&msg);
62
-
63
- }
64
-
65
- }
66
-
67
- return (int)msg.wParam;
68
-
69
- }
70
-
71
-
72
-
73
- //ウィンドウ・クラスの登録
74
-
75
-
76
-
77
- ATOM InitApp(HINSTANCE hInst)
78
-
79
- {
80
-
81
- WNDCLASSEX wc;
82
-
83
- wc.cbSize = sizeof(WNDCLASSEX);
84
-
85
- wc.style = CS_HREDRAW | CS_VREDRAW;
86
-
87
- wc.lpfnWndProc = WndProc; //プロシージャ名
88
-
89
- wc.cbClsExtra = 0;
90
-
91
- wc.cbWndExtra = 0;
92
-
93
- wc.hInstance = hInst;//インスタンス
94
-
95
- wc.hIcon = (HICON)LoadImage(NULL,
96
-
97
- MAKEINTRESOURCE(IDI_APPLICATION),
98
-
99
- IMAGE_ICON,
100
-
101
- 0,
102
-
103
- 0,
104
-
105
- LR_DEFAULTSIZE | LR_SHARED);
106
-
107
- wc.hCursor = (HCURSOR)LoadImage(NULL,
108
-
109
- MAKEINTRESOURCE(IDC_ARROW),
110
-
111
- IMAGE_CURSOR,
112
-
113
- 0,
114
-
115
- 0,
116
-
117
- LR_DEFAULTSIZE | LR_SHARED);
118
-
119
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
120
-
121
- wc.lpszMenuName = NULL; //メニュー名
122
-
123
- wc.lpszClassName = (LPCTSTR)szClassName;
124
-
125
- wc.hIconSm = (HICON)LoadImage(NULL,
126
-
127
- MAKEINTRESOURCE(IDI_APPLICATION),
128
-
129
- IMAGE_ICON,
130
-
131
- 0,
132
-
133
- 0,
134
-
135
- LR_DEFAULTSIZE | LR_SHARED);
136
-
137
-
138
-
139
- return (RegisterClassEx(&wc));
140
-
141
- }
142
-
143
-
144
-
145
- //ウィンドウの生成
146
-
147
-
148
-
149
- BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
150
-
151
- {
152
-
153
- HWND hWnd;
154
-
155
-
156
-
157
- hWnd = CreateWindow(szClassName,
158
-
159
- TEXT("Windowsプログラミング"), //タイトルバーにこの名前が表示されます
160
-
161
- WS_OVERLAPPEDWINDOW, //ウィンドウの種類
162
-
163
- CW_USEDEFAULT, //X座標
164
-
165
- CW_USEDEFAULT, //Y座標
166
-
167
- CW_USEDEFAULT, //幅
168
-
169
- CW_USEDEFAULT, //高さ
170
-
171
- NULL, //親ウィンドウのハンドル、親を作るときはNULL
172
-
173
- NULL, //メニューハンドル、クラスメニューを使うときはNULL
174
-
175
- hInst, //インスタンスハンドル
176
-
177
- NULL);
178
-
179
- if (!hWnd)
180
-
181
- return FALSE;
182
-
183
- ShowWindow(hWnd, nCmdShow);
184
-
185
- UpdateWindow(hWnd);
186
-
187
- return TRUE;
188
-
189
- }
190
-
191
-
192
-
193
- #pragma endregion
194
-
195
-
196
-
197
- //ウィンドウプロシージャ
198
-
199
-
200
-
201
- LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
202
-
203
- {
204
-
205
- int id;
206
-
207
-
208
-
209
- HDC hdc; // デバイスコンテキストハンドル(描画の出力先(ディスプレイ)へのハンドル)
210
-
211
- PAINTSTRUCT ps; // 描画構造体
212
-
213
- static HDC hMemDC;
214
-
215
- static HBITMAP hBitmap; // ビットマップハンドル
216
-
217
- static BITMAP bitmap; // ビットマップ
218
-
219
-
220
-
221
- switch (msg) {
222
-
223
- case WM_CREATE:
224
-
225
- {
226
-
227
- hMemDC = CreateCompatibleDC(NULL);
228
-
229
- hBitmap = (HBITMAP)LoadImage(
230
-
231
- (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
232
-
233
- BMPFILE,IMAGE_BITMAP,
234
-
235
- 0,0,LR_LOADFROMFILE);
236
-
237
-
238
-
239
- SelectObject(hMemDC,hBitmap);
240
-
241
- GetObject(hBitmap,sizeof(BITMAP),&bitmap);
242
-
243
- }
244
-
245
- break;
246
-
247
- case WM_PAINT:
248
-
249
- {
250
-
251
- hdc = BeginPaint(hWnd,&ps);
252
-
253
- BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hMemDC,0,0,SRCCOPY);
254
-
255
- EndPaint(hWnd,&ps);
256
-
257
- }
258
-
259
- break;
260
-
261
- case WM_CLOSE:
262
-
263
- {
264
-
265
- id = MessageBox(hWnd,
266
-
267
- TEXT("終了してもよろしいですか"),
268
-
269
- TEXT("確認"),
270
-
271
- MB_YESNO | MB_ICONQUESTION);
272
-
273
- if (id == IDYES)
274
-
275
- DestroyWindow(hWnd);
276
-
277
- }
278
-
279
- break;
280
-
281
- case WM_DESTROY:
282
-
283
- {
284
-
285
- DeleteDC(hMemDC); // デバイスコンテキストの削除
286
-
287
- DeleteObject(hBitmap); // ビットマップの消去
288
-
289
- PostQuitMessage(0);
290
-
291
- }
292
-
293
- break;
294
-
295
- default:
296
-
297
- return (DefWindowProc(hWnd, msg, wp, lp));
298
-
299
- }
300
-
301
- return 0;
302
-
303
- }