Find the control which mouse is over in MFC












0















Is there anyway when mouse moving find the control mouse is over on it? I mean if you have a dialog with some labels and text boxes, and the mouse move to label, notify me that label name, after that if move it to text box notify the text box name.










share|improve this question

























  • In your own program you can do everything, since you know position of all child windows. Generic way is using ChildWindowFromPoint API.

    – Alex F
    Nov 12 '13 at 10:07








  • 2





    Windows don't have names. A dialog template sets the control ID of the window, CWnd::GetDlgCtrlID() returns it. This is of course not useful to the user at all, little point in actually writing this code.

    – Hans Passant
    Nov 12 '13 at 10:36











  • @HansPassant none the less a perfectly valid and helpful point if the OP is hellbent on hunting for one thing when they should be looking for something else. Good info.

    – WhozCraig
    Nov 12 '13 at 10:49
















0















Is there anyway when mouse moving find the control mouse is over on it? I mean if you have a dialog with some labels and text boxes, and the mouse move to label, notify me that label name, after that if move it to text box notify the text box name.










share|improve this question

























  • In your own program you can do everything, since you know position of all child windows. Generic way is using ChildWindowFromPoint API.

    – Alex F
    Nov 12 '13 at 10:07








  • 2





    Windows don't have names. A dialog template sets the control ID of the window, CWnd::GetDlgCtrlID() returns it. This is of course not useful to the user at all, little point in actually writing this code.

    – Hans Passant
    Nov 12 '13 at 10:36











  • @HansPassant none the less a perfectly valid and helpful point if the OP is hellbent on hunting for one thing when they should be looking for something else. Good info.

    – WhozCraig
    Nov 12 '13 at 10:49














0












0








0








Is there anyway when mouse moving find the control mouse is over on it? I mean if you have a dialog with some labels and text boxes, and the mouse move to label, notify me that label name, after that if move it to text box notify the text box name.










share|improve this question
















Is there anyway when mouse moving find the control mouse is over on it? I mean if you have a dialog with some labels and text boxes, and the mouse move to label, notify me that label name, after that if move it to text box notify the text box name.







c++ mfc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '13 at 10:16









R. Martinho Fernandes

163k57380469




163k57380469










asked Nov 12 '13 at 9:57









paytampaytam

94412




94412













  • In your own program you can do everything, since you know position of all child windows. Generic way is using ChildWindowFromPoint API.

    – Alex F
    Nov 12 '13 at 10:07








  • 2





    Windows don't have names. A dialog template sets the control ID of the window, CWnd::GetDlgCtrlID() returns it. This is of course not useful to the user at all, little point in actually writing this code.

    – Hans Passant
    Nov 12 '13 at 10:36











  • @HansPassant none the less a perfectly valid and helpful point if the OP is hellbent on hunting for one thing when they should be looking for something else. Good info.

    – WhozCraig
    Nov 12 '13 at 10:49



















  • In your own program you can do everything, since you know position of all child windows. Generic way is using ChildWindowFromPoint API.

    – Alex F
    Nov 12 '13 at 10:07








  • 2





    Windows don't have names. A dialog template sets the control ID of the window, CWnd::GetDlgCtrlID() returns it. This is of course not useful to the user at all, little point in actually writing this code.

    – Hans Passant
    Nov 12 '13 at 10:36











  • @HansPassant none the less a perfectly valid and helpful point if the OP is hellbent on hunting for one thing when they should be looking for something else. Good info.

    – WhozCraig
    Nov 12 '13 at 10:49

















In your own program you can do everything, since you know position of all child windows. Generic way is using ChildWindowFromPoint API.

– Alex F
Nov 12 '13 at 10:07







In your own program you can do everything, since you know position of all child windows. Generic way is using ChildWindowFromPoint API.

– Alex F
Nov 12 '13 at 10:07






2




2





Windows don't have names. A dialog template sets the control ID of the window, CWnd::GetDlgCtrlID() returns it. This is of course not useful to the user at all, little point in actually writing this code.

– Hans Passant
Nov 12 '13 at 10:36





Windows don't have names. A dialog template sets the control ID of the window, CWnd::GetDlgCtrlID() returns it. This is of course not useful to the user at all, little point in actually writing this code.

– Hans Passant
Nov 12 '13 at 10:36













@HansPassant none the less a perfectly valid and helpful point if the OP is hellbent on hunting for one thing when they should be looking for something else. Good info.

– WhozCraig
Nov 12 '13 at 10:49





@HansPassant none the less a perfectly valid and helpful point if the OP is hellbent on hunting for one thing when they should be looking for something else. Good info.

– WhozCraig
Nov 12 '13 at 10:49












2 Answers
2






active

oldest

votes


















1














If you handle WM_MOUSEMOVE within your dialog, you can grab the mouse position, convert it to dialog coordinates, and determine what control lies underneath the cursor point.






share|improve this answer
























  • WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

    – IInspectable
    Nov 12 '13 at 14:36



















1














After some research, I came to this code which let me know if the mouse cursor is over my control in a dialog box.



//Handling mouse move in mfc dialog

