关于Windows程序设计的简单问题

635402431 2008-11-28 10:32:41
#include <windows.h>
#include"resource.h"
#define ID_TIMER 1

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

static TCHAR szAppName[] = TEXT ("HelloWin") ;

HWND hwnd ;
.....
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{


static int idColor[5]={WHITE_BRUSH,LTGRAY_BRUSH,GRRAY_BRUSH,DKGRAY_BRUSH,BLACK_BRUSH};
static int iSelection=IDM_BKGND_WHITE;
HMENU hMenu;
switch (message)

{

case WM_COMMAND:
hMenu=GetMenu(hwnd);
switch(LOWORD(wParam))
{
case IDM_FILE_NEW:
case IDM_FILE_OPEN:
case IDM_FILE_SAVE:
case IDM_FILE_SAVE_AS:
MessageBeep(0);
return 0;
case IDM_APP_EXIT:
SendMessage(hwnd,WM_CLOSE,0,0);
return 0;
case IDM_EDIT_UNDO:
case IDM_EDIT_CUT:
case IDM_EDIT_COPY:
case IDM_EDIT_PASTE:
case IDM_EDIT_CLEAR:
MessageBeep(0);
return 0;
case IDM_BKGND_WHITE:
case IDM_BKGND_LTGRAY:
case IDM_BKGND_GRAY:
case IDM_BKGND_DKGRAY:
case IDM_BKGND_BLACK:
CheckMenuItem(hMenu,iSelection,MF_UNCHECKED);
iSelection=LOWORD(wParam);
CheckMenuItem(hMenu,iSelection,MF_CHECKED);
SetClassLong(hwnd,GCL_HBRBACKGROUND,
(LONG)GetStockObject(idColor[LOWORD(wParam)-IDM_BKGND_WHITE]));
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case IDM_TIMER_START:
if(SetTimer(hwnd,ID_TIMER,1000,NULL))
{
EnableMenuItem(hMenu,IDM_TIMER_START,MF_GRAYED);
EnableMenuItem(hMenu,IDM_TIMER_STOP,MF_GRAYED);
}
return 0;
}

case IDM_TIMER_STOP:
KillTimer(hwnd,ID_TIMER);
EnableMenuItem(hMenu,IDM_TIMER_START,MF_ENABLED);
EnableMenuItem(hMenu,IDM_TIMER_STOP,MF_GRAYED);
return 0 ;
case IDM_APP_HELP:
MessageBox(hwnd,TEXT("Help not yet implemented!"),szAppName,MB_ICONEXCLAMATION|MB_OK);
return 0;
case IDM_APP_ABOUT:
MessageBox(hwnd,TEXT("Menu Demonstration programe\n")
TEXT("(c)Charles Petzold,1998"),
szAppName,MB_ICONINFORMATION|MB_OK);
return 0;
break;
case WM_TIMER:
MessageBeep(0);
return 0;
case WM_DESTROY:

PostQuitMessage (0) ;

return 0 ;

}

return DefWindowProc (hwnd, message, wParam, lParam) ;

}


出现
error C2065:
f:\cadan\cadan.c(107) : error C2065: 'IDM_BKGND_WHITE' : undeclared identifier
f:\cadan\cadan.c(107) : error C2099: initializer is not a constant
f:\cadan\cadan.c(117) : error C2065: 'IDM_FILE_NEW' : undeclared identifier
f:\cadan\cadan.c(117) : error C2051: case expression not constant
f:\\cadan\cadan.c(118) : error C2065: 'IDM_FILE_OPEN' : undeclared identifier
f:\cadan\cadan.c(118) : error C2051: case expression not constant
f:\cadan\cadan.c(119) : error C2065: 'IDM_FILE_SAVE' : undeclared identifier
f:\cadan\cadan.c(119) : error C2051: case expression not constant
f:\cadan\cadan.c(120) : error C2065: 'IDM_FILE_SAVE_AS' : undeclared identifier
f:\cadan\cadan.c(120) : error C2051: case expression not constant
f:\cadan\cadan.c(123) : error C2065: 'IDM_APP_EXIT' : undeclared identifier
f:\cadan\cadan.c(123) : error C2051: case expression not constant
f:\cadan\cadan.c(126) : error C2065: 'IDM_EDIT_UNDO' : undeclared identifier
f:\cadan\cadan.c(126) : error C2051: case expression not constant
f:\cadan\cadan.c(127) : error C2065: 'IDM_EDIT_CUT' : undeclared identifier
f:\cadan\cadan.c(127) : error C2051: case expression not constant
f:\cadan\cadan.c(128) : error C2065: 'IDM_EDIT_COPY' : undeclared identifier
f:\cadan\cadan.c(128) : error C2051: case expression not constant
f:\cadan\cadan.c(129) : error C2065: 'IDM_EDIT_PASTE' : undeclared identifier
f:\cadan\cadan.c(129) : error C2051: case expression not constant
f:\cadan\cadan.c(130) : error C2065: 'IDM_EDIT_CLEAR' : undeclared identifier
f:\cadan\cadan.c(130) : error C2051: case expression not constant
f:\cadan\cadan.c(133) : error C2051: case expression not constant
f:\cadan\cadan.c(134) : error C2065: 'IDM_BKGND_LTGRAY' : undeclared identifier
f:\cadan\cadan.c(134) : error C2051: case expression not constant
f:\cadan\cadan.c(135) : error C2065: 'IDM_BKGND_GRAY' : undeclared identifier
f:\cadan\cadan.c(135) : error C2051: case expression not constant
f:\cadan\cadan.c(136) : error C2065: 'IDM_BKGND_DKGRAY' : undeclared identifier
f:\cadan\cadan.c(136) : error C2051: case expression not constant
f:\cadan\cadan.c(137) : error C2065: 'IDM_BKGND_BLACK' : undeclared identifier
f:\cadan\cadan.c(137) : error C2051: case expression not constant
f:\cadan\cadan.c(145) : error C2065: 'IDM_TIMER_START' : undeclared identifier
f:\cadan\cadan.c(145) : error C2051: case expression not constant
f:\cadan\cadan.c(149) : error C2065: 'IDM_TIMER_STOP' : undeclared identifier
f:\cadan\cadan.c(154) : error C2051: case expression not constant
f:\cadan\cadan.c(159) : error C2065: 'IDM_APP_HELP' : undeclared identifier
f:\cadan\cadan.c(159) : error C2051: case expression not constant
f:\cadan\cadan.c(160) : error C2065: 'szAppName' : undeclared identifier
f:\cadan\cadan.c(160) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
f:\cadan\cadan.c(160) : warning C4024: 'MessageBoxA' : different types for formal and actual parameter 3
f:\cadan\cadan.c(162) : error C2065: 'IDM_APP_ABOUT' : undeclared identifier
f:\cadan\cadan.c(162) : error C2051: case expression not constant
f:\cadan\cadan.c(165) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
f:\cadan\cadan.c(165) : warning C4024: 'MessageBoxA' : different types for formal and actual parameter 3
那位好心的大哥帮忙解决
...全文
229 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mingchaoyan 2010-01-10
  • 打赏
  • 举报
