我写的程序运行后没有窗口,查了下,是ReigsterWindowEx执行失败了,错误代码是87,说参数不正确,我想了半天都没找到哪里不对了,我把部分代码帖出来高手能不能指点我一下? 不胜感激! 错误的地方我注释出来了, 和其他代码应该没什么关系。
#include <windows.h>
#include <dinput.h>
HINSTANCE g_hInst;
HWND g_hWnd;
const TCHAR g_szWndClass[]=TEXT("Game");
const TCHAR g_szWndTitle[]=TEXT("DirectInput 键盘输入");
WNDCLASSEX g_wcex;
ATOM RegWndClass(HINSTANCE);
BOOL CreateWnd(HINSTANCE,int);
LRESULT WndProc(HWND,UINT,WPARAM,LPARAM);
extern BOOL InitKeyboard();
extern BOOL IsKeyPressed(int);
extern void ReleaseCOMObject();
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
g_hInst=hInstance;
ATOM atom=RegWndClass(hInstance);
int error =GetLastError(); ////错误代码为87,参数不正确
if(!CreateWnd(hInstance,nCmdShow))
{
return FALSE;
}
if(!InitKeyboard())
{
return FALSE;
}
while(msg.message!=WM_QUIT)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
if(IsKeyPressed(DIK_RIGHT))
{
MessageBox(NULL,TEXT("右箭头按下"),TEXT("按键状态"),MB_OK|MB_ICONINFORMATION);
}
if(IsKeyPressed(DIK_LEFT))
{
MessageBox(NULL,TEXT("左箭头按下"),TEXT("按键状态"),MB_OK|MB_ICONINFORMATION);
}
if(IsKeyPressed(DIK_D)&IsKeyPressed(DIK_LCONTROL))
{
MessageBox(NULL,TEXT("Ctrl+D双键按下"),TEXT("按键状态"),MB_OK|MB_ICONINFORMATION);
}
if(IsKeyPressed(DIK_ESCAPE))
{
PostQuitMessage(0);
}
}
}
return msg.wParam;
}
//ReleaseCOMObject();
ATOM RegWndClass(HINSTANCE hInstance)
{
g_wcex.cbSize=sizeof(WNDCLASS);
g_wcex.style=CS_HREDRAW|CS_VREDRAW;
g_wcex.lpfnWndProc=(WNDPROC)WndProc;
g_wcex.cbClsExtra=0;
g_wcex.cbWndExtra=0;
g_wcex.hInstance=hInstance;
g_wcex.hIcon=LoadIcon(NULL,IDI_WINLOGO);
g_wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
g_wcex.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
g_wcex.lpszMenuName=NULL;
g_wcex.lpszClassName=g_szWndClass;
g_wcex.hIconSm=NULL;
int error =GetLastError();
return RegisterClassEx(&g_wcex); ///////////////这里出错
}
BOOL CreateWnd(HINSTANCE hInstance,int nCmdShow)
{
g_hWnd=CreateWindow(g_szWndClass,g_szWndTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
//int error =GetLastError();
if(!g_hWnd)
{
return false;
}
ShowWindow(g_hWnd,nCmdShow);
UpdateWindow(g_hWnd);
return true;
}
LRESULT WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
高手能不能帮告诉我哪里的问题? 小弟先谢过拉!