什么时候改用 ON_CONTROL ? 什么时候改用 ON_NOTIFY ??

解决方案 »

  1.   

    先在MSDN上看这两个宏的解释.把看不懂的地方贴出来.
      

  2.   

    http://www.codeguru.com/forum/printthread.php?t=137313Alex Fedotov 06-06-2001 11:13 PM 
    --------------------------------------------------------------------------------
    Re: What is the difference between ON_NOTIFY and ON_CONTROL
    ON_CONTROL is used to define message map entries for old-style control
    notifications that are based on WM_COMMAND message. ON_NOTIFY is used
    to define message map entries for WM_NOTIFY-based notifications that
    were introduced in Win32.fblaha 06-06-2001 11:31 PM 
    --------------------------------------------------------------------------------
    Re: What is the difference between ON_NOTIFY and ON_CONTROL
     
    The difference is that ON_CONTROL define custom notification and isn't supported by ClassWizard. You must add something like ON_CONTROL(YourNotificationCode, ....) to message map entry.In case of ON_NOTIFY you can use ClassWizard. Otherwise, there isn't( on my opinion) signicificat difference. From programmers points of view. 
      

  3.   

    ON_CONTROL,ON_NOTIFY是控件发给父窗口的消息映射
    如果消息是通过WM_COMMAND发出的,用ON_CONTROL()映射,
    如果消息是通过WM_NOTIFY发出的,用ON_NOTIFY映射,
    早期的通知消息是通过WM_COMMAND“携带”过来的,
    后来通知消息种类太多了,微软又增加了WM_NOTIFY消息专门处理,
    为了向前兼容,所以出现了WM_COMMAND和WM_NOTIFY同时用于
    传递通知消息的局面,不错,ON_COMMAND宏也是针对WM_COMMAND消息,但是它是专门针对
    CN_COMMAND这个通知消息,所以就不用指定通知码了 :)最直观地比较可以从宏定义看出来:#define ON_COMMAND(id, memberFxn) \
    { WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSigCmd_v, \
    #define ON_CONTROL(wNotifyCode, id, memberFxn) \
    { WM_COMMAND, (WORD)wNotifyCode, (WORD)id, (WORD)id, AfxSigCmd_v, \
    #define ON_NOTIFY(wNotifyCode, id, memberFxn) \
    { WM_NOTIFY, (WORD)(int)wNotifyCode, (WORD)id, (WORD)id, AfxSigNotify_v, \