CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2011
    Posts
    12

    Need Listbox to not be cropped when displayed

    Hi,
    I have a GUI with several controls. One of them is a ListBox that is displayed occasionally. When it is displayed, it is cropped by it's siblings windows, which is an EditBox and a window that is a sibling of it's parent. I have attached snapshots of the screen before the ListBox is displayed and after it is displayed. When the ListBox is displayed, I want it displayed fully and not cropped at all.

    When displaying the list box, I tried calling "BringWindowToTop" to assure that the ListBox will be displayed fully, but it is not. Is there any other call I can make to force the ListBox to be displayed fully and not be cropped?

    Thank you,
    Rakefet
    Attached Images Attached Images   

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Need Listbox to not be cropped when displayed

    Try to use SetWindowPos with HWND_TOP as parameter.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Need Listbox to not be cropped when displayed

    AFAIK, BringWindowToTop has the same effect like SetWindowPos with HWND_TOP.

    Well, never know... a try is not a mistake.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Oct 2011
    Posts
    12

    Re: Need Listbox to not be cropped when displayed

    Yes, the SetWindowsPos function didn't help the problem.

    But from debugging I see that after I display the ListBox, the other controls are getting WM_PAINT messages and so they are re=painting over the ListBox. Is there any way I can prevent the other controls from getting these WM_PAINT messages?

    Thank you,
    Rakefet

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Need Listbox to not be cropped when displayed

    At last, everything is possible but "preventing the other controls from getting these WM_PAINT" is not a good practical solution.
    Consider the following alternatives:
    1. rearrange the controls in order to prevent overlapping, or
    2. put the listbox in a top-level frame, or
    3. replace the listbox with a combobox.

    I would like to suggest #3.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Need Listbox to not be cropped when displayed

    I forgot to mention the alternative #4: playing with WS_CLIPSIBLINGS style.
    It may work but IMO, #3 is still better.
    It seems that you have a combination of an edit control and an occasionally displayed listbox. This is exactly the behavior of a combobox.
    Once the dropdown list of a combobox is a top-level window, it does not need any other action from your side to make it visible over other controls.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  7. #7
    Join Date
    Oct 2011
    Posts
    12

    Re: Need Listbox to not be cropped when displayed

    Thank you very much for the suggestions. I originally used a ComboBox but I couldn't dynamically set the text in the EditBox part of the control. I have a previous post about that. When the user selected an item from the ComboBox, I wanted to then set the text to whatever I wanted. But the control set it to whatever was selected in the ComboBox. Interestingly, the ComboBox had no problem with being cropped. It was always displayed properly.

    Thanks,
    Rakefet

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Need Listbox to not be cropped when displayed

    Quote Originally Posted by rzdybel View Post
    Interestingly, the ComboBox had no problem with being cropped. It was always displayed properly.
    As I already said, the dropdown list of a combobox is a top-most top-level window. For that reason, it stays always on top.

    Quote Originally Posted by rzdybel View Post
    I originally used a ComboBox but I couldn't dynamically set the text in the EditBox part of the control. I have a previous post about that. When the user selected an item from the ComboBox, I wanted to then set the text to whatever I wanted. But the control set it to whatever was selected in the ComboBox.
    As an end user, I would be enough happy to have a standard combobox and not one with "special effects". This one may at least annoy me.
    Although, (almost) everything is possible and you can catch that dropdown list window, subclass it then probably, can do what your muscles want.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured