CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    5

    PreTranslateMessage: how can I get the handle of the edit box the cursor is in?

    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.





  2. #2
    Join Date
    Apr 1999
    Posts
    48

    Re: PreTranslateMessage: how can I get the handle of the edit box the cursor is in?

    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



  3. #3
    Join Date
    May 1999
    Posts
    116

    Re: PreTranslateMessage: how can I get the handle of the edit box the cursor is in?

    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);





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured