源代码为# include<windows.h>
# include" 7_1.h"
# include <stdio.h>HMENU hmenu,haddmenu;
HACCEL hAccel;
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
){
WNDCLASS wndclass1;
wndclass1.style=CS_HREDRAW | CS_VREDRAW;
wndclass1.lpfnWndProc=WinSunProc;
wndclass1.cbClsExtra=0;
wndclass1.cbWndExtra=0;
wndclass1.hInstance=hInstance;
wndclass1.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass1.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass1.lpszClassName="Winged Monkey";
wndclass1.lpszMenuName="I will";
wndclass1.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
RegisterClass(&wndclass1);
HWND hwnd;
hwnd=CreateWindow("Winged Monkey","I will",WS_OVERLAPPEDWINDOW,0,0,400,300,NULL,hmenu,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,"I will");
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_COMMAND:
switch(wParam)
{
case IDM_ADDMENU://在主菜单中添加弹出式菜单
hmenu=GetMenu(hwnd);
haddmenu=CreateMenu();
AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,"方差");
AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,"均方根");
AppendMenu(haddmenu,MF_ENABLED,IDM_pingjunzhi,"平均值");
AppendMenu(haddmenu,MF_ENABLED,IDM_quihe,"求和");
InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddmenu,"统计计算");
EnableMenu(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenu(hmenu,IDM_DELMENU,MF_ENABLED);
DrawMenuBar(hwnd); //重新显示窗口
break;
}
case IDM_DELEMENU:
DeleteMenu(hmenu,2,BYPOSITION);
EnableMenu(hmenu,IDM_ADDMENU,MF_ENABLED);
EnableMenu(hmenu,IDM_DELMENU,MF_GRAYED);
DrawMenuBar(hwnd);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的要结束","Winged Monkey",MB_YESNO))
{
DestroyWindow(hwnd);
}
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
提示错误为Cannot open include file: ' 7_1.h': No such file or directory
执行 cl.exe 时出错.但是我定义了7_1.h到Header Files中啊
# include" 7_1.h"
# include <stdio.h>HMENU hmenu,haddmenu;
HACCEL hAccel;
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
){
WNDCLASS wndclass1;
wndclass1.style=CS_HREDRAW | CS_VREDRAW;
wndclass1.lpfnWndProc=WinSunProc;
wndclass1.cbClsExtra=0;
wndclass1.cbWndExtra=0;
wndclass1.hInstance=hInstance;
wndclass1.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass1.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass1.lpszClassName="Winged Monkey";
wndclass1.lpszMenuName="I will";
wndclass1.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
RegisterClass(&wndclass1);
HWND hwnd;
hwnd=CreateWindow("Winged Monkey","I will",WS_OVERLAPPEDWINDOW,0,0,400,300,NULL,hmenu,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,"I will");
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_COMMAND:
switch(wParam)
{
case IDM_ADDMENU://在主菜单中添加弹出式菜单
hmenu=GetMenu(hwnd);
haddmenu=CreateMenu();
AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,"方差");
AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,"均方根");
AppendMenu(haddmenu,MF_ENABLED,IDM_pingjunzhi,"平均值");
AppendMenu(haddmenu,MF_ENABLED,IDM_quihe,"求和");
InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddmenu,"统计计算");
EnableMenu(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenu(hmenu,IDM_DELMENU,MF_ENABLED);
DrawMenuBar(hwnd); //重新显示窗口
break;
}
case IDM_DELEMENU:
DeleteMenu(hmenu,2,BYPOSITION);
EnableMenu(hmenu,IDM_ADDMENU,MF_ENABLED);
EnableMenu(hmenu,IDM_DELMENU,MF_GRAYED);
DrawMenuBar(hwnd);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的要结束","Winged Monkey",MB_YESNO))
{
DestroyWindow(hwnd);
}
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
提示错误为Cannot open include file: ' 7_1.h': No such file or directory
执行 cl.exe 时出错.但是我定义了7_1.h到Header Files中啊
这个文件你放哪了