vc的问题,哪里错了,,代码怎么改?

qq_34661855 qq_34661855 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<windows.h>
#include <tchar.h>
#include<math.h>
#include<WinUser.h>
#include<stdlib.h>
#include "stdafx.h"
#include<tchar.h>


#define IDM_ADDMENU 15
#define IDM_DELMENU 16
#define IDM_EXIT 17
#define IDM_HELP 22
#define IDM_qiuhe 23
#define IDM_fangcha 24
#define IDM_pinjunzhi 25
#define IDM_junfangcha 26
HWND hwnd;
BOOLEAN IniWindowClass(HINSTANCE hInstance,int nCmdshow);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
if(!IniWindowClass(hInstance,nCmdShow))
{ MessageBox(NULL,_T("创建失败"), _T("创建窗口"),NULL);
return 1;
}

HACCEL hAccel=LoadAccelerators(hInstance,_T("MYMENUACCEL"));
while(GetMessage(&msg,NULL,0,0))
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

}
return(int) msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hmenu,haddmenu;
switch (message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_ADDMENU:
hmenu=GetMenu(hwnd);
haddmenu=CreateMenu();
AppendMenu(haddmenu,MF_ENABLED,IDM_qiuhe,L"求和");
AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,L"方差");
AppendMenu(haddmenu,MF_ENABLED,IDM_pinjunzhi,L"品均值");
AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,L"均方差");
InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddhmenu,L"统计计算(&C)");
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_ENABLED);
DrawMenuBar(hwnd);
break;
case IDN_DELMENU:
hmenu=GetMenu(hwnd);
DeleteMenu(hmenu,2,MF_BYPOSITION);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_ENABLED);
DrawMenuBar(hwnd);
break;

case IDM_EXIT:
SendMessage(hwnd,WM_DESTROY,0,0);
break;
}

case WM_DESTROY:
PostQuitMessage(0);
break;
}
return 0;
}



BOOLEAN IniWindowClass(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASSEX wndclass;

TCHAR szWindowClass[] = _T("菜单窗口示例");
TCHAR szTitle[] = _T("菜单窗口示例");

//memset(&wndclass, 0, sizeof(WNDCLASSEX));

wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = L"MYMENUANME";
wndclass.lpszClassName = szWindowClass;
wndclass.hIconSm = LoadIcon(wndclass.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if (!RegisterClassEx(&wndclass))
return FALSE;

hwnd = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;



}
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
qq_34661855
VC/MFC 16,551 成员 421,605 内容