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

qq_34661855 2016-05-26 02:32:59
#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;



}
...全文
217 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_34661855 2016-05-28
  • 打赏
  • 举报
回复
下面代码哪里错了???? MYMENUNAME MENU BEGIN POPUP "(&F)" BEGIN ENUITEM "创建统计菜单(&P)", IDM_ADDMENU ENUITEM "删除统计菜单(&D)", IDM_DELMENU,GRAYED ENUITEM SEPARATOR ENUITEM "退出(&X)",IDM_EXIT END MENUITEM "帮助(&H)", END MYMENUACCEL ACCELERATORS BEGIN "^P", IDM_ADDMENU, ASCII,NOINVERT "^D", IDM_DELMENU,ASCII,NOINVERT "^X",IDM_EXIT,ASCII,NOINVERT END
qq_34661855 2016-05-28
  • 打赏
  • 举报
回复
哪个大神帮我看看
Eleven 2016-05-27
  • 打赏
  • 举报
回复
你的WndProc回调函数中写的有问题~
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,_T("求和"));
			AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,_T("方差"));
			AppendMenu(haddmenu,MF_ENABLED,IDM_pinjunzhi,_T("品均值"));
			AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,_T("均方差"));
			InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddmenu,_T("统计计算(&C)"));
			EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
			EnableMenuItem(hmenu,IDM_ADDMENU,MF_ENABLED);
			DrawMenuBar(hwnd);
			break;
		case IDM_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;

	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}
赵4老师 2016-05-27
  • 打赏
  • 举报
回复
仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    PAINTSTRUCT ps;
    HDC hdc;
    HFONT hfont,ohfont;
    RECT r;
    COLORREF oc;

    switch(message) {
    case WM_CLOSE://按Alt+F4退出
        PostQuitMessage(0);
        break;
    case WM_PAINT:
        BeginPaint(hWnd, &ps);
        hdc = ps.hdc; // the device context to draw in
        GetClientRect(hWnd, &r); // Obtain the window's client rectangle
        hfont = CreateFont(200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "宋体");
        ohfont=(HFONT)SelectObject(hdc,hfont);
        oc=SetTextColor(hdc,0x00C080FF);
        SetBkMode(hdc, TRANSPARENT);
        TextOut(hdc,r.left+r.right/2-600, r.top+r.bottom/2-100,"最短画图程序",12);
        SelectObject(hdc,ohfont);
        SetTextColor(hdc,oc);
        DeleteObject(hfont);
        EndPaint(hWnd, &ps);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    MSG msg             = {0};
    WNDCLASS wc         = {0};
    HBRUSH hbrh;
    hbrh=CreateSolidBrush(0x00000000);
    wc.lpfnWndProc      = WndProc;
    wc.hInstance        = hInstance;
    wc.hbrBackground    = hbrh;
    wc.lpszClassName    = "minwindowsapp";
    wc.hCursor          = LoadCursor(NULL,IDC_ARROW);
    if (0==RegisterClass(&wc)) return 1;

    if (NULL==CreateWindow(wc.lpszClassName,
                        "Minimal Windows Application",
                        WS_POPUP|WS_VISIBLE,
                        0,
                        0,
                        GetSystemMetrics(SM_CXSCREEN),
                        GetSystemMetrics(SM_CYSCREEN),
                        0,
                        0,
                        hInstance,
                        NULL))
        return 2;

    while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
        DispatchMessage( &msg );
    }
    DeleteObject(hbrh);
    return 0;
}
qq_34661855 2016-05-27
  • 打赏
  • 举报
回复
创建“求和”“平均值”等没有显示
Eleven 2016-05-27
  • 打赏
  • 举报
回复
引用 10 楼 qq_34661855 的回复:
回调函数改了之后,可以创建,但是只是闪现,就关闭了
这里也错了
while(GetMessage(&msg,NULL,0,0))
    {
        if(!TranslateAccelerator(hwnd,hAccel,&msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
 
        }
     //   return(int) msg.wParam;
    }
return(int) msg.wParam;
qq_34661855 2016-05-27
  • 打赏
  • 举报
回复
回调函数改了之后,可以创建,但是只是闪现,就关闭了
qq_34661855 2016-05-26
  • 打赏
  • 举报
回复
可以了,但是创建失败

#include "67890.h"
#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 InitWindowsClass(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(!InitWindowsClass(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,_T("求和"));
AppendMenu(haddmenu,MF_ENABLED,IDM_fangcha,_T("方差"));
AppendMenu(haddmenu,MF_ENABLED,IDM_pinjunzhi,_T("品均值"));
AppendMenu(haddmenu,MF_ENABLED,IDM_junfanggen,_T("均方差"));
InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)haddmenu,_T("统计计算(&C)"));
EnableMenuItem(hmenu,IDM_ADDMENU,MF_GRAYED);
EnableMenuItem(hmenu,IDM_ADDMENU,MF_ENABLED);
DrawMenuBar(hwnd);
break;
case IDM_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 false;
}

BOOLEAN InitWindowsClass(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASSEX wndclass;
HWND hWnd;
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 = NULL;
wndclass.lpszClassName = szWindowClass;
wndclass.hIcon = 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;


//return BOOLEAN();
}
qq_34661855 2016-05-26
  • 打赏
  • 举报
回复
加了个},还是不行 cpp(63) : error C2664: 'AppendMenuA' : cannot convert parameter 4 from 'unsigned short [3]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast .cpp(64) : error C2664: 'AppendMenuA' : cannot convert parameter 4 from 'unsigned short [3]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast .cpp(65) : error C2664: 'AppendMenuA' : cannot convert parameter 4 from 'unsigned short [4]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 0.cpp(66) : error C2065: 'IDM_junfanggen' : undeclared identifier cpp(67) : error C2065: 'haddhmenu' : undeclared identifier cpp(67) : error C2664: 'InsertMenuA' : cannot convert parameter 5 from 'unsigned short [9]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast .cpp(72) : error C2065: 'IDN_DELMENU' : undeclared identifier cpp(72) : error C2051: case expression not constant
小灸舞 2016-05-26
  • 打赏
  • 举报
回复
WinMain函数少了个}
碎炎 2016-05-26
  • 打赏
  • 举报
回复
函数不要定义在函数内
打你屁屁 2016-05-26
  • 打赏
  • 举报
回复
这个应该是基本错误,大括号啥的不匹配
qq_34661855 2016-05-26
  • 打赏
  • 举报
回复
'WndProc' : local function definitions are illegal error C2601: 'IniWindowClass' : local function definitions are illegal : fatal error C1004: unexpected end of file found
赵4老师 2016-05-26
  • 打赏
  • 举报
回复
有啥错?

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