运行例子,点击菜单中文件->打开,本来是想让其弹出通用对话框的,但却没有响应。请DX帮忙指出哪里出错了。。:O源码:7_5.cpp:
  #include <windows.h>                      
   #include <commdlg.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include "7_5.h"OPENFILENAME ofn;//定义一个OPENFILENAME结构
HINSTANCE hInst;LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd ;
MSG Msg ;
HACCEL hAccel;
WNDCLASS wndclass ;
     char lpszMenuName[]="Menu";
     char lpszClassName[] = "通用对话框"; 
     char lpszTitle[]= "通用对话框样例";

     wndclass.style = 0;                   
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 =  lpszMenuName ;                       
wndclass.lpszClassName = lpszClassName ;                   

     if( !RegisterClass( &wndclass))       
  {
MessageBeep(0) ;
return FALSE ;
  } hwnd = CreateWindow(lpszClassName,     
lpszTitle,     
WS_OVERLAPPEDWINDOW,   
CW_USEDEFAULT, 
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,,
                        CW_USEDEFAULT,    
NULL,       
NULL,      
hInstance,    
NULL) ;      ShowWindow( hwnd, nCmdShow) ;
UpdateWindow(hwnd); hInst=hInstance;
hAccel=LoadAccelerators(hInst,lpszMenuName);      
    while( GetMessage(&Msg, NULL, 0, 0))
  {  
  
if (!TranslateAccelerator(hwnd,hAccel,&Msg))
      {
   TranslateMessage( &Msg) ;
   DispatchMessage( &Msg) ;
       }

  } return Msg.wParam;      
}
    
LRESULT CALLBACK WndProc(HWND hwnd,   
                            UINT message,  
                            WPARAM  wParam,
                            LPARAM  lParam)       {  
       static char szFilter[] = "Text Files (*.TXT)\0*.txt\0"  \
                         "All Files (*.*)\0*.*\0\0" ;
       static char lpstrFileName[]="";     switch(message)
          {
    case WM_CREATE:
       
    //初始化对话框结构
        ofn.lStructSize      = sizeof (OPENFILENAME) ;
        ofn.hwndOwner     = hwnd ;
        ofn.hInstance       = NULL ;
        ofn.lpstrFilter       = szFilter ;
        ofn.lpstrCustomFilter = NULL ;
      ofn.nMaxCustFilter   = 0 ;
        ofn.nFilterIndex      = 1 ;
        ofn.lpstrFile         = NULL ;          
        ofn.nMaxFile        = 0 ;
        ofn.lpstrFileTitle    = NULL ;          
        ofn.nMaxFileTitle     = 0 ;
       ofn.lpstrInitialDir   = NULL ;
        ofn.lpstrTitle        = NULL ;
       ofn.Flags             = 0 ;             
        ofn.nFileOffset       = 0 ;
        ofn.nFileExtension    = 0 ;
        ofn.lpstrDefExt       = NULL ;
        ofn.lCustData         = 0 ;
        ofn.lpfnHook          = NULL ;
        ofn.lpTemplateName    = NULL ;
MessageBox(hwnd,"the OFN has been created.","creat OFN",MB_OK);   break;
       
     case WM_COMMAND:
       switch(LOWORD(wParam))
    {
       case IDM_NEW:
   MessageBox(hwnd,"已经打开了一个文件。","新建文件",MB_OK);
       break;                  case IDM_OPEN:
             //设置“打开”对话框
              ofn.lpstrFile=lpstrFileName;
               ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST
                      |OFN_HIDEREADONLY|OFN_SHOWHELP;
      ofn.lpstrTitle="打开";
  //调用函数GetOpenFileName显示对话框
              GetOpenFileName(&ofn);
  MessageBox(hwnd,"there created.","creat OFN",MB_OK);
  
  break;   //文件读写操作
                    case IDM_SAVEAS:
                //设置“另存为”对话框
                          ofn.lpstrFile=lpstrFileName;
                          ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST
                              |OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
                 ofn.lpstrTitle="另存为";
                //调用函数GetSaveFileName显示对话框
                          GetSaveFileName(&ofn);
                         break;
                    case IDM_CLOSE:
                          break;
  
                    case IDM_EXIT:
                          SendMessage(hwnd,WM_DESTROY,0,0);
                          break;
                     case IDM_ABOUT:
                         MessageBox(hwnd,"通用对话框示例","关于",MB_OK);
                 break;              }
         break;             case WM_DESTROY:          
               PostQuitMessage(0);   
             break;   
   
             default:                  
                return  DefWindowProc(hwnd,message,wParam,lParam);
           }
          return 0;
       }

解决方案 »

  1.   

    这个是头文件7_5.h:
          #define IDM_NEW             10
          #define IDM_OPEN            11
          #define IDM_CLOSE           12
          #define IDM_SAVEAS          14
          #define IDM_SAVE            13
          #define IDM_EXIT            15
          #define IDM_ABOUT           20
      

  2.   

    这是资源文件7_5.rc:
    #include <windows.h>
    #include "7_5.h"Menu MENU DISCARDABLE 
       {
           POPUP "文件(&F)"
          {   
               MENUITEM "新建(&N)\t Ctrl+N",           IDM_NEW
               MENUITEM "打开(&O)\t Ctrl+O",           IDM_OPEN
               MENUITEM "关闭(&C)",           IDM_CLOSE
               MENUITEM SEPARATOR
               MENUITEM "另存为(&A)",                 IDM_SAVEAS
               MENUITEM SEPARATOR                           
                    MENUITEM "退出(&X)",                    IDM_EXIT
           }     POPUP "帮助(&H)"
           {
             MENUITEM "关于(&A)...",                 IDM_ABOUT
           }
       }

    Menu ACCELERATORS  
       {
         "^N",             IDM_NEW                  
         "^O",             IDM_OPEN                  
         "^S",             IDM_SAVE                 
       }