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. list box

list box

Scheduled Pinned Locked Moved C / C++ / MFC
help
13 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.
  • A Offline
    A Offline
    AbhiHcl
    wrote on last edited by
    #1

    I have created a list box using my own class derived from CListBox. I want to disapear it from the dialog if anyone is clicking outside that listbox. very similar to combobox. Please help me to do that.. It will be fine if provide some sample code. Thanks

    _ I 2 Replies Last reply
    0
    • A AbhiHcl

      I have created a list box using my own class derived from CListBox. I want to disapear it from the dialog if anyone is clicking outside that listbox. very similar to combobox. Please help me to do that.. It will be fine if provide some sample code. Thanks

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

      Create a handler for WM_KILLFOCUS inside you're class and call ShowWindow(SW_HIDE) on the listbox handle.

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      A 1 Reply Last reply
      0
      • _ _Superman_

        Create a handler for WM_KILLFOCUS inside you're class and call ShowWindow(SW_HIDE) on the listbox handle.

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        A Offline
        A Offline
        AbhiHcl
        wrote on last edited by
        #3

        That I hv done but its not closing. Actually I am trying to create a dropdown Control. For that I created a button control derived from CButton and on click of that button control I am creating a listbox derived from CListBox. I am able to show and hide on the button click, even I am able to show and hide on listbox onselchange(), but I am not able to hide when I am clicking anywhere on the dialogbox. is there any child and parent window problem ? Thanks.

        _ 1 Reply Last reply
        0
        • A AbhiHcl

          That I hv done but its not closing. Actually I am trying to create a dropdown Control. For that I created a button control derived from CButton and on click of that button control I am creating a listbox derived from CListBox. I am able to show and hide on the button click, even I am able to show and hide on listbox onselchange(), but I am not able to hide when I am clicking anywhere on the dialogbox. is there any child and parent window problem ? Thanks.

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

          I'm guessing you're not getting the kill focus event. That's probably because you're not setting focus to the list when shown.

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          A 1 Reply Last reply
          0
          • _ _Superman_

            I'm guessing you're not getting the kill focus event. That's probably because you're not setting focus to the list when shown.

            «_Superman_»
            I love work. It gives me something to do between weekends.

            Microsoft MVP (Visual C++)

            Polymorphism in C

            A Offline
            A Offline
            AbhiHcl
            wrote on last edited by
            #5

            Could you please tell me how and where to set the focus for the list box. Bcoz I m creatin List box on the click of button control.

            _ 1 Reply Last reply
            0
            • A AbhiHcl

              Could you please tell me how and where to set the focus for the list box. Bcoz I m creatin List box on the click of button control.

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

              You could try to call SetFocus after creating and showing the list box.

              «_Superman_»
              I love work. It gives me something to do between weekends.

              Microsoft MVP (Visual C++)

              Polymorphism in C

              A 1 Reply Last reply
              0
              • A AbhiHcl

                I have created a list box using my own class derived from CListBox. I want to disapear it from the dialog if anyone is clicking outside that listbox. very similar to combobox. Please help me to do that.. It will be fine if provide some sample code. Thanks

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                Have a look at my article: Generic Picker Dropdown Control[^] or the article I borrowed the original popup / killfocus idea from: Office 97 style Colour Picker control[^] Hopefully they will help you! Iain.

                I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                N 1 Reply Last reply
                0
                • _ _Superman_

                  You could try to call SetFocus after creating and showing the list box.

                  «_Superman_»
                  I love work. It gives me something to do between weekends.

                  Microsoft MVP (Visual C++)

                  Polymorphism in C

                  A Offline
                  A Offline
                  AbhiHcl
                  wrote on last edited by
                  #8

                  Hi I hv tried but its not working.. Here by I m sending my code , plz look into that.. // Here I am creating the button as well as ListBox. CTxDropDown is derived from CButton. void CTxDropDown::CreateDropDown(CRect rect, CWnd *pWnd, UINT nID) { this->Create(L"", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,rect, pWnd, nID); CRect m_rtBtn(rect); m_rtLst.left = m_rtBtn.left + 2 ; m_rtLst.top = m_rtBtn.top + 38 ; m_rtLst.right = m_rtBtn.right - 2 ; m_rtLst.bottom = m_rtBtn.bottom + 120 ; m_lstCtrl.CreateListBox(m_rtLst , pWnd , this , nID); m_lstCtrl.SetItemHeight(0, 25); m_lstCtrl.AddString(L" ENGLISH"); m_lstCtrl.AddString(L" JAPANIES"); m_lstCtrl.AddString(L" FRENCH"); m_lstCtrl.AddString(L" GERMAN"); m_lstCtrl.ShowWindow(SW_HIDE); } // On button click I m showing the and hiding the ListBox. m_lstCtrl is the object of my listbox class void CTxDropDown::OnBnClicked() { // TODO: Add your control notification handler code here. m_lstCtrl.SetFocus(); m_bShowListCtrl = !m_bShowListCtrl; m_lstCtrl.ShowWindow(m_bShowListCtrl ); Invalidate(); } // Here I am creating the ListBox.CTxListControl is derived froom CListBox. void CTxListControl::CreateListBox(CRect rect,CWnd *pWnd,CWnd *pDropDownWnd ,UINT nID) { this->Create(WS_VISIBLE |WS_CHILD|WS_VSCROLL|LBS_NOTIFY| LBS_HASSTRINGS | WS_TABSTOP ,rect , pWnd , nID); this->SetFocus(); m_pDropDownWnd = pDropDownWnd; m_rtLst = rect ; } // Calling the KillFocus on ClistBox void CTxListControl::OnLbnKillfocus() { // TODO: Add your control notification handler code here CListBox::ShowWindow(SW_HIDE); } Plz look the code.. and Gv some idea where I m worng..

                  1 Reply Last reply
                  0
                  • I Iain Clarke Warrior Programmer

                    Have a look at my article: Generic Picker Dropdown Control[^] or the article I borrowed the original popup / killfocus idea from: Office 97 style Colour Picker control[^] Hopefully they will help you! Iain.

                    I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                    N Offline
                    N Offline
                    Niklas L
                    wrote on last edited by
                    #9

                    Did the KillFocus path have any advantages over SetCapture/ReleaseCature? (And 10 extra points for why.) The capture way seems to be how comboboxes are implemented, since mouse clicks outside the dropped down list has no effect on other controls.

                    home

                    I 1 Reply Last reply
                    0
                    • N Niklas L

                      Did the KillFocus path have any advantages over SetCapture/ReleaseCature? (And 10 extra points for why.) The capture way seems to be how comboboxes are implemented, since mouse clicks outside the dropped down list has no effect on other controls.

                      home

                      I Offline
                      I Offline
                      Iain Clarke Warrior Programmer
                      wrote on last edited by
                      #10

                      I might have to miss the extra points, I'm afraid - I mostly just took Chris' idea and went with it. In the end, pretty much all the code was mine, I just took the idea. But SetCapture does have a disadvantage or two once you go from Win 3 to NT - it doesn't work across processes now - for good reason. KillFocus will work better if you click on another application. Your point about not doing anything when you're just clicking away from the dropdown bit of a combox box is a good one, I have to say. I hadn't really noticed it before. I press escape, or click on the already selected item if I want to get rid of it. In the app I used the Generic Dropdown's in had a decent about of safe clickable space, so it wasn't an issue. Did I get the cookie? Iain.

                      I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                      A N 2 Replies Last reply
                      0
                      • I Iain Clarke Warrior Programmer

                        I might have to miss the extra points, I'm afraid - I mostly just took Chris' idea and went with it. In the end, pretty much all the code was mine, I just took the idea. But SetCapture does have a disadvantage or two once you go from Win 3 to NT - it doesn't work across processes now - for good reason. KillFocus will work better if you click on another application. Your point about not doing anything when you're just clicking away from the dropdown bit of a combox box is a good one, I have to say. I hadn't really noticed it before. I press escape, or click on the already selected item if I want to get rid of it. In the app I used the Generic Dropdown's in had a decent about of safe clickable space, so it wasn't an issue. Did I get the cookie? Iain.

                        I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                        A Offline
                        A Offline
                        AbhiHcl
                        wrote on last edited by
                        #11

                        Can u guys please help, how to do that..

                        I 1 Reply Last reply
                        0
                        • I Iain Clarke Warrior Programmer

                          I might have to miss the extra points, I'm afraid - I mostly just took Chris' idea and went with it. In the end, pretty much all the code was mine, I just took the idea. But SetCapture does have a disadvantage or two once you go from Win 3 to NT - it doesn't work across processes now - for good reason. KillFocus will work better if you click on another application. Your point about not doing anything when you're just clicking away from the dropdown bit of a combox box is a good one, I have to say. I hadn't really noticed it before. I press escape, or click on the already selected item if I want to get rid of it. In the app I used the Generic Dropdown's in had a decent about of safe clickable space, so it wasn't an issue. Did I get the cookie? Iain.

                          I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                          N Offline
                          N Offline
                          Niklas L
                          wrote on last edited by
                          #12

                          Iain Clarke, Warrior Programmer wrote:

                          disadvantage or two once you go from Win 3 to NT

                          Well, lucky for me, I'm not planning on upgrading anytime soon. :omg: Maybe the actual combobox implementation is a combination of WM_KILLFOCUS and Set/Release capture. ...and this[^] is for you.

                          home

                          1 Reply Last reply
                          0
                          • A AbhiHcl

                            Can u guys please help, how to do that..

                            I Offline
                            I Offline
                            Iain Clarke Warrior Programmer
                            wrote on last edited by
                            #13

                            Have a look at my original reply: http://www.codeproject.com/Messages/3528108/Re-list-box.aspx[^] I gave you links to two good articles that should help you. It will take you a little while to read them, look at the code, try moving some of the code to your own program... Good luck, Iain.

                            I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                            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