Thread: problem with sending BN_CLICK messages

  1. #1
    Registered User
    Join Date
    Aug 2004

    problem with sending BN_CLICK messages

    I've made a program that can send BN_CLICK messages to buttons from other programs using SendMessageTimeout(), and it works fine for buttons that are obviously standard Windows buttons. But there are some windows in programs I've been trying to use that function as buttons, but don't do anything in response to being sent a BN_CLICK message. Is there maybe a more general way of simulating a click on a window that would work even if it's not a standard Windows button control? I'd really like something that doesn't depend on the screen coordinates of the window, so it could be done without the window being displayed on the screen at the time.

  2. #2
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Use FindWindow, FindChildWindow, EnumWindow, or EnumChildWindow to get the handle of the button.

    Then use SendMessage or PostMessage with the handle to the button and BN_CLICK as arguments.

    Something like this:

    SendMessage(Button_Handle, BN_CLICK, 0, 0);

    If it doesn't work using SendMessage try PostMessage.

    Also use Spy++ to make sure you have the correct handle for the button.

    I am sure there is a better way, but this has worked for me.

    Hope this helps.
    Last edited by CartoonLarry; 08-10-2004 at 11:40 PM.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    To simulate a mouse click, send WM_LBUTTONDOWN followed by WM_LBUTTONUP.


  4. #4
    Registered User
    Join Date
    Aug 2004
    Thanks very much, the WM_LBUTTONDOWN and WM_LBUTTONUP worked perfectly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Missing first few multicast messages in udp.
    By lovecoding in forum C Programming
    Replies: 3
    Last Post: 03-04-2009, 03:53 PM
  2. Client/server problem; server either stops receiving data or client stops sending
    By robot-ic in forum Networking/Device Communication
    Replies: 10
    Last Post: 02-16-2009, 11:45 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. Sending problem, or 1 = smiley face
    By Asmodeus in forum Tech Board
    Replies: 1
    Last Post: 04-25-2005, 11:01 AM
  5. WIN32 Problem!
    By jdude in forum Windows Programming
    Replies: 2
    Last Post: 03-09-2005, 01:03 AM