Solved

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

Posted on 2000-05-13
1
188 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:
VinExpert earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now