新年早々早速質問させていただきます。
Win32プログラミングを始めるにあたって雛形となるプログラムを書いたのですが、なぜかCreateWindow関数の部分でNULLが帰ってしまいます
以下ソースコード
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE,int);
TCHAR szClassName[] = TEXT("Win32テスト");
HWND hWnd;
HINSTANCE hInstance;//インスタンスハンドルのグローバル変数
//エントリーポイント
int WINAPI WinMain(HINSTANCE hCurInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nCmdShow){
MSG msg;
hInstance = hCurInstance;
BOOL bRet;
if(!InitApp(hCurInstance)) return -1;
if(!InitInstance(hCurInstance,nCmdShow)) return -1;
while((bRet = GetMessage(&msg,NULL,0,0)) != 0){
if(bRet == -1){
break;
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp){
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc( hWnd, msg, wp, lp );
}
return 0;
}
ATOM InitApp(HINSTANCE hInst){
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = (HICON)LoadImage( // アイコン
NULL, MAKEINTRESOURCE(IDI_APPLICATION), IMAGE_ICON,
0, 0, LR_DEFAULTSIZE | LR_SHARED
);
wc.hIconSm = wc.hIcon;
wc.hCursor = (HCURSOR)LoadImage( // マウスカーソル
NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR,
0, 0, LR_DEFAULTSIZE | LR_SHARED);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
return RegisterClassEx(&wc);
}
BOOL InitInstance(HINSTANCE hInst,int nCmdShow){
hWnd = CreateWindow( szClassName, // ウィンドウクラス名
TEXT("Win32"), // タイトルバーに表示する文字列
WS_OVERLAPPEDWINDOW, // ウィンドウの種類
CW_USEDEFAULT, // ウィンドウを表示する位置(X座標)
CW_USEDEFAULT, // ウィンドウを表示する位置(Y座標)
CW_USEDEFAULT, // ウィンドウの幅
CW_USEDEFAULT, // ウィンドウの高さ
NULL, // 親ウィンドウのウィンドウハンドル
NULL, // メニューハンドル
hInst, // インスタンスハンドル
NULL // その他の作成データ
);
if(hWnd == NULL) return FALSE; // NULLが帰ってくる
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}