思うように出来なかったので、どこか間違いがあれば、教えてください。
#include <windows.h>
// グローバル変数
HWND hMainWindow;
HINSTANCE hInstance;
//ウィンドウプロシージャ作成
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg){
case WM_DESTROY:
/*
* Windowを消しても メモリにはプログラムが残ってる
* 場合があるので 消したらメモリからも消えるように
*/
PostQuitMessage(0);
break;
default:
//Windowsに処理を任せる
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
int WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSIR cmdLine, int cmdShow)
{
hInstance = hInst;
WNDCLASSEX wc;
/*** WINDCLASSEX(ウィンドウ作成) の設定***/
static LPSTR pClassName = "Test"; // クラス名
wc.cbSize = sizeof(WNDCLASSEX); // 構造体サイズ
wc.style = CS_HREDRAW | CS_VREDRAW; // クラススタイル
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0; // 不足メモリ
wc.cbWndExtra = 0; // のサイズ
wc.hInstance = hInst; // インスタンス
wc.hIcon = NULL; // アイコン
wc.hCursor = LoadCursor(NULL.IDC_ARROW); // カーソル
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // 背景色
wc.lpszMenuName = NULL; // メニュー
wc.lpszClassName = pClassName; // クラス名
wc.hIconSm = NULL; // アイコン
if (!RegisterClassEx(&wc)) return FALESE; // 登録
//Windowサイズ指定専用API
//AdjustWindowRectEX -> Windowの大きさを計算するAPI
RECT r;
r.left = r.top = 0;
r.right = 24 * 10;
r.bottom = 24 * 20;
AdjustWindowRectEx(&r, WS_OVERLAPPED | WS_MINIMIZEBOX |
WS_SYSMENU | WS_CAPTION, false, 0);
//ウィンドウの作成
hMainWindow = CreateWindow(pClassName, "Test", WS_OVERLAPPED | WS_MINIMIZEBOX |
WS_SYSMENU | WS_CAPTION, CW_USEDEFALUT, CW_USEDEFAULT,
r.right - r.left, r.bottom - r.left, NULL, NULL, hInst, NULL);
ShowWindow(hMainWindow, SW_SHOW);
//メッセージループ
MSG msg;
while(GetMessage(&msg, NULL, 0,0)){
TranslateMessage(&msg); //キー入力を扱いやすくする
DispatchMessage(&msg); //関連付けられたウィンドウプロシージャへディスパッチ
}
return 0;
}
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
c:\users\kai\desktop\c\tetris.cpp:
エラー E2303 c:\users\kai\desktop\c\tetris.cpp 28: 型名が必要
*** 1 errors in Compile ***
** error 1 ** deleting Debug\tetris.obj
Make End !! (Elapsed time 0:00.671)
このように表示され、
MinGWからコンパイルすると
tetris.cpp: In function 'LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':
tetris.cpp:21:53: error: 'IParam' was not declared in this scope
tetris.cpp: At global scope:
tetris.cpp:28:13: error: 'int WinMain' redeclared as different kind of symbol
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winbase.h:1251:14: err
or: previous declaration of 'int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)
'
tetris.cpp:28:13: error: 'HINSRANCE' was not declared in this scope
tetris.cpp:28:30: error: 'HINSRANCE' was not declared in this scope
tetris.cpp:28:51: error: 'LPSIR' was not declared in this scope
tetris.cpp:28:66: error: expected primary-expression before 'int'
このように表示されます。