void CDialogRoll::OnMouseMove(UINT nFlags, CPoint point)
{

CRect rect1;

m_FrameArea.GetClientRect(&rect1); //control rectangle

m_FrameArea.ClientToScreen(&rect1)
ScreenToClient(&rect1); //dialog coordinates`
if (point.x >= rect1.left && point.x <= rect1.right && point.y >= rect1.top &&
point.y <= rect1.bottom) {
char str[100];
sprintf(str, "%d-%d", point.x - rect1.left, point.y - rect1.top);

}
CDialogEx::OnMouseMove(nFlags, point);
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19926020%2ffind-the-control-which-mouse-is-over-in-mfc%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    If you handle WM_MOUSEMOVE within your dialog, you can grab the mouse position, convert it to dialog coordinates, and determine what control lies underneath the cursor point.






    share|improve this answer
























    • WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

      – IInspectable
      Nov 12 '13 at 14:36
















    1














    If you handle WM_MOUSEMOVE within your dialog, you can grab the mouse position, convert it to dialog coordinates, and determine what control lies underneath the cursor point.






    share|improve this answer
























    • WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

      – IInspectable
      Nov 12 '13 at 14:36














    1












    1








    1







    If you handle WM_MOUSEMOVE within your dialog, you can grab the mouse position, convert it to dialog coordinates, and determine what control lies underneath the cursor point.






    share|improve this answer













    If you handle WM_MOUSEMOVE within your dialog, you can grab the mouse position, convert it to dialog coordinates, and determine what control lies underneath the cursor point.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 12 '13 at 13:34









    rrirowerrrirower

    3,51121732




    3,51121732













    • WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

      – IInspectable
      Nov 12 '13 at 14:36



















    • WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

      – IInspectable
      Nov 12 '13 at 14:36

















    WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

    – IInspectable
    Nov 12 '13 at 14:36





    WM_MOUSEMOVE is sent to the control underneath the mouse cursor (unless the control is disabled). DispatchMessage already determined which control is underneath the mouse cursor. You don't have to find the answer to a question the system already answered for you.

    – IInspectable
    Nov 12 '13 at 14:36













    1














    After some research, I came to this code which let me know if the mouse cursor is over my control in a dialog box.



    //Handling mouse move in mfc dialog

    void CDialogRoll::OnMouseMove(UINT nFlags, CPoint point)
    {

    CRect rect1;

    m_FrameArea.GetClientRect(&rect1); //control rectangle

    m_FrameArea.ClientToScreen(&rect1)
    ScreenToClient(&rect1); //dialog coordinates`
    if (point.x >= rect1.left && point.x <= rect1.right && point.y >= rect1.top &&
    point.y <= rect1.bottom) {
    char str[100];
    sprintf(str, "%d-%d", point.x - rect1.left, point.y - rect1.top);

    }
    CDialogEx::OnMouseMove(nFlags, point);
    }





    share|improve this answer






























      1














      After some research, I came to this code which let me know if the mouse cursor is over my control in a dialog box.



      //Handling mouse move in mfc dialog

      void CDialogRoll::OnMouseMove(UINT nFlags, CPoint point)
      {

      CRect rect1;

      m_FrameArea.GetClientRect(&rect1); //control rectangle

      m_FrameArea.ClientToScreen(&rect1)
      ScreenToClient(&rect1); //dialog coordinates`
      if (point.x >= rect1.left && point.x <= rect1.right && point.y >= rect1.top &&
      point.y <= rect1.bottom) {
      char str[100];
      sprintf(str, "%d-%d", point.x - rect1.left, point.y - rect1.top);

      }
      CDialogEx::OnMouseMove(nFlags, point);
      }





      share|improve this answer




























        1












        1








        1







        After some research, I came to this code which let me know if the mouse cursor is over my control in a dialog box.



        //Handling mouse move in mfc dialog

        void CDialogRoll::OnMouseMove(UINT nFlags, CPoint point)
        {

        CRect rect1;

        m_FrameArea.GetClientRect(&rect1); //control rectangle

        m_FrameArea.ClientToScreen(&rect1)
        ScreenToClient(&rect1); //dialog coordinates`
        if (point.x >= rect1.left && point.x <= rect1.right && point.y >= rect1.top &&
        point.y <= rect1.bottom) {
        char str[100];
        sprintf(str, "%d-%d", point.x - rect1.left, point.y - rect1.top);

        }
        CDialogEx::OnMouseMove(nFlags, point);
        }





        share|improve this answer















        After some research, I came to this code which let me know if the mouse cursor is over my control in a dialog box.



        //Handling mouse move in mfc dialog

        void CDialogRoll::OnMouseMove(UINT nFlags, CPoint point)
        {

        CRect rect1;

        m_FrameArea.GetClientRect(&rect1); //control rectangle

        m_FrameArea.ClientToScreen(&rect1)
        ScreenToClient(&rect1); //dialog coordinates`
        if (point.x >= rect1.left && point.x <= rect1.right && point.y >= rect1.top &&
        point.y <= rect1.bottom) {
        char str[100];
        sprintf(str, "%d-%d", point.x - rect1.left, point.y - rect1.top);

        }
        CDialogEx::OnMouseMove(nFlags, point);
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 7:27









        Ali Sheikhpour

        5,61611743




        5,61611743










        answered Jan 1 at 7:22









        RanRan

        111




        111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19926020%2ffind-the-control-which-mouse-is-over-in-mfc%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith