Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. sending click message to child button of a window.

sending click message to child button of a window.

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _T No name
    wrote on last edited by
    #1

    hi, i want to send a click message to a window button. i am able to enumerate the window and also find the handle of button as well but not able to send the click message. Actually the default focus is set on some another message if i send BM_CLICK message that call goes to other button not the one i am sending..... attached code is below

    CWnd\* pWnd = NULL;
    CWnd\* pWndBtn = NULL;
    DWORD dwErr = 0;
    while(true)
    {
         CWnd\* WindowHandle = NULL;
         CWnd\* ButtonHandle = NULL;
    
         WindowHandle = FindWindow(NULL, L"Microsoft Office Outlook");
    
         if(WindowHandle)
         {
             ButtonHandle = FindWindowEx(WindowHandle->GetSafeHwnd(), 0, L"Button", L"Allow");
    
         //send a message to the button that you are "clicking" it. Surprisingly C++ understands what BM\_CLICK is without having to set it. Different than VB
             if(ButtonHandle)
             {
                 CString strWnd ;
                 ButtonHandle->GetWindowText(strWnd);
                 WindowHandle->SetActiveWindow();
                 ButtonHandle->SendMessage(BM\_CLICK ,0,0);
             }
         }
    }
    

    plz help.. i tried even setting window active also but dint work

    N R 2 Replies Last reply
    0
    • _ _T No name

      hi, i want to send a click message to a window button. i am able to enumerate the window and also find the handle of button as well but not able to send the click message. Actually the default focus is set on some another message if i send BM_CLICK message that call goes to other button not the one i am sending..... attached code is below

      CWnd\* pWnd = NULL;
      CWnd\* pWndBtn = NULL;
      DWORD dwErr = 0;
      while(true)
      {
           CWnd\* WindowHandle = NULL;
           CWnd\* ButtonHandle = NULL;
      
           WindowHandle = FindWindow(NULL, L"Microsoft Office Outlook");
      
           if(WindowHandle)
           {
               ButtonHandle = FindWindowEx(WindowHandle->GetSafeHwnd(), 0, L"Button", L"Allow");
      
           //send a message to the button that you are "clicking" it. Surprisingly C++ understands what BM\_CLICK is without having to set it. Different than VB
               if(ButtonHandle)
               {
                   CString strWnd ;
                   ButtonHandle->GetWindowText(strWnd);
                   WindowHandle->SetActiveWindow();
                   ButtonHandle->SendMessage(BM\_CLICK ,0,0);
               }
           }
      }
      

      plz help.. i tried even setting window active also but dint work

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      Can't you associate a member variable to that button and then send the BM_Click to that particular button? Does this[^] help you?

      Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

      _ 1 Reply Last reply
      0
      • N Nelek

        Can't you associate a member variable to that button and then send the BM_Click to that particular button? Does this[^] help you?

        Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

        _ Offline
        _ Offline
        _T No name
        wrote on last edited by
        #3

        no event that dint help....

        1 Reply Last reply
        0
        • _ _T No name

          hi, i want to send a click message to a window button. i am able to enumerate the window and also find the handle of button as well but not able to send the click message. Actually the default focus is set on some another message if i send BM_CLICK message that call goes to other button not the one i am sending..... attached code is below

          CWnd\* pWnd = NULL;
          CWnd\* pWndBtn = NULL;
          DWORD dwErr = 0;
          while(true)
          {
               CWnd\* WindowHandle = NULL;
               CWnd\* ButtonHandle = NULL;
          
               WindowHandle = FindWindow(NULL, L"Microsoft Office Outlook");
          
               if(WindowHandle)
               {
                   ButtonHandle = FindWindowEx(WindowHandle->GetSafeHwnd(), 0, L"Button", L"Allow");
          
               //send a message to the button that you are "clicking" it. Surprisingly C++ understands what BM\_CLICK is without having to set it. Different than VB
                   if(ButtonHandle)
                   {
                       CString strWnd ;
                       ButtonHandle->GetWindowText(strWnd);
                       WindowHandle->SetActiveWindow();
                       ButtonHandle->SendMessage(BM\_CLICK ,0,0);
                   }
               }
          }
          

          plz help.. i tried even setting window active also but dint work

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          Typically its the parent window that handles the BN_CLICKED event for a child window. As you can find the actual window you want to send the BN_CLICKED event for, all you need to do is get the control ID number using the GetDlgCtrlID() function on the button window. You can then use PostMessage to the buttons parent window using: parentWindow->PostMessage(WM_COMMAND, MAKELONG(buttonId, BN_CLICKED), buttonHwnd) (I only had a quick and dirty look at the docs for this but I think it should work, you may have to sort out the parameters to make sure their correct)

          If you vote me down, my score will only get lower

          _ 1 Reply Last reply
          0
          • R Roger Allen

            Typically its the parent window that handles the BN_CLICKED event for a child window. As you can find the actual window you want to send the BN_CLICKED event for, all you need to do is get the control ID number using the GetDlgCtrlID() function on the button window. You can then use PostMessage to the buttons parent window using: parentWindow->PostMessage(WM_COMMAND, MAKELONG(buttonId, BN_CLICKED), buttonHwnd) (I only had a quick and dirty look at the docs for this but I think it should work, you may have to sort out the parameters to make sure their correct)

            If you vote me down, my score will only get lower

            _ Offline
            _ Offline
            _T No name
            wrote on last edited by
            #5

            i have tried this also... but this also does not work.. You know what happend if i click anywhere on my desktop or elsewhere than message starts going. i dont quiet understand whats happening.

            R _ 2 Replies Last reply
            0
            • _ _T No name

              i have tried this also... but this also does not work.. You know what happend if i click anywhere on my desktop or elsewhere than message starts going. i dont quiet understand whats happening.

              R Offline
              R Offline
              Roger Allen
              wrote on last edited by
              #6

              Have you tried SendMessage instead? Other than that I am not sure what to suggest. X|

              If you vote me down, my score will only get lower

              1 Reply Last reply
              0
              • _ _T No name

                i have tried this also... but this also does not work.. You know what happend if i click anywhere on my desktop or elsewhere than message starts going. i dont quiet understand whats happening.

                _ Offline
                _ Offline
                _T No name
                wrote on last edited by
                #7

                i have tried that also i am afraid that also does not work.. i tried SendInput() with MOUSE_EVENT just to simulate the click event than this message is going but sometimes what happens this SendMessage goes to the default button in the window. The button i want to send the message is not the default button. :(

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups