static message handlers 
Author Message
 static message handlers

Is it possible to assign static method as command handler without additional
nonstatic wrapper method? I.e. now I have some handlers looking like this:
void OnStaticJob() {CMyClass::DoStaticJob();}

Another problem is CCmdUI update handlers, which enables/disables command
according to BOOL IsX() method result. I have these BOOL IsX() methods, but
there is no way to 'connect' them with command update handlers, so I need to
define wrapper handlers, which just does this code:
OnUpdateX(CCmdUI* pCmdUI) {pCmdUI->Enable(IsX());}

Maybe there is more elegant solutions for these problems? Thanks in advance.



Sat, 17 Dec 2005 23:36:01 GMT  
 static message handlers
No.

I always get nervous when I see static handlers, because they often keep state in global
or static variables, which is starting down the Path To Perdition. static methods are
usually fairly rare, and typically only apply to methods where the behavior is totally
defined by the input parameters, and often exist to create objects (e.g.,
CWnd::FromHandle, CTime::GetCurrentTime). They are also needed for callback handlers. Most
of the time I see them outside these uses, they are someone trying to write C code in C++.

That said, you must do the wrapper. Note that if you are in CMyClass when you do the
function definition, you don't need the additional qualification, e.g.,
  class CMyClass : public CSomething {
     protected:
             static void DoStaticJob();
        void OnStaticJob() { DoStaticJob(); }
  };
works just fine.

The whole point of the update handlers is to use them as you describe. If you have an IsX
method, there really is no way to couple it to the command update logic without the
wrapper you show. Why does this seem to be a problem? It is how you are supposed to use
update command handlers.
                                joe

Quote:

>Is it possible to assign static method as command handler without additional
>nonstatic wrapper method? I.e. now I have some handlers looking like this:
>void OnStaticJob() {CMyClass::DoStaticJob();}

>Another problem is CCmdUI update handlers, which enables/disables command
>according to BOOL IsX() method result. I have these BOOL IsX() methods, but
>there is no way to 'connect' them with command update handlers, so I need to
>define wrapper handlers, which just does this code:
>OnUpdateX(CCmdUI* pCmdUI) {pCmdUI->Enable(IsX());}

>Maybe there is more elegant solutions for these problems? Thanks in advance.

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Sat, 17 Dec 2005 23:57:06 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mystery in Static Control message handler

2. Message handler for dynamic messages ?

3. message handler for shell notify icon callback message ?

4. How to add custom window message handler to MESSAGE MAP

5. How to apply an event handler when click on a static text

6. VC7: How to Specify the difference between Dialog Message Handler and Window Message Handler?

7. Visual C++ 2003 CTreeCtrl and Message Handlers

8. mapping multiple messages to one handler

9. VS7.0 IDE Problem (Can't add Message Handler Function)

10. Throwing an exception from a message handler?

11. calling base window message handler

12. Message Handler for Return Key

 

 
Powered by phpBB® Forum Software