Click to See Complete Forum and Search --> : PreTranslateMessage: how can I get the handle of the edit box the cursor is in?


Erich J. Ruth
May 16th, 1999, 09:58 PM
Let's say the user has their cursor in edit box
IDC_EDIT1. How can I write an if-statement saying

if (cursor in IDC_EDIT1) MessageBox("IDC_EDIT1");

while if the cursor is in edit box IDC_EDIT2, how
can I write:

if (cursor in IDC_EDIT2) MessageBox("IDC_EDIT2");

I am trying to get the handle from an edit box and
I am absolutely stuck and appreciate, as always, any
response any one can give me.

Roger Osborn
May 17th, 1999, 02:39 AM
Hi,

If it's the caret cursor you are interested in (i.e. which edit control has input focus) you can find out which by code like:


CWnd *pWnd=GetFocus();
if(pWnd)
{
TRACE("Focus in control %d",pWnd->GetDlgCtrlID( ));
}

(but see documentation on GetDlgCtrlID() to see when it's valid). Also, if you put the code in a button handler or similar then focus will have switched to that before it runs, so it will always give that control's id.


Roger

BrianOG
May 17th, 1999, 05:03 AM
If its the mouse cursor you're interested in (as opposed to the caret in edit boxes), you can try:POINT point;
::GetCursorPos(&point);
CWnd *pWnd = CWnd::WindowFromPoint(point);