vc++如何加载菜单,以下代码请帮我看一下,各路高手,
这是Menu.h文件#include "windows.h"
#define IDM_NEW 10
#define IDM_OPEN 20
#define IDM_CLOSE 30
#define IDM_SAVE 40
#define IDM_SAVEAS 50
#define IDM_EXIT 60
这是test.cpp文件
#include "windows.h"
#include "stdio.h"
#include "string.h"
#include "Menu.h"
//定义菜单
Menu MENU MOVEABLE
{
POPUP"文件(&F)" //弹出式菜单
{
MENUITEM"新建(&N)",IDM_NEW
MENUITEM"打开(&O)",IDM_OPEN
MENUITEM"关闭(&C)",IDM_CLOSE
MENUITEM"保存(&S)",IDM_SAVE
MENUITEM"另存为(&A)",IDM_SAVEAS
MENUITEM"退出(&E)",IDM_EXIT
}
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WinProc;
WndClass.lpszClassName="whyan";
WndClass.lpszMenuName="Menu";
WndClass.style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
RegisterClass(&WndClass);
hWnd=CreateWindow("whyan","whyan",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,SW_SHOWNORMAL);
UpdateWindow(hWnd);
while(GetMessage(&Message,NULL,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
HBRUSH hbrush;
HPEN pen;
PAINTSTRUCT pstr;
int x,y;
HCURSOR cursor;
switch (Message)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&pstr);
SetMapMode(hdc,MM_ANISOTROPIC);
pen=(HPEN)GetStockObject(BLACK_PEN);
hbrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
SelectObject(hdc,hbrush);
SelectObject(hdc,pen);
RoundRect(hdc,50,120,100,200,15,15);
EndPaint(hWnd,&pstr);
break;
case WM_LBUTTONDOWN:
//MessageBox(hWnd,"你按下了左键","infomation",MB_OK);
if(wParam&MK_CONTROL)
{
MessageBox(hWnd,"你按下了control键","infomation",MB_OK);
}
if(wParam&MK_SHIFT)
{
MessageBox(hWnd,"你按下了shift键","infomation",MB_OK);
}
break;
case WM_MBUTTONDOWN:
MessageBox(hWnd,"你按下了中健","infomation",MB_OK);
break;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"你按下了右键","infomation",MB_OK);
break;
case WM_LBUTTONDBLCLK:
MessageBox(hWnd,"你双击了左键","infomation",MB_OK);
break;
case WM_MOUSEMOVE:
x=LOWORD(lParam);//取得lParam的低位值
y=HIWORD(lParam);//取得lParam的高位值
if(x>50&&x<400&&y>50&&y<400)
{
if(x>=50&&x<=100&&y>=50&&y<=100)
{
cursor=LoadCursor(NULL,IDC_WAIT);
SetCursor(cursor);
}
if(x>=100&&x<=400&&y>=100&&y<=400)
{
cursor=LoadCursor(NULL,IDC_CROSS);
SetCursor(cursor);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd,Message,wParam,lParam));
}
return 0;
}