Unselecting a selected button in C++Builder 5

This is a discussion on Unselecting a selected button in C++Builder 5 within the Windows Programming forums, part of the Platform Specific Boards category; Is there a way to deselect a button after it has been clicked? I am working on a simple calculator ...

  1. #1
    Frozen_solid
    Guest

    Unselecting a selected button in C++Builder 5

    Is there a way to deselect a button after it has been clicked? I am working on a simple calculator for my programming class and found that if I use the mouse to click a button, and try to use enter on the keyboard, it calls the onclick event for that button instead of running onkeydown and then using the if (Key == VK_RETURN) that I have inside of the onkeydown function.

    Is there a way to deselect the button so that I can use the form's onkeydown? I set all the tabstops to false so nothing is selected when the program is run the first time, but I can't find a way to deselect the button after someone clicked it with the mouse so that I can use the form's onkeydown again.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, I use Borland C++ 5, never tried Builder, but this should work for any control or window:

    Trap the WM_SETFOCUS message (which is sent to any window as it gains focus) and, in the handler, make whatever window you want to have the focus, gain the focus.

    I use this sometimes when I have a window I can't hide or disable, but don't want to gain focus; for example, I use this in a window whose only function is to play MIDI files, and respond to the callback messages.

    I have the following handler for WM_SETFOCUS:

    void MidiWindow::EvSetFocus(THandle){ // Make sure we DON'T receive the focus, because we don't want it.
    Parent->SetFocus();
    }

    In this case, the focus is sent to the parent of my MidiWindow. You can also use the handle that is passed with the WM_SETFOCUS message to redirect the focus to the window that just lost focus.
    Last edited by The V.; 09-25-2001 at 01:44 PM.

  3. #3
    Frozen_Solid
    Guest

    that doesn't work

    All that does is focuses on the window, not deselect a single button. I have been told to try that several times and it doesn't deselect a button.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Hmm... odd.

    Have you tried including the SetFocus() command in the handler which handles the button press? I've sucessfully used a button along with a Tree Window to do exactly that -- the button would normally gain focus after being clicked, but then when it was clicked, it used SetFocus() to set the tree window as having focus (both of these were controls in the same window, BTW, which I'm assuming is your case as well).

    I'm not sure, but it's possible this isn't working because the target window of the SetFocus() has the button as a control within it -- I am 100% sure you can pass control from one control in a window to another, though, with this method, because I use it all the time.

  5. #5
    Frozen_Solid
    Guest
    yes, the set focus works between windows, but the button is on a window that is already focused on, I want to just entirely unselect the button so that it is as if I just ran the program and nothing is selected. The closest thing I can get to work is setting the focus to the = button, but then there is still the annoying dashed box around the = key. I can deselect one button only by selecting another, which I don't want to do. There has to be a way to make it so the button isn't selected at all or to just unselect it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. THE END - Borland C++ Builder, Delphi, J Builder?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-28-2006, 10:23 PM
  3. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  4. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM
  5. Unselecting a radio button
    By canine in forum Windows Programming
    Replies: 1
    Last Post: 11-27-2001, 05:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21