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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Clicking a windowless button programatically

Clicking a windowless button programatically

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
8 Posts 4 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.
  • G Offline
    G Offline
    Green Fuze
    wrote on last edited by
    #1

    Hey everybody I have a YES/NO dialog, which the buttons are windowless controls. I want to click YES or NO buttons programmaticly. Does does anyone have any idea how to do that? btw, I don't mean sending VK_RETURN message... Thanks a lot in advance! p.s. If you want to see what I mean, open a "print" dialog in your office and use spy++ to check out the controls. You'll notice most controls don't have HWND. Thanks again! :-)

    M _ 2 Replies Last reply
    0
    • G Green Fuze

      Hey everybody I have a YES/NO dialog, which the buttons are windowless controls. I want to click YES or NO buttons programmaticly. Does does anyone have any idea how to do that? btw, I don't mean sending VK_RETURN message... Thanks a lot in advance! p.s. If you want to see what I mean, open a "print" dialog in your office and use spy++ to check out the controls. You'll notice most controls don't have HWND. Thanks again! :-)

      M Offline
      M Offline
      Member 3219104
      wrote on last edited by
      #2

      Hello, Use SendMessage() Win32 API. This will solve your problem. Happy Programming.

      1 Reply Last reply
      0
      • G Green Fuze

        Hey everybody I have a YES/NO dialog, which the buttons are windowless controls. I want to click YES or NO buttons programmaticly. Does does anyone have any idea how to do that? btw, I don't mean sending VK_RETURN message... Thanks a lot in advance! p.s. If you want to see what I mean, open a "print" dialog in your office and use spy++ to check out the controls. You'll notice most controls don't have HWND. Thanks again! :-)

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        When you spy on a button, for instance the Print button on a print dialog, you will see a field called Window Handle. This will have a value. But when doing it programmatically, we usually use the Control ID field. Here is what you can do to send a click on a button -

        PostMessage(WM_COMMAND, MAKELONG(ID_BUTTON, BN_CLICKED), reinterpret_cast<LPARAM>(GetDlgItem(ID_BUTTON)->m_hWnd));

        I'm assuming ID_BUTTON to be the button id. Replace that with the actual ID of the button. I'm assuming you're using MFC.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        G 1 Reply Last reply
        0
        • _ _Superman_

          When you spy on a button, for instance the Print button on a print dialog, you will see a field called Window Handle. This will have a value. But when doing it programmatically, we usually use the Control ID field. Here is what you can do to send a click on a button -

          PostMessage(WM_COMMAND, MAKELONG(ID_BUTTON, BN_CLICKED), reinterpret_cast<LPARAM>(GetDlgItem(ID_BUTTON)->m_hWnd));

          I'm assuming ID_BUTTON to be the button id. Replace that with the actual ID of the button. I'm assuming you're using MFC.

          «_Superman_» I love work. It gives me something to do between weekends.
          Microsoft MVP (Visual C++)

          G Offline
          G Offline
          Green Fuze
          wrote on last edited by
          #4

          Hey, Thanks for you help! :-) But the thing is that the control DOES NOT have a dialog item ID. If it had a dialog item ID, than it would have an HWND (which I could get using GetDlgItem()). About the Spy, if you use Spy++ on the print dialog in office, you will see that the buttons (or the combobox) will not have an HWND at all (only the RichEditBoxes have HWNDs in that dialog).

          _ 1 Reply Last reply
          0
          • G Green Fuze

            Hey, Thanks for you help! :-) But the thing is that the control DOES NOT have a dialog item ID. If it had a dialog item ID, than it would have an HWND (which I could get using GetDlgItem()). About the Spy, if you use Spy++ on the print dialog in office, you will see that the buttons (or the combobox) will not have an HWND at all (only the RichEditBoxes have HWNDs in that dialog).

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            Try if IDOK works for the OK button.

            «_Superman_» I love work. It gives me something to do between weekends.
            Microsoft MVP (Visual C++)

            G 1 Reply Last reply
            0
            • _ _Superman_

              Try if IDOK works for the OK button.

              «_Superman_» I love work. It gives me something to do between weekends.
              Microsoft MVP (Visual C++)

              G Offline
              G Offline
              Green Fuze
              wrote on last edited by
              #6

              Doesn't work... I'll try to expand the problem even a little bit more, what if I want to know what is written inside the button, or the combobox (in the print dialog). I am not sure it is even possible...

              K 1 Reply Last reply
              0
              • G Green Fuze

                Doesn't work... I'll try to expand the problem even a little bit more, what if I want to know what is written inside the button, or the combobox (in the print dialog). I am not sure it is even possible...

                K Offline
                K Offline
                Keith Worden
                wrote on last edited by
                #7

                You can't do this. "Windowless" means it's not a windows control so it doesn't have a window handle so you can't use APIs to interact with it. It's been created by code within the application to look and function as a button but it's not a Windows button.

                G 1 Reply Last reply
                0
                • K Keith Worden

                  You can't do this. "Windowless" means it's not a windows control so it doesn't have a window handle so you can't use APIs to interact with it. It's been created by code within the application to look and function as a button but it's not a Windows button.

                  G Offline
                  G Offline
                  Green Fuze
                  wrote on last edited by
                  #8

                  Hey, Thanks ! Yeah, I knew all that, but I was hoping someone will come up with a technique I didn't think of. :) Currently I am using the x,y of the window OR using spy++ to see if there is another message being sent because of my click (some kind of WM_COMMAND or WM_USER+k). Anyway, thanks again.

                  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