From: Phil on
I was having the same trouble with a static control. By default, when they're created, static controls don't have the Notify style flag set to true, so don't get these notifications. Set it to true in appstudio and you'll be sorted. This is actually mentioned above but I almost missed it - thanks whoever pointed it out above.



geeta.mudaliya wrote:

Re: Mouse movement within CStatic/Picture box
30-Jun-07

On Jun 14, 1:45 am, MD <madhu.da...(a)gmail.com> wrote:

I am also trying to do the same activity. problem here is though i
have mapped the CStatic - dervied class LButtonDown(), MouseMove() and
LButtonUp(), my dlgbox does not process these functions on event
occurance.

the test code is as follows:-

void CDrawingStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("Hi Btn Down");
CStatic::OnLButtonDown(nFlags, point);
}

void CDrawingStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("Hi Btn Up");
CStatic::OnLButtonUp(nFlags, point);
}

void CDrawingStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("Hi MouseMv");
CStatic::OnMouseMove(nFlags, point);
}



please guide me what's wrong here?

Previous Posts In This Thread:

On Monday, June 11, 2007 9:15 PM
MD wrote:

Mouse movement within CStatic/Picture box
Hello,

I have a picture box, in which I need to draw a rectangle when user
makes a selection by dragging the mouse.

I am able to capture the mouse click event in the picture box(by
deriving from CStatic and handled the
ON_STN_CLICKED event from main Form).

But I am unable to understand how to capture mouse drag/ draw a
rectangle over picture box when the mouse moves. (New to MFC
programming, Pls help, any tips on how to handle OnLButtonUp,
OnMouseMove events for CStatic controls!) I really appreciate any
help.


Heres the code of what I have right now:

CpictureBox.h
------------------------------------------------------------------------------------------------------
class CPictureBox : public CStatic
{
DECLARE_DYNAMIC(CPictureBox)

public:
CPictureBox();
virtual ~CPictureBox();
void SetBitmap(CString strBitmap);
protected:
afx_msg void OnPaint();
void ShowBitmap(CPaintDC *pDC);
CString m_sBitmap;
CBitmap m_bmpBitmap;
BITMAP bm;
CRect m_Rect;

DECLARE_MESSAGE_MAP()
};

void CPictureBox::OnLButtonDown(UINT nFlags, CPoint point)
{
m_Tracking = TRUE;
SetCapture();
m_Rect.right = m_Rect.left = point.x;
m_Rect.bottom = m_Rect.top = point.y;
Invalidate();
CStatic::OnLButtonDown(nFlags, point);

}

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

CPictureBox.cpp -- These dont get the control when events are fired!

----------------------------------------------------------------------------------------------------
void CPictureBox::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_Tracking)
{
m_Rect.right = point.x;
m_Rect.bottom = point.y;
Invalidate();
}

CStatic::OnMouseMove(nFlags, point);
}

----------------------------
Main Dialog.cpp--
-----------------
BEGIN_MESSAGE_MAP(CmfcThsProj1Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BTN_BROWSE, OnBnClickedBtnBrowse)
ON_WM_MOUSEMOVE()
ON_STN_CLICKED(IDC_STATIC_PICBOX, OnStnClickedStaticPicbox)
END_MESSAGE_MAP()


void CmfcThsProj1Dlg::OnStnClickedStaticPicbox()
{
// TODO: Add your control notification handler code here
MessageBox("hello world");
//CPictureBox::OnLButtonUp
//m_PictureBox.Invalidate();
}

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

-Thanks

On Monday, June 11, 2007 10:38 PM
Scott McPhillips [MVP] wrote:

Re: Mouse movement within CStatic/Picture box
MD wrote:

What is ON_STN_CLICKED?

To get the mouse messages in your CStatic-derived class you need to add
entries to the CStatic-derived class message map, not to the main
window's message map. Windows sends the mouse messages directly to the
static control when the mouse is on the static control.

--
Scott McPhillips [MVP VC++]

On Tuesday, June 12, 2007 1:19 AM
Tom Serface wrote:

You might find this sample program interesting.
You might find this sample program interesting. It illustrates drag and
drop of objects. It doesn't draw a rectangle, but resize "dots" are put
around the object.

http://msdn2.microsoft.com/en-us/library/9t94971d(VS.80).aspx

You might also find this article interesting:

http://www.codeproject.com/shell/dragdrop.asp?df=100&forumid=2238&exp=0&select=790736

Also, one thing to note is that static controls don't display a focus
rectangle by default. You'll have to develop your own control and add a
call to:

http://msdn2.microsoft.com/en-us/library/ms534886.aspx

I've never done this sort of thing, never had to, but I think you could set
the focus rectangle in OnSetFocus() OnKillFocus().

You may want to use something besides a static (like create your own object)
for doing drag and drop type things. Hopefully, these examples help.

Tom


"MD" <madhu.datla(a)gmail.com> wrote in message
news:1181610949.461689.237730(a)r19g2000prf.googlegroups.com...

On Tuesday, June 12, 2007 1:22 AM
armancho_ wrote:

Re: Mouse movement within CStatic/Picture box
"Scott McPhillips [MVP]" wrote:


it is defined as ON_CONTROL(STN_CLICKED, ctrlId, memFunc),
and STN_CLICKED is defined as 0 [the same as BN_CLICKED].



--
======
Arman

On Tuesday, June 12, 2007 10:50 AM
AliR \(VC++ MVP\) wrote:

