I have created a small MFC Document View App in C++ and I am having some trouble receiving messages in a class that inherits from CStatic. I have managed to create the CStatic derivative and it is visible on my View however my message handlers are not being fired.
When using Spy++ it seems that window is only receiving WM_NCHITTEST
and it is returning HTTRANSPARENT
, which according to MSDN means:
"In a window currently covered by another window in the same thread (the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT)."
Here is an exert from Spy++:
<000001> 001D1350 S WM_NCHITTEST xPos:128 yPos:167
<000002> 001D1350 R WM_NCHITTEST nHittest:HTTRANSPARENT
<000003> 001D1350 S WM_NCHITTEST xPos:128 yPos:166
<000004> 001D1350 R WM_NCHITTEST nHittest:HTTRANSPARENT
<000005> 001D1350 S WM_NCHITTEST xPos:128 yPos:165
<000006> 001D1350 R WM_NCHITTEST nHittest:HTTRANSPARENT
<000007> 001D1350 S WM_NCHITTEST xPos:128 yPos:164
<000008> 001D1350 R WM_NCHITTEST nHittest:HTTRANSPARENT
This seems strange because the CStatic derivative is the only child window of my view. I created it like this:
Create(pItem->Value->GetBuffer(), WS_CHILD | WS_VISIBLE | SS_CENTER, Rect, Parent);
ShowWindow(SW_SHOW);
where Parent
is a pointer to the CView
.
Any help would be really appreciated.
EDIT:
Foo.h
class Foo: public CStatic
{
DECLARE_DYNAMIC(Foo)
public:
Foo();
virtual ~Foo();
virtual void CreateCtrl(CWnd * Parent, POINT TopLeft, SIZE sz);
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};
Foo.cpp
void Foo::CreateCtrl(CWnd * Parent, POINT TopLeft, SIZE sz)
{
CRect Rect(TopLeft, sz);
Create(pItem->Value->GetBuffer(), WS_CHILD | WS_VISIBLE | SS_CENTER, Rect, Parent);
ShowWindow(SW_SHOW);
}
BEGIN_MESSAGE_MAP(Foo, CStatic)
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
void Foo::OnLButtonUp(UINT nFlags, CPoint point)
{
AfxMessageBox("Hello World!");
__super::OnLButtonUp(nFlags, point);
}
CStatic
? – Edward ClementsOnLButtonUp
. I did have a look around SO and though some questions are similar I don't think they are the same as mine. – Shane HawOnLButtonUp
handler? – Edward Clements