主题:CreateWindow函数
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wndclass.hCursor=LoadCursor(m_hInstance,IDC_ARROW);
wndclass.hIcon=LoadIcon(m_hInstance,(LPCTSTR)GetIcon());
wndclass.hInstance=m_hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=m_szWindowClass;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
return FALSE;
}
//游戏区域的宽度加上边框
int iWindowWidth=m_iWidth+GetSystemMetrics(SM_CXFIXEDFRAME)*2;
int iWindowHeight=m_iHeight+GetSystemMetrics(SM_CYFIXEDFRAME)*2+
GetSystemMetrics(SM_CYCAPTION);
if(wndclass.lpszMenuName!=NULL)
iWindowHeight+=GetSystemMetrics(SM_CYMENU);
int xPos=(GetSystemMetrics(SM_CXSCREEN)-iWindowWidth)/2;
int yPos=(GetSystemMetrics(SM_CYSCREEN)-iWindowHeight)/2;
//创建窗口
m_hWindow=CreateWindow(m_szWindowClass,m_szTitle,WS_POPUPWINDOW|
WS_CAPTION|WS_MINIMIZEBOX,xPos,yPos,
iWindowWidth,
iWindowHeight,
NULL,
NULL,
m_hInstance,
NULL);
我的编译器在CreateWindow函数中报错,说内存错误
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wndclass.hCursor=LoadCursor(m_hInstance,IDC_ARROW);
wndclass.hIcon=LoadIcon(m_hInstance,(LPCTSTR)GetIcon());
wndclass.hInstance=m_hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=m_szWindowClass;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
return FALSE;
}
//游戏区域的宽度加上边框
int iWindowWidth=m_iWidth+GetSystemMetrics(SM_CXFIXEDFRAME)*2;
int iWindowHeight=m_iHeight+GetSystemMetrics(SM_CYFIXEDFRAME)*2+
GetSystemMetrics(SM_CYCAPTION);
if(wndclass.lpszMenuName!=NULL)
iWindowHeight+=GetSystemMetrics(SM_CYMENU);
int xPos=(GetSystemMetrics(SM_CXSCREEN)-iWindowWidth)/2;
int yPos=(GetSystemMetrics(SM_CYSCREEN)-iWindowHeight)/2;
//创建窗口
m_hWindow=CreateWindow(m_szWindowClass,m_szTitle,WS_POPUPWINDOW|
WS_CAPTION|WS_MINIMIZEBOX,xPos,yPos,
iWindowWidth,
iWindowHeight,
NULL,
NULL,
m_hInstance,
NULL);
我的编译器在CreateWindow函数中报错,说内存错误