Drawing a rectangle with the user draging the mouse in any window would be
Drawing a rectangle with the user draging the mouse in any window would be
like this: (make sure the static control has the notify flag set to true)

void CDrawingStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
//capture mouse
SetCapture();

//set the flag so that MouseMove will adjust the end of the rectangle
m_Capture = TRUE;
m_Rect.SetRect(point.x,point.y,point.x+10,point.y+10);

CStatic::OnLButtonDown(nFlags, point);
}

void CDrawingStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
//release mouse capture
ReleaseCapture();

m_Capture = FALSE;

m_Rect.right = point.x;
m_Rect.bottom = point.y;

Invalidate();
CStatic::OnLButtonUp(nFlags, point);
}

void CDrawingStatic:OnMouseMove(UINT nFlags, CPoint point)
{
if (m_Capture)
{
m_Rect.right = point.x;
m_Rect.bottom = point.y;

Invalidate();
}

CStatic::OnMouseMove(nFlags, point);
}

AliR.

"MD" <madhu.datla(a)gmail.com> wrote in message
news:1181610949.461689.237730(a)r19g2000prf.googlegroups.com...

On Wednesday, June 13, 2007 2:34 AM
MD wrote:

Re: Mouse movement within CStatic/Picture box
Thanks Scott, Tom , Alir, Arman:

Like I told I am just a beginner in MFC programming. I started on a
wrong foot with handling ON_STN_CLICKED. Thats the event for clicking
on Static controls within a dialog.

But I was able to work this out using Alir's method.Now I am able to
draw a rectangle on picture box using the following code, now the
problem is as I move the mouse there will be a track of rectangles
over the picture box, I was wondering if you guys can suggest a method
where I can refresh the picture box or reset the previous rectangle,
so that as I drag only one final rectangle remains .

void CPictureBox::OnPaint()
{
CPaintDC pDC(this); // device context for painting

RECT rect;
GetClientRect(&rect);
if(m_Tracking==TRUE)
{
pDC.SelectStockObject(HOLLOW_BRUSH);
pDC.Rectangle(m_Rect); //rectangle
coordinates captured in mousedown/up and move events

}
else
if(m_sBitmap!="")
ShowBitmap(&pDC);
}

Thanks for the help,

On Wednesday, June 13, 2007 2:50 AM
MD wrote:

Re: Mouse movement within CStatic/Picture box
On Jun 12, 11:34 pm, MD <madhu.da...(a)gmail.com> wrote:

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

Hi Guys,

I tried something here, Why does not this work?

if(m_Tracking)
{
this->SetBitmap(NULL);
//m_bmpBitmap.DeleteObject();
if(m_sBitmap!="")
ShowBitmap(&pDC);
pDC.SelectStockObject(HOLLOW_BRUSH);
pDC.Rectangle(m_Rect);
}

Thanks,

On Wednesday, June 13, 2007 9:37 AM
Scott McPhillips [MVP] wrote:

Re: Mouse movement within CStatic/Picture box
MD wrote:

OnPaint must paint the entire picture box, not just add to it. The
reason is that the image on a window can be destroyed by other popup
windows, and Windows calls OnPaint when you need to fix it. So you
should make it always paint the bitmap and then optionally add the
tracking rect. In fact, if you don't currently have a bitmap you should
draw a blank background rect to "fix" an empty box. Otherwise an image
of the other popup window will remain.

By the way, if(m_Tracking==TRUE) is very poor style and error-prone: Use

if (m_Tracking)
....

--
Scott McPhillips [MVP VC++]

On Wednesday, June 13, 2007 4:45 PM
MD wrote:

Re: Mouse movement within CStatic/Picture box
scottmcp> wrote:

Thanks Scott,

I understood what you were trying to say, and I fixed it. I have it
working now.

-MD

On Saturday, June 30, 2007 3:26 AM
geeta.mudaliya wrote:

Re: Mouse movement within CStatic/Picture box
On Jun 14, 1:45 am, MD <madhu.da...(a)gmail.com> wrote:

I am also trying to do the same activity. problem here is though i
have mapped the CStatic - dervied class LButtonDown(), MouseMove() and
LButtonUp(), my dlgbox does not process these functions on event
occurance.

the test code is as follows:-

void CDrawingStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("Hi Btn Down");
CStatic::OnLButtonDown(nFlags, point);
}

void CDrawingStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("Hi Btn Up");
CStatic::OnLButtonUp(nFlags, point);
}

void CDrawingStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("Hi MouseMv");
CStatic::OnMouseMove(nFlags, point);
}



please guide me what's wrong here?

On Saturday, June 30, 2007 9:22 AM
Scott McPhillips [MVP] wrote:

Re: Mouse movement within CStatic/Picture box
geeta.mudaliyar(a)gmail.com wrote:

Tell us more about your problem. Does the message box appear? The
dialog box is not expected to process these messages, so your posting is
not clear.

Make sure you edited the control ID (IDC_STATIC is not unique) and make
sure you added a control member variable in the dialog.

--
Scott McPhillips [MVP VC++]


Submitted via EggHeadCafe - Software Developer Portal of Choice
Team Foundation Server Installation and Troubleshooting
http://www.eggheadcafe.com/tutorials/aspnet/9da90e38-eaa6-4b8d-ad12-76d56f25f385/team-foundation-server-in.aspx