#define IDM_EXIT      1001 case WM_COMMAND:
   switch(LOWORD(wParam))
   {
 case IDM_EXIT:
                 SendMessage(hwnd,WM_DESTROY,0,0L);
 break;
   }
   break;如上面代码,正常应该是一点这个菜单就退出了,可是现在没有反映。我换成MessageBox(hwnd, "退出", "退出菜单", MB_YESNO );也是没反映。我怀疑是没有接收到消息。请大家帮帮我。谢谢

解决方案 »

  1.   

    SendMessage(hwnd,WM_CLOSE,0,0L);

    PostMessage(hwnd,WM_QUIT,0,0L);老弟,WM_DESTROY不是这样用的!
      

  2.   

    兄弟,现在问题不是WM_DESTROY这个是怎么使用的,而是根本就接收不到消息呀如上。我用MessageBox(hwnd, "退出", "退出菜单", MB_YESNO );这个也是没反映的。。
      

  3.   

    你确定你的程序能接收到这个消息吗?
    把你的CPP文件和RS文件贴出来看看吧,大家帮你找找原因~~~``````
      

  4.   

    (study1.h)
    #define IDB_A       1000
    #define IDM_EXIT      1001(study1.cpp)
    #include "stdafx.h"
    #include "study1.h"LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);//初始化函数,初始化窗口数据,并注册窗口
    BOOL InitApplication(HINSTANCE);
    BOOL InitInstance(HINSTANCE,int);HWND hwnd ;     //主窗口句柄
    HWND        hwndBotton; //按钮句柄int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR  lpCmdLine,int   nCmdShow)
    {
      // TODO: Place code here.
    MSG msg;

    if (!InitApplication(hInstance))
    return (FALSE);
    if (!InitInstance(hInstance,nCmdShow))
    return (FALSE);
    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    } return msg.wParam ;
    }BOOL InitApplication(HINSTANCE hInstance)
    {
    WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = (WNDPROC) WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon (NULL,"IDI_WINICON");
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH);
    wndclass.lpszMenuName = "IDR_FRAMEWIND";
    wndclass.lpszClassName = "HelloWin";

    if (!RegisterClass (&wndclass))
    {
    MessageBox (NULL, TEXT ("This program requires Windows NT!"), "HelloWin", MB_ICONERROR);

    return 0;
    }
    return (TRUE);
    }BOOL InitInstance( HINSTANCE  hInstance,int  nCmdShow)
    {

    hwnd = CreateWindow ("HelloWin",TEXT ("Vwind"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
    if (!hwnd)
    return (FALSE);

    ShowWindow (hwnd, nCmdShow);
    UpdateWindow (hwnd);
    return (TRUE);
    }LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

    switch (message)
    {
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    //退出菜单
    case IDM_EXIT:
    MessageBox(hwnd, "wParam", "关闭", MB_YESNO );
    break;
    }
    break;
    case WM_DESTROY: //消息:本窗口正将被销毁
    //请求退出窗口和应用程序
    PostQuitMessage (0);
    break;
    default:
    //调用默认窗口过程对未处理的消息进行必要的处理
    return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return (0);
    }程序就是这样的。
      

  5.   

    自己跟踪一下不就知道有没有处理了吗/
    估计是id冲突或者什么原因,尽量不要自己定义id
      

  6.   

    可以把工程发给我看看[email protected]
      

  7.   

    IDM_EXIT是什么触发这个message?
    还有#define IDM_EXIT 10001最好改成#define IDM_EXIT WM_USER+10001,以避免跟系统消息冲突
    还少了一个#include <windows.h>,
      

  8.   

    在你的.RS文件中加上:
    #include "study1.h"
    如果没有错误或警告,你的程序应该就可以收到消息了:)
      

  9.   

    用这个
    case IDM_EXIT:
     DestroyWindow(hWnd);
    break;
    简单快捷
      

  10.   


    //(study1.h)//(study1.cpp)
    #include "stdafx.h"
    //#include "study1.h"LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);#define IDB_A       1000
    #define IDM_EXIT      1001
    //初始化函数,初始化窗口数据,并注册窗口
    BOOL InitApplication(HINSTANCE);
    BOOL InitInstance(HINSTANCE,int);HWND hwnd ;     //主窗口句柄
    HWND        hwndBotton; //按钮句柄int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR  lpCmdLine,int   nCmdShow)
    {
      // TODO: Place code here.
    MSG msg;

    if (!InitApplication(hInstance))
    return (FALSE);
    if (!InitInstance(hInstance,nCmdShow))
    return (FALSE);
    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    } return msg.wParam ;
    }BOOL InitApplication(HINSTANCE hInstance)
    {
    WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = (WNDPROC) WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon (NULL,"IDI_WINICON");
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH);
    wndclass.lpszMenuName = "IDR_FRAMEWIND";
    wndclass.lpszClassName = "HelloWin";

    if (!RegisterClass (&wndclass))
    {
    MessageBox (NULL, TEXT ("This program requires Windows NT!"), "HelloWin", MB_ICONERROR);

    return 0;
    }
    return (TRUE);
    }BOOL InitInstance( HINSTANCE  hInstance,int  nCmdShow)
    {

    hwnd = CreateWindow ("HelloWin",TEXT ("Vwind"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
    if (!hwnd)
    return (FALSE);

    ShowWindow (hwnd, nCmdShow);
    UpdateWindow (hwnd);
    return (TRUE);
    }LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

    switch (message)
    {
    case WM_SYSCOMMAND:
    switch(LOWORD(wParam))
    {
    //退出菜单
    case SC_CLOSE:
    MessageBox(hwnd, "wParam", "关闭", MB_YESNO );
    SendMessage(hwnd,WM_CLOSE,0,0);
    break;
    }
    break;
    case WM_DESTROY: //消息:本窗口正将被销毁
    //请求退出窗口和应用程序
    PostQuitMessage (0);
    break;
    default:
    //调用默认窗口过程对未处理的消息进行必要的处理
    return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return (0);
    }
      

  11.   

    楼主,基础不好呀。快学呀。
    在选X(或是选菜单) 的时候,那么系统收的消息是WM_SYSCOMMAND 而不是WM_COMMAND。
     对DefWindowProc的理解不沟深入。
     对ID理解有问题。你可能混淆了Dialog 的和Windows 的区别。