?
Solved

Handling message of controls on dialog boxes

Posted on 2001-09-04
10
Medium Priority
?
253 Views
Last Modified: 2013-11-20
Hi
I have a dialog box on which there is a button control. I wish to handle the mouse move message on the button.
That is when the user moves the mouse over the button on the dialog box, I wish to change the background & foreground color of the button. How do I achieve this?
The environment is VC++ 6.0, MFC and the application is a dialog based application.

Thanks
Rashmin
0
Comment
Question by:rsanwatsarkar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6453309
Derive a class from CButton,let's say CBtn. Go to class wizard and override WM_MOUSEMOVE event for CBtn class and do your drawing there. Map a control of CBtn type over your button.
0
 
LVL 3

Author Comment

by:rsanwatsarkar
ID: 6453334
Hi
Thanks for the quick answer. How do I map the control of CBtn over my button. Can u please elaborate it a bit

Thanks
Rashmin
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6453411
Go to class wizzard, Member Variables tab.
At class name select the name o the dialog class that contains the button.
At controls id's select the id of your button.
Press Add variable button on the right.
At category select control.
At type select CBtn.
Enter a name.
Press Ok button.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 3

Author Comment

by:rsanwatsarkar
ID: 6453576
Hi
I tried adding the member variable, specifying the type as CBtn. In the CBtn class, I have overridden the OnCtlColor function and changed the background color using the
     pDC->SetBkColor( RGB(255,0,0) );
function
But the background of the button is still noy changing. Do I need to do anyting specific in my dialog class which is hosting the button?
Thanks
Rashmin
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6453610
No, override the on paint to paint the button.
0
 
LVL 3

Author Comment

by:rsanwatsarkar
ID: 6453642
Thanks a lot for the quick reply.

I tried the following code in the OnPaint of CBtn

     CPaintDC dc(this); // device context for painting

     if(m_bMouseOver )
     {
          dc.SetBkColor( RGB(255,0,0) );
          m_bMouseOver = FALSE;
     }
     else
          dc.SetBkColor( RGB(0,255,0) );


The m_bMouseOver is set to true in the OnMouseMove implementaion of CBtn

But its still not working.

Can u please tell what is the problem?
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6453777
void CBtn::OnMouseMove(UINT nFlags, CPoint point)
{
     m_bMouseOver = TRUE;
     Invalidate();
     TRACE("mouse over \n");
}

void CBtn::OnPaint()
{
     CPaintDC dc(this); // device context for painting
     CBrush br;
     TRACE("painting \n");
     RECT rc;
     GetClientRect( &rc );
     if(m_bMouseOver )
     {
          TRACE("mouse true \n");
          br.CreateSolidBrush( RGB ( 255,0,0 ) );
          m_bMouseOver = FALSE;
     }
     else
     {
          TRACE("mouse false \n");
          br.CreateSolidBrush( RGB ( 0,255,0 ) );
     }
          dc.FillRect( &rc, &br );
     
}

I recomand you to override the OnMouseMove on your Dialog class and redraw the button.

If u want more, set the button style BS_OWNERDRAW and override the CButton::DrawItem() function.
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6453791
Don't forget m_bMouseOver = FALSE on constructor.
0
 
LVL 3

Author Comment

by:rsanwatsarkar
ID: 6454195
Hey thanks a lot for the help. I tried that and the color changes to red when the mouse moves over the button but it stays red when the mouse moves away from the button. It does not turn back green again. Why is it so?
Why do I need to overridethe OnMouseMove of dialog  to redraw the button?
Rashmin
0
 
LVL 2

Accepted Solution

by:
BogdyPtr earned 200 total points
ID: 6454209
So the color change back to green. The button dosen't know when the mouse is leaving. U can use a timer to periodicaly check if the mouse is on the button if u want.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question