vc++创建菜单问题
#include<windows.h>#include<stdlib.h>#include<string.h>#include<math.h>HMENUhmune,had...
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
HMENU hmune,haddmenu;//定义菜单句柄
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG iMessage;
HACCEL hAccel;
WNDCLASS WndClass;
char lpszMenuName[]="Menu";
char lpszClassName[]="caidan";
char lpszTitle[]="My_Nenu_Example";
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClassName;
WndClass.lpszMenuName=lpszMenuName;
WndClass.style=0;
if(!RegisterClass(&WndClass))
{
MessageBeep(0);
return false;
}
hwnd=CreateWindow(lpszClassName,lpszTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,lpszMenuName);
while(GetMessage(&iMessage,NULL,0,0))//消息循环
{
if(!TranslateAccelerator(hwnd,hAccel,&iMessage))
{
TranslateMessage(&iMessage);
DispatchMessage(&iMessage);
}
}
return iMessage.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMessage,UINT wParam,LONG lParam)
{
switch(iMessage)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_ADDMENU:
hmenu=GetMenu(hwnd);
haddmenu=CreateMenu();
AppendMenu(haddmenu,MF_ENABLED,IDM_qiuhe,"qiuhe");
AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,"fangcha");
AppendMenu(haddmenu,MF_ENABLED,IDM_pingjunzhi,"pingjunzhi");
AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,"junfanggen");
InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddmenu,"tongjijisuan(&C)");
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
DrawMenuBar(hwnd);
break;
case IDM_DELMENU:
DeleteMenu(hmenu,2,MF_BYPOSITION);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_ENABLED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
DrawMenuBar(hwnd);
break;
case IDM_EXIT:
SendMessage(hwnd,WM_DESTROY,0,0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default://默认时采用系统消息默认处理函数
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
return 0;
} 展开
#include <stdlib.h>
#include <string.h>
#include <math.h>
HMENU hmune,haddmenu;//定义菜单句柄
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG iMessage;
HACCEL hAccel;
WNDCLASS WndClass;
char lpszMenuName[]="Menu";
char lpszClassName[]="caidan";
char lpszTitle[]="My_Nenu_Example";
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClassName;
WndClass.lpszMenuName=lpszMenuName;
WndClass.style=0;
if(!RegisterClass(&WndClass))
{
MessageBeep(0);
return false;
}
hwnd=CreateWindow(lpszClassName,lpszTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,lpszMenuName);
while(GetMessage(&iMessage,NULL,0,0))//消息循环
{
if(!TranslateAccelerator(hwnd,hAccel,&iMessage))
{
TranslateMessage(&iMessage);
DispatchMessage(&iMessage);
}
}
return iMessage.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMessage,UINT wParam,LONG lParam)
{
switch(iMessage)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_ADDMENU:
hmenu=GetMenu(hwnd);
haddmenu=CreateMenu();
AppendMenu(haddmenu,MF_ENABLED,IDM_qiuhe,"qiuhe");
AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,"fangcha");
AppendMenu(haddmenu,MF_ENABLED,IDM_pingjunzhi,"pingjunzhi");
AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,"junfanggen");
InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddmenu,"tongjijisuan(&C)");
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
DrawMenuBar(hwnd);
break;
case IDM_DELMENU:
DeleteMenu(hmenu,2,MF_BYPOSITION);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_ENABLED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
DrawMenuBar(hwnd);
break;
case IDM_EXIT:
SendMessage(hwnd,WM_DESTROY,0,0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default://默认时采用系统消息默认处理函数
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
return 0;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询