请问如何在API中加载菜单?我是一个新手,才接触windows下编程不久,望大神指教。准备和朋友自学游戏开发
WinMain代码如下:intWINAPIWinMain(HINSTANCEhinstance,HINSTANCEhprevinstance,LPSTRlpcmdline...
WinMain代码如下:
int WINAPI WinMain (HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdShow){
static TCHAR szAppName[] = TEXT ("RandRect") ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX winclass ={ winclass.cbSize=sizeof(WNDCLASSEX), //定义一个窗口类
CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
WindProc,
0,
0,
hinstance,
LoadIcon(NULL,IDI_APPLICATION),
LoadCursor(NULL,"IDI_ARROW"),
(HBRUSH)GetStockObject(BLACK_BRUSH),
MAKEINTRESOURCE(IDR_MENU1),
"Random Rectangles",
LoadIcon(NULL,IDI_APPLICATION)
};
if (!(RegisterClassEx (&winclass))){
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
if(!(hwnd = CreateWindowEx(NULL,
TEXT ("Random Rectangles"),
NULL,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL,
hinstance,
NULL))) ;
ShowWindow (hwnd,SW_SHOWNORMAL);
UpdateWindow (hwnd) ;
while (TRUE)
{
if (GetMessage (&msg, NULL, 0, 0))
{
if (msg.message == WM_QUIT)
break ;
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
DrawRectangle (hwnd) ;
}
else
break;
}
//用于替换的部分
return msg.wParam ;
}
我在资源中加了一个,名叫IDR_MENU1的菜单资源,头文件中包含了resource.h,编译通过,但运行之后没有菜单,请问是什么原因,希望得到大神指点。我用的是VS2010.希望得到windows下游戏开发的大牛们的指教。谢谢。 展开
int WINAPI WinMain (HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdShow){
static TCHAR szAppName[] = TEXT ("RandRect") ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX winclass ={ winclass.cbSize=sizeof(WNDCLASSEX), //定义一个窗口类
CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
WindProc,
0,
0,
hinstance,
LoadIcon(NULL,IDI_APPLICATION),
LoadCursor(NULL,"IDI_ARROW"),
(HBRUSH)GetStockObject(BLACK_BRUSH),
MAKEINTRESOURCE(IDR_MENU1),
"Random Rectangles",
LoadIcon(NULL,IDI_APPLICATION)
};
if (!(RegisterClassEx (&winclass))){
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
if(!(hwnd = CreateWindowEx(NULL,
TEXT ("Random Rectangles"),
NULL,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL,
hinstance,
NULL))) ;
ShowWindow (hwnd,SW_SHOWNORMAL);
UpdateWindow (hwnd) ;
while (TRUE)
{
if (GetMessage (&msg, NULL, 0, 0))
{
if (msg.message == WM_QUIT)
break ;
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
DrawRectangle (hwnd) ;
}
else
break;
}
//用于替换的部分
return msg.wParam ;
}
我在资源中加了一个,名叫IDR_MENU1的菜单资源,头文件中包含了resource.h,编译通过,但运行之后没有菜单,请问是什么原因,希望得到大神指点。我用的是VS2010.希望得到windows下游戏开发的大牛们的指教。谢谢。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询