我试过就把菜单的名字由 IDR_MENU1 改成 "IDR_MENU1" (多了对双引号)
也试过将那里写为 wndclass.lpszMenuName =MAKEINTRESOURCE(IDR_MENU1)
菜单都显示不出来~这么简单的一个问题快杀死我了~
程序如下:#include <windows.h>
#include"resource.h"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 ;
MSG msg ;
WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = "IDR_MENU1";
wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
"The Hello Program", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parametersShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;GetClientRect (hwnd, &rect) ;DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
也试过将那里写为 wndclass.lpszMenuName =MAKEINTRESOURCE(IDR_MENU1)
菜单都显示不出来~这么简单的一个问题快杀死我了~
程序如下:#include <windows.h>
#include"resource.h"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 ;
MSG msg ;
WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = "IDR_MENU1";
wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
"The Hello Program", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parametersShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;GetClientRect (hwnd, &rect) ;DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
解决方案 »
- glLoadIdentity()函数真正的意义是什么
- 如何得到 windows 线程消息队列的长度?就是里面还有多少消息没取出来?
- 用waveOutSetVolume怎么保证两个声道一致
- Debug版本没问题, Release版报错:内存不够
- 用VC做一个DLL,供BCB调用,请问VC的DLL能否导出类供BCB调用?
- 关于列表框的选中否?
- 请问怎么连接两个BSTR。
- 如何在VC中作出和QQ字体颜色选择的效果
- VC6的工程拿到.net里编译通过,但链接产生错误,为什么?
- 我要在对话框类函数ONINITDIALOG()中用到MAINFRM中的一个变量,怎么做?
- hash_map
- CSocket连接错误!
改为:wndclass.lpszMenuName = (LPCSTR)IDR_MENU1;
其中IDR_MENU1是资源文件中定义的菜单ID。
对的。
//
#include "resource.h"#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS/////////////////////////////////////////////////////////////////////////////
// Chinese (P.R.C.) resources#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32/////////////////////////////////////////////////////////////////////////////
//
// Menu
//IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "aadsfsdaf"
BEGIN
MENUITEM "asdfdasf", ID_MENUITEM40001
END
POPUP "asdfsadf"
BEGIN
MENUITEM "adsfdsafasdfadsf", ID_MENUITEM40002
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END#endif // APSTUDIO_INVOKED#endif // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
这样是对的
但不知道是怎么触发各菜单点击事件??????????????????
wndclass.lpszMenuName =(LPCSTR)IDR_MENU1
和wndclass.lpszMenuName =MAKEINTRESOURCE(IDR_MENU1)
都可以,前提是要#include"resouce.h"如果不include的话我怎样都搞不了~不知道为什么~
另外关于vicallee(^^一壶红酒杯十年^^) 提出的方法: 回复人: vicallee(^^一壶红酒杯十年^^) ( ) 信誉:100 2004-09-13 07:59:00 得分: 0
这样当然不行,除非你在资源文件中给菜单起名了.但一般是不起名的,只是用ID
hMenu = LoadMenu (hInstance, MAKEINTRESOURCE (ID_MENU)) ;
再在CreateWindow的第九个参数中指定为hMenu,或者创建窗口之后再
SetMenu(hwnd,hMenu);
好像可以用来复盖前面说的那一个菜单的