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. How do you remove focus from a listbox manually?

How do you remove focus from a listbox manually?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 4 Posters 1 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello, This is my problem: I have a list box which is used to select a certain item via double-click. This item can then be placed on a map. The problem is, while placing the item, the mousewheel has functionality within the program other than scrolling the list box. I need this mousewheel functionality to work, but once the item in the list box is selected, the focus stays on the list box and the mousewheel will only scroll the list and not do what I want it to do within the main program window. If I could just move the focus from the list box to some other button, or remove it entirely, (without actually clicking on another list or button) the problem should be solved. I have tried: SendMessage(list_box,LBN_KILLFOCUS,0,0); SendMessage(list_box,WM_KILLFOCUS,0,0); where list_box is the handle of my list box, but, both of those KILLFOCUS messages are returns rather than messages that can be sent to the handle and processed. I just need some way to get the focus off of the darned list box... Thanks for your help, Kelly

    I G D 3 Replies Last reply
    0
    • L Lost User

      Hello, This is my problem: I have a list box which is used to select a certain item via double-click. This item can then be placed on a map. The problem is, while placing the item, the mousewheel has functionality within the program other than scrolling the list box. I need this mousewheel functionality to work, but once the item in the list box is selected, the focus stays on the list box and the mousewheel will only scroll the list and not do what I want it to do within the main program window. If I could just move the focus from the list box to some other button, or remove it entirely, (without actually clicking on another list or button) the problem should be solved. I have tried: SendMessage(list_box,LBN_KILLFOCUS,0,0); SendMessage(list_box,WM_KILLFOCUS,0,0); where list_box is the handle of my list box, but, both of those KILLFOCUS messages are returns rather than messages that can be sent to the handle and processed. I just need some way to get the focus off of the darned list box... Thanks for your help, Kelly

      I Offline
      I Offline
      includeh10
      wrote on last edited by
      #2

      i was in your case before. i did lots test, result is: no way to do that. my solution is: create a Static control (Static has no focus on), then draw strings on the control - it is quite hard because you need to draw scroll-bar also. when user click the static control, you know which string is selected, then do something according to the string. but, maybe someone knows easy solution, i hope see it via your post. includeh10

      1 Reply Last reply
      0
      • L Lost User

        Hello, This is my problem: I have a list box which is used to select a certain item via double-click. This item can then be placed on a map. The problem is, while placing the item, the mousewheel has functionality within the program other than scrolling the list box. I need this mousewheel functionality to work, but once the item in the list box is selected, the focus stays on the list box and the mousewheel will only scroll the list and not do what I want it to do within the main program window. If I could just move the focus from the list box to some other button, or remove it entirely, (without actually clicking on another list or button) the problem should be solved. I have tried: SendMessage(list_box,LBN_KILLFOCUS,0,0); SendMessage(list_box,WM_KILLFOCUS,0,0); where list_box is the handle of my list box, but, both of those KILLFOCUS messages are returns rather than messages that can be sent to the handle and processed. I just need some way to get the focus off of the darned list box... Thanks for your help, Kelly

        G Offline
        G Offline
        G Steudtel
        wrote on last edited by
        #3

        Hi, I once had a similiar problem within a tree control. My solution was to make a boolean variable (bDoubleClicked) which was initially set to false. When the user double clicked an item I just set this variable to true and remembered what he/she choosed. My actual action was taken on the mouse button up message. By looking if the user had double clicked I performed the task. In any case bDoubleClicked was set to false again. The problem was that the mouse action was bound to the tree control and not released until the button up message arrived to that control. I think you should use this method for your problem too. Hope this helps. Regards G. Steudtel

        L 1 Reply Last reply
        0
        • L Lost User

          Hello, This is my problem: I have a list box which is used to select a certain item via double-click. This item can then be placed on a map. The problem is, while placing the item, the mousewheel has functionality within the program other than scrolling the list box. I need this mousewheel functionality to work, but once the item in the list box is selected, the focus stays on the list box and the mousewheel will only scroll the list and not do what I want it to do within the main program window. If I could just move the focus from the list box to some other button, or remove it entirely, (without actually clicking on another list or button) the problem should be solved. I have tried: SendMessage(list_box,LBN_KILLFOCUS,0,0); SendMessage(list_box,WM_KILLFOCUS,0,0); where list_box is the handle of my list box, but, both of those KILLFOCUS messages are returns rather than messages that can be sent to the handle and processed. I just need some way to get the focus off of the darned list box... Thanks for your help, Kelly

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          After the item in the listbox has been double-clicked, why can't you just call SetFocus() to set the focus on the "map" control?


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          L 1 Reply Last reply
          0
          • G G Steudtel

            Hi, I once had a similiar problem within a tree control. My solution was to make a boolean variable (bDoubleClicked) which was initially set to false. When the user double clicked an item I just set this variable to true and remembered what he/she choosed. My actual action was taken on the mouse button up message. By looking if the user had double clicked I performed the task. In any case bDoubleClicked was set to false again. The problem was that the mouse action was bound to the tree control and not released until the button up message arrived to that control. I think you should use this method for your problem too. Hope this helps. Regards G. Steudtel

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thank you for the suggestion, but I think it probably won't work - the problem is, once the mouse clicks onto the list box, that's it, the focus is now on the list box. I need some way to remove the focus from the list box. Regardless of what variables I use to save position and such, once the mouse clicks even once on the list box, that's it, problem activated. I'd really rather not manually write a list box, I've done that in other portions of the code that involve larger bitmaps and such and it's a pain to always keep track of where they are in relation to the larger window etc, if I'm going to do that I'll just throw in an extra button instead that you're forced to click in order to place the selected items, but that's such a hassle for the user.. I can't imagine that there isn't some way to simply send a message to a window to change or remove focus.. it seems like such a basic function? Thanks for the suggestions though guys, hopefully there is some way to do this.. Kelly

            1 Reply Last reply
            0
            • D David Crow

              After the item in the listbox has been double-clicked, why can't you just call SetFocus() to set the focus on the "map" control?


              Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I didn't realize there was a SetFocus function - Thank you, that's exactly what I was asking, I just tried it and it works the way I want :)

              I 1 Reply Last reply
              0
              • L Lost User

                I didn't realize there was a SetFocus function - Thank you, that's exactly what I was asking, I just tried it and it works the way I want :)

                I Offline
                I Offline
                includeh10
                wrote on last edited by
                #7

                if you have scroll-bar in listbox, i don't think things are so simple, especially need to manage keyboad-input. visual c++ prompt window (appears if type dot after an object) is an example which doesn't use normal listbox. includeh10

                D 1 Reply Last reply
                0
                • I includeh10

                  if you have scroll-bar in listbox, i don't think things are so simple, especially need to manage keyboad-input. visual c++ prompt window (appears if type dot after an object) is an example which doesn't use normal listbox. includeh10

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  A scrollbar does not affect a listbox's ability to set/kill focus.


                  Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                  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