回复
我也碰到了这个问题 我知道是菜单资源没加 好 哪位大牛可以讲解的详细些
我加了菜单资源 头文件里是这样的:
//
#define IDR_MENU1 101
#define ID_MENUITEM40001 40001
#define ID_MENUITEM40002 40002
#define ID_MENUITEM40003 40003
#define ID_MENUITEM40004 40004
#define ID_MENUITEM40005 40005
#define ID_MENUITEM40006 40006
#define ID_MENUITEM40007 40007
#define ID_MENUITEM40008 40008
#define ID_MENUITEM40009 40009
#define ID_MENUITEM40010 40010
#define ID_MENUITEM40011 40011
#define ID_MENUITEM40012 40012
#define ID_MENUITEM40013 40013
#define ID_MENUITEM40014 40014
#define ID_MENUITEM40015 40015
#define ID_MENUITEM40016 40016
#define ID_MENUITEM40017 40017
#define ID_MENUITEM40018 40018
#define ID_MENUITEM40019 40019
正确的应该是:
#define IDM_FILE_NEW 40001
#define IDM_FILE_OPEN 40002
#define IDM_FILE_SAVE 40003
#define IDM_FILE_SAVE_AS 40004
#define IDM_APP_EXIT 40005
#define IDM_EDIT_UNDO 40006
#define IDM_EDIT_CUT 40007
#define IDM_EDIT_COPY 40008
#define IDM_EDIT_PASTE 40009
#define IDM_EDIT_CLEAR 40010
#define IDM_BKGND_WHITE 40011
#define IDM_BKGND_LTGRAY 40012
#define IDM_BKGND_GRAY 40013
#define IDM_BKGND_DKGRAY 40014
#define IDM_BKGND_BLACK 40015
#define IDM_TIMER_START 40016
#define IDM_TIMER_STOP 40017
#define IDM_APP_HELP 40018
#define IDM_APP_ABOUT 40019
#define ID_MENUITEM40020 40020
可以告诉我 我哪里错了吗、
谢谢
635402431 2008-11-29
  • 打赏
  • 举报
回复
小弟是菜鸟 刚接触这玩意 能说出具体的解决方案吗?包括最后两项的错误形式
不胜感激
635402431 2008-11-29
  • 打赏
  • 举报
回复
小弟是菜鸟 刚接触这玩意 能说出具体的解决方案吗?包括最后两项的错误形式
不胜感激
lygfqy 2008-11-28
  • 打赏
  • 举报
回复
加上你的菜单资源
就呆在云上 2008-11-28
  • 打赏
  • 举报
回复
case IDM_FILE_NEW:
case IDM_FILE_OPEN:
case IDM_FILE_SAVE:
case IDM_FILE_SAVE_AS:

你就没有建立这些个资源吧
自然就没有id啊
qqwx_1986 2008-11-28
  • 打赏
  • 举报
回复
看看resource.h中那些switch中的ID有没有定义
Mougou 2008-11-28
  • 打赏
  • 举报
回复
错误信息很清楚嘛,case 分支用的常量没有定义。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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