SetCursor weirdness

"domehead100" <[email protected]>
Newsgroups gmane.comp.windows.wtl
Message-ID <[email protected]>
Hi Folks,

So, I've writtten this window finder thingie, like the window finder in Spy++ but hopefully a lot better.

It's based on CStatic and displays a bitmap of a crosshairs-type picture, and when you click on it you can drag the crosshairs over different windows and it highlights them.  

I was reviewing the code today and discovered a couple of oddities that have me quite confused.  I'm wondering if anyone could help explain things.

Oddity #1

When reviewing the code, I discovered that the class was declared like this:

template<class TValidator = CNoSWSValidate>
class CSelectWindowStaticT : public CWindowImpl<CStatic>
{
...
}

Note that it is not ": public CWindowImpl<CSelectWindowStaticT<TValidator>, CStatic>", it's just ": public CWindowImpl<CStatic>"

Yet, all of my message handlers in CSelectWindowStaticT ARE being called (OnMouseMove, OnLButtonDown, etc.).

Why?  The message map should be calling ProcessWindowMessage for the first template argument to CWindowImpl, and CStatic is not an Impl class and has no such function.  Well, actually it should static_cast itself to CStatic and then end-up calling it's own ProcessWindowMessage because CStatic has none.  

Why it is calling my message map/handlers when it shouldn't even know they exist?


Oddity #2
One of the things the OnLButtonDown handler does is call SetCursor() to set the cursor (mouse pointer) to the crosshairs.  Then it calls SetCapture() to track the mouse movement.  As it turns out, the class works perfectly when it's ": public CWindowImpl<CStatic>"; e.g., when I click on the control the crosshairs seem to move off of the static as I move the mouse.

When I derive it correctly, however, then when I click the left mouse button the cursor remains the standard arrow and does not change to the crosshairs.

I have an OnSetCursor() handler that sets the cursor to the crosshairs if "window-finding" has begun, but that is never called after the left mouse click due to the SetCapture() call.  If "window-finding" has not begun, it just passes the message to the DefWindowProc.  But the SetCursor in OnLButtonDown seems to have absolutely no effect if I've derived the class correctly but to work perfectly if I've derived from CWindowImpl<CStatic>.

Any comments would be welcome; I'm really scratching my head at the moment.

~Mike



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wtl/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/wtl/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.