<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Using_single_message_response_function</title><link>https://sourceforge.net/p/owlnext/wiki/Using_single_message_response_function/</link><description>Recent changes to Using_single_message_response_function</description><atom:link href="https://sourceforge.net/p/owlnext/wiki/Using_single_message_response_function/feed" rel="self"/><language>en</language><lastBuildDate>Fri, 27 Jun 2014 10:09:02 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/owlnext/wiki/Using_single_message_response_function/feed" rel="self" type="application/rss+xml"/><item><title>Using_single_message_response_function modified by Vidar Hasfjord</title><link>https://sourceforge.net/p/owlnext/wiki/Using_single_message_response_function/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -1,37 +1,42 @@
-Sometimes, a series of command messages may be related in such a way that it makes more sense to handle them all with a single message-response function than to create a message-response function for each. For example, a Line menu may enable a user to select one of several line thicknesses. It's logical to handle all Line menu commands in a single function whose job it is to set the line width. To perform this trick, you need to use EV_COMMAND_AND_ID macros in your window class's response table. 
+Sometimes, a series of command messages may be related in such a way that it makes more sense to handle them all with a single message-response function than to create a function for each. For example, a Line menu may enable a user to select one of several line thicknesses. It's logical to handle all Line menu commands in a single function whose job it is to set the line width. To perform this trick, you need to use EV_COMMAND_AND_ID macros in your window class's response table.

 ## The Solution

 First, create a response table that contains an EV_COMMAND_AND_ID macro for each message you want handled by the single message-response function, using the same function as the macro's second argument: 

-    &amp;lt;pre&amp;gt;
-    DEFINE_RESPONSE_TABLE1(TWndw, TFrameWindow)
-      EV_COMMAND_AND_ID(CM_COHHAND1, CmCommand),
-      EV_COMMAND_AND_ID(CM_COMMAND2, CmCommand),
-      EV_COMMAND_AND_ID(CM_COMHAND3, CmCommand),
+    DEFINE_RESPONSE_TABLE1(TLineWindow, TFrameWindow)
+      EV_COMMAND_AND_ID(CM_LINEWIDTH1, CmLineWidth),
+      EV_COMMAND_AND_ID(CM_LINEWIDTH2, CmLineWidth),
+      EV_COMMAND_AND_ID(CM_LINEWIDTH3, CmLineWidth),
     END RESPONSE TABLE;

-&amp;lt;/pre&amp;gt;
-
-The EV_COMMAND_AND_ID macro takes exactly the same arguments as the EV_COMMAND macro: the message ID and the name of the function that will handle that message. 
-
-The difference is that, when the program calls the message-response function, it sends along the ID of the message that triggered the call. In the message-response function, use this parameter to determine which message you need to respond to: 
+The EV_COMMAND_AND_ID macro takes exactly the same arguments as the EV_COMMAND macro: the message ID and the name of the function that will handle that message. The difference is that when the program calls the message-response function it sends along the ID of the message that triggered the call. In the message-response function, use this parameter to implement the handler appropriately: 

-    &amp;lt;pre&amp;gt;
-    void TWndw::CmCommand(WPARAM messageld)
+    void TLineWindow::CmLineWidth(WPARAM id)
+    {
+      typedef std::map&amp;lt;WPARAM, int&amp;gt; LineWidthMap;
+      const LineWidthMap::value_type v[] = 
+        {{CM_LINEWIDTH1, 1}, {CM_LINEWIDTH2, 5}, {CM_LINEWIDTH3, 10}};
+      static const LineWidthMap m(v, v + COUNTOF(v));
+      SetLineWidth(m[idWidth]); // 0 if not in map
+    } 
+    
+
+On the other hand, beware that if your handler ends up looking like the following you should really consider using separate handlers. Don't do manual dispatch. 
+    
+    
+    void TMyWindow::CmCommand(WPARAM messageld)
     {
       switch (messageld) {
-        case CM_COMMAND1 /* Handle message 1 */
+        case CM_COMMAND1: /* Handle message 1 */
           break;
-        case CM_COMMAND2 /* Handle message 2 */
+        case CM_COMMAND2: /* Handle message 2 */
           break;
-        case CM_COMMAND3 /* Handle message 3 */
+        case CM_COMMAND3: /* Handle message 3 */
           break;
       }
     } 

-
-&amp;lt;/pre&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Vidar Hasfjord</dc:creator><pubDate>Fri, 27 Jun 2014 10:09:02 -0000</pubDate><guid>https://sourceforge.netc0afcd0300573edea88b9bae25b9d985fa616a6c</guid></item><item><title>Using_single_message_response_function modified by Ognian Tchernokojev</title><link>https://sourceforge.net/p/owlnext/wiki/Using_single_message_response_function/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,4 +1,6 @@
-Sometimes, a series of command messages may be related in such a way that it makes more sense to handle them all with a single message-response function than to create a message-response function for each. For example, a Line menu may enable a user to select one of several line thicknesses. It's logical to handle all Line menu commands in a single function whose job it is to set the line width. To perform this trick, you need to use EV_COMMAND_AND_ID macros in your window class's response table. The Solution 
+Sometimes, a series of command messages may be related in such a way that it makes more sense to handle them all with a single message-response function than to create a message-response function for each. For example, a Line menu may enable a user to select one of several line thicknesses. It's logical to handle all Line menu commands in a single function whose job it is to set the line width. To perform this trick, you need to use EV_COMMAND_AND_ID macros in your window class's response table. 
+
+## The Solution

 First, create a response table that contains an EV_COMMAND_AND_ID macro for each message you want handled by the single message-response function, using the same function as the macro's second argument: 

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ognian Tchernokojev</dc:creator><pubDate>Fri, 27 Jun 2014 10:09:02 -0000</pubDate><guid>https://sourceforge.nete6c631cdb4fc064ac3b84f96b6d564e16c016a87</guid></item><item><title>Using_single_message_response_function modified by Ognian Tchernokojev</title><link>https://sourceforge.net/p/owlnext/wiki/Using_single_message_response_function/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Sometimes, a series of command messages may be related in such a way that it makes more sense to handle them all with a single message-response function than to create a message-response function for each. For example, a Line menu may enable a user to select one of several line thicknesses. It's logical to handle all Line menu commands in a single function whose job it is to set the line width. To perform this trick, you need to use EV_COMMAND_AND_ID macros in your window class's response table. The Solution &lt;/p&gt;
&lt;p&gt;First, create a response table that contains an EV_COMMAND_AND_ID macro for each message you want handled by the single message-response function, using the same function as the macro's second argument: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;pre&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;DEFINE_RESPONSE_TABLE1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;TWndw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;TFrameWindow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;EV_COMMAND_AND_ID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CM_COHHAND1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CmCommand&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;EV_COMMAND_AND_ID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CM_COMMAND2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CmCommand&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;EV_COMMAND_AND_ID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CM_COMHAND3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CmCommand&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="n"&gt;END&lt;/span&gt; &lt;span class="n"&gt;RESPONSE&lt;/span&gt; &lt;span class="n"&gt;TABLE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;lt;/pre&amp;gt;&lt;/p&gt;
&lt;p&gt;The EV_COMMAND_AND_ID macro takes exactly the same arguments as the EV_COMMAND macro: the message ID and the name of the function that will handle that message. &lt;/p&gt;
&lt;p&gt;The difference is that, when the program calls the message-response function, it sends along the ID of the message that triggered the call. In the message-response function, use this parameter to determine which message you need to respond to: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;pre&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;TWndw&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;CmCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;WPARAM&lt;/span&gt; &lt;span class="n"&gt;messageld&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageld&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;CM_COMMAND1&lt;/span&gt; &lt;span class="cm"&gt;/* Handle message 1 */&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;CM_COMMAND2&lt;/span&gt; &lt;span class="cm"&gt;/* Handle message 2 */&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;CM_COMMAND3&lt;/span&gt; &lt;span class="cm"&gt;/* Handle message 3 */&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;lt;/pre&amp;gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ognian Tchernokojev</dc:creator><pubDate>Fri, 27 Jun 2014 10:09:01 -0000</pubDate><guid>https://sourceforge.net060e4f5e7e7b89a72efd3fe64ed93d0eddf7a50e</guid></item></channel></rss>