【C】简单的菜单的实例 - HMENU
#include<Windows.h>LRESULT CALLBACK WndProc(HWND hWnd,UINT Msg,WPARAM wp,LPARAM lp)
{
switch(Msg)
{
default:
return DefWindowProc(hWnd,Msg,wp,lp);
case WM_CREATE:
do{
HMENU hMenu=CreateMenu();//创建主菜单
HMENU hM1=CreateMenu();//创建下级菜单
AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT_PTR)hM1,TEXT("文件"));
AppendMenu(hM1,MF_STRING,(UINT_PTR)233,TEXT("退出"));
SetMenu(hWnd,hMenu);
}while(0);
break;
case WM_COMMAND:
switch(LOWORD(wp))
{
case 233:
DestroyWindow(hWnd);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return 0;
}
int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR szCmd,int nCmd)
{
WNDCLASSEX WCEx={sizeof(WNDCLASSEX),0,WndProc,0,0,hInst,NULL,LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)),(HBRUSH)COLOR_BTNFACE,NULL,TEXT("tutmenu"),NULL};//窗口类
MSG msg;
HWND hWnd=CreateWindowEx(0,MAKEINTATOM(RegisterClassEx(&WCEx)),TEXT("tutmenu"),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInst,NULL);//窗口句柄
ShowWindow(hWnd,nCmd);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))//消息循环
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
页:
[1]