//////////////////////////////////////////
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
);

解决方案 »

  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")); SetMenu( hwnd, hMenuMain );
    DrawMenuBar( hwnd ); return 0;
      

  2.   

    BOOL SetMenu(
      HWND hWnd,  // handle to window
      HMENU hMenu // handle to menu
    );BOOL DrawMenuBar(
      HWND hWnd  // handle to window with menu bar to redraw
    );不想检测返回值 可以, 但 有问题 就要检测了!
      

  3.   


    检测了,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;
      

  4.   

    hMenuMain = LoadMenu( hInstance, TEXT("MenuMain"));
    ]hMenuMain == 0???
      

  5.   


    hMenuMain:0x00000000
    unused: <unable to read memory>
      

  6.   

    BOOL LoadMenu( UINT nIDResource );// 如:IDC_MENU
    你那个 肯定是 "MenuMain" ?
      

  7.   


    是个,这是定义:
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //MENUMAIN MENU
    BEGIN
        POPUP "MAIN", INACTIVE
        BEGIN
            MENUITEM "&File...",                    IDM_FILE
            MENUITEM "&Edit...",                    IDM_EDIT
        END
    END
      

  8.   

    窗口注册时 加菜单:
    wcex.lpszMenuName = (LPSTR)IDC_MENU1;
    你是又加了个菜单 ?
      

  9.   

    hMenuMain = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
      

  10.   


    这个是测试动态换菜单的功能,刚开始的时候没有设置菜单。 wndclass.lpszMenuName = NULL;
      

  11.   


    像我这样的菜单定义,如何用MAKEINTERESOURCE函数那?
    //
    // Menu
    //MENUMAIN MENU
    BEGIN
        POPUP "MAIN", INACTIVE
        BEGIN
            MENUITEM "&File...",                    IDM_FILE
            MENUITEM "&Edit...",                    IDM_EDIT
        END
    END
      

  12.   

    你加 菜单时 用了 “ 号 , 即 ”MAINMENU“ 就不要 MAKEINTRESOURCE, 是 数值 时才要
      

  13.   

    NoPopup.c:
    #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 );
    }
      

  14.   

    Chapter102.rc:
    // 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
      

  15.   

    贴resoruce3.h的时候发现里面有如下的定义:#define MENUEDIT                        6
    #define MENUMAIN                        101
    #define MENUFILE                        102
    于是把程序改成: hMenuMain = LoadMenu( hInstance, MAKEINTRESOURCE(MENUMAIN));
    就可以了,多谢两位大侠的帮忙。