//////////////////////////////////////////
The DrawMenuBar function redraws the menu bar of the specified window. If the menu bar changes after the system has created the window, this function must be called to draw the changed menu bar. BOOL DrawMenuBar(
HWND hWnd // handle to window with menu bar to redraw
);
The DrawMenuBar function redraws the menu bar of the specified window. If the menu bar changes after the system has created the window, this function must be called to draw the changed menu bar. BOOL DrawMenuBar(
HWND hWnd // handle to window with menu bar to redraw
);
试过了,加上还是不行: case WM_CREATE:
hInstance = (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ); hMenuMain = LoadMenu( hInstance, TEXT("MenuMain"));
hMenuFile = LoadMenu( hInstance, TEXT("MenuFile"));
hMenuEdit = LoadMenu( hInstance, TEXT("MenuEdit")); SetMenu( hwnd, hMenuMain );
DrawMenuBar( hwnd ); return 0;
HWND hWnd, // handle to window
HMENU hMenu // handle to menu
);BOOL DrawMenuBar(
HWND hWnd // handle to window with menu bar to redraw
);不想检测返回值 可以, 但 有问题 就要检测了!
检测了,result1和result2都是1. case WM_CREATE:
hInstance = (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ); hMenuMain = LoadMenu( hInstance, TEXT("MenuMain"));
hMenuFile = LoadMenu( hInstance, TEXT("MenuFile"));
hMenuEdit = LoadMenu( hInstance, TEXT("MenuEdit")); result = SetMenu( hwnd, hMenuMain );
result2 = DrawMenuBar( hwnd ); return 0;
]hMenuMain == 0???
hMenuMain:0x00000000
unused: <unable to read memory>
你那个 肯定是 "MenuMain" ?
是个,这是定义:
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//MENUMAIN MENU
BEGIN
POPUP "MAIN", INACTIVE
BEGIN
MENUITEM "&File...", IDM_FILE
MENUITEM "&Edit...", IDM_EDIT
END
END
wcex.lpszMenuName = (LPSTR)IDC_MENU1;
你是又加了个菜单 ?
这个是测试动态换菜单的功能,刚开始的时候没有设置菜单。 wndclass.lpszMenuName = NULL;
像我这样的菜单定义,如何用MAKEINTERESOURCE函数那?
//
// Menu
//MENUMAIN MENU
BEGIN
POPUP "MAIN", INACTIVE
BEGIN
MENUITEM "&File...", IDM_FILE
MENUITEM "&Edit...", IDM_EDIT
END
END
#include <Windows.h>
#include "resource3.h"LRESULT CALLBACK wWinProc( HWND, UINT, WPARAM, LPARAM );int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCommandLine, int iCmdShow )
{
static TCHAR szAppName[] = TEXT("NoPopUps");
HWND hWnd;
MSG msg;
WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = wWinProc;
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 = NULL;
wndclass.lpszClassName = szAppName; if ( !RegisterClass( &wndclass ) )
{
MessageBox( NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR); return 0;
} hWnd = CreateWindow( szAppName, //windows class name
TEXT("No-Popup Nested Menu Demonstration"), // windows caption.
WS_OVERLAPPEDWINDOW, //windows style.
CW_USEDEFAULT, // initial X positon.
CW_USEDEFAULT, // initial Y positon.
CW_USEDEFAULT, // initial X size.
CW_USEDEFAULT, // initial Y positon.
NULL, //Parent window handle.
NULL, //window menu handle.
hInstance, // program instance handle.
NULL); // creation parameters. ShowWindow( hWnd, iCmdShow );
UpdateWindow( hWnd ); while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
} return msg.wParam;}
LRESULT CALLBACK wWinProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static HMENU hMenuMain, hMenuEdit, hMenuFile;
HINSTANCE hInstance;
BOOL result, result2; switch (message)
{
case WM_CREATE:
hInstance = (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE );
hMenuMain = LoadMenu( hInstance, TEXT("MenuMain"));
hMenuFile = LoadMenu( hInstance, TEXT("MenuFile"));
hMenuEdit = LoadMenu( hInstance, TEXT("MenuEdit")); result = SetMenu( hwnd, hMenuMain );
result2 = DrawMenuBar( hwnd ); return 0; case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_MAIN:
SetMenu( hwnd, hMenuMain );
return 0;
case IDM_FILE:
SetMenu( hwnd, hMenuFile );
return 0;
case IDM_EDIT:
SetMenu( hwnd, hMenuEdit );
return 0;
case IDM_FILE_NEW:
case IDM_FILE_OPEN:
case IDM_FILE_SAVE:
case IDM_FILE_SAVE_AS:
case IDM_EDIT_UNDO:
case IDM_EDIT_CUT:
case IDM_EDIT_COPY:
case IDM_EDIT_PASTE:
case IDM_EDIT_DELETE:
MessageBeep( 0 );
return 0; } break; case WM_DESTROY:
SetMenu( hwnd, hMenuMain );
DestroyMenu( hMenuFile );
DestroyMenu( hMenuEdit );
PostQuitMessage( 0 );
return 0;
} return DefWindowProc( hwnd, message, wParam, lParam );
}
// Microsoft Visual C++ generated resource script.
//
#include "resource3.h"#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS/////////////////////////////////////////////////////////////////////////////
// Chinese (Simplified, PRC) resources#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//1 TEXTINCLUDE
BEGIN
"resource3.h\0"
END2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END#endif // APSTUDIO_INVOKED#endif // Chinese (Simplified, PRC) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US/////////////////////////////////////////////////////////////////////////////
//
// Menu
//MENUMAIN MENU
BEGIN
POPUP "MAIN", INACTIVE
BEGIN
MENUITEM "&File...", IDM_FILE
MENUITEM "&Edit...", IDM_EDIT
END
ENDMENUFILE MENU
BEGIN
POPUP "File", INACTIVE
BEGIN
MENUITEM "&New", IDM_FILE_NEW
MENUITEM "&Open", IDM_FILE_OPEN
MENUITEM "&Save", IDM_FILE_SAVE
MENUITEM "Save &As", IDM_FILE_SAVE_AS
MENUITEM "(&Main)", IDM_MAIN
END
ENDMENUEDIT MENU
BEGIN
POPUP "EDIT", INACTIVE
BEGIN
MENUITEM "&Undo", IDM_EDIT_UNDO
MENUITEM "Cu&t", IDM_EDIT_CUT
MENUITEM "&Copy", IDM_EDIT_COPY
MENUITEM "&Paste", IDM_EDIT_PASTE
MENUITEM "De&lete", IDM_EDIT_DELETE
MENUITEM "(&Main)", ID_MAIN
END
END#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
#define MENUMAIN 101
#define MENUFILE 102
于是把程序改成: hMenuMain = LoadMenu( hInstance, MAKEINTRESOURCE(MENUMAIN));
就可以了,多谢两位大侠的帮忙。