?
Solved

How to know the ID of the control who received an event

Posted on 2000-05-13
1
Medium Priority
?
198 Views
Last Modified: 2013-11-20
Hi...

I have placed some ActiveX controls in a Dialog Resource. Those controls have to make some actions when the mouse is over or has clicked on it. I'm planning to use only 1 event handler to accomplish the actions for all controls so I need to know the ID of the control who has thrown the event.

How can I do it?
Thanks in advance

Demarcy
0
Comment
Question by:demarcy
1 Comment
 
LVL 8

Accepted Solution

by:
Vinayak Kumbar earned 200 total points
ID: 2807914
Hi,

Map the PreTranslateMessage(...) message handler to that dialog. And modify the code as

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
      if(pMsg->message == WM_MOUSEMOVE)
      {
            CRect rect;
            GetDlgItem(IDC_EDIT1)->GetWindowRect(rect);
            if(rect.PtInRect(pMsg->pt))
            {
                  AfxMessageBox("Mouse On The Edit Box");
                  return CDialog::PreTranslateMessage(pMsg);
            }
            
            GetDlgItem(IDC_LIST1)->GetWindowRect(rect);
            if(rect.PtInRect(pMsg->pt))
            {
                  AfxMessageBox("Mouse On The List Box");
                  return CDialog::PreTranslateMessage(pMsg);
            }

            GetDlgItem(IDC_MY_DBGRID)->GetWindowRect(rect);
            if(rect.PtInRect(pMsg->pt))
            {
                  AfxMessageBox("Mouse On The DB Grid Box");
                  return CDialog::PreTranslateMessage(pMsg);
            }

            GetDlgItem(IDOK)->GetWindowRect(rect);
            if(rect.PtInRect(pMsg->pt))
            {
                  AfxMessageBox("Mouse On The OK Button");
                  return CDialog::PreTranslateMessage(pMsg);
            }

      }
      return CDialog::PreTranslateMessage(pMsg);
}

here I have taken some normal controls and a activex dbgrid control. U can make out by thier ID. But here U R not getting the ID's but, u will know where the mouse is. So u can replace the AfxMessageBox() with Ur function call and their U know the id also as if it says I am in DBGrid, then ID is known as ID_MY_DBGRID.

Hope this helps.

VinExpert
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

839 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