ListBox is cropped by other controls

Hi,
I am writing a straight win32 api app. I have a GUI with several controls: EditBox; Button; and a ListBox I show when the user enters appropriate text in the EditBox. When I show the ListBox, parts of it are covered by some other controls. I can't find a way to show the ListBox in full. I have tried using these api's:

1
2
bool result = BringWindowToTop(m_hAddressList);
result = SetForegroundWindow(m_hAddressList);


But neither call made the ListBox fully visible.

Does anyone know how I can assure that the ListBox is visible on top of all other controls?

Thank you,
Rakefet
IF you haven't gotten an HWND handle to your listbox then the above code won't work. Rather, you should do this --

1
2
bool result = BringWindowToTop(GetDlgItem(hwnd,m_hAddressList));
result = SetForegroundWindow(GetDlgItem(hwnd,m_hAddressList));


Or you could just declare a handle to your listbox like this --

1
2
HWND hListWnd = GetDlgItem(hwnd,hAddressList);
bool result = BringWindowToTop(hListWnd); etc.


If you have already gotten a handle to your listbox, you might try --

ShowWindow(hListWnd, SW_SHOWNORMAL);
Hi,

The h_addressList is a handle to my ListBox. This is how I create my listbox:

1
2
3
4
5
6
7
m_hAddressList = CreateWindow(L"LISTBOX", NULL, WS_CHILD | WS_BORDER | LBS_STANDARD | LBS_HASSTRINGS,
		rc.right/2 - 120, 27, 300, 120, m_hWnd, (HMENU) IDC_LIST_ADDRESS_LIST, NULL, NULL);

// This EditBox control is on top of the ListBox when the ListBox is displayed.
m_hSubject = CreateWindow(L"EDIT", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL,
		rc.right/2 - 120, 37, 400, 20, m_hWnd, (HMENU)IDC_EDIT_EMAIL_SUBJECT, NULL, NULL);
Edit_SetCueBannerTextFocused( m_hSubject, L"Enter a subject for your message", true );


When an edit is made into the EditBox control, I check to see if I should display the ListBox. If so, I want the entire ListBox displayed and none of it hidden by other controls. I do that as so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
HRESULT TB03PreviewSend::displayAddressList(void)
{
    HRESULT hr = S_OK;

    // add a bunch of entries to the ListBox

    // Show the ListBox if not empty	
    int count = SendMessage(m_hAddressList, LB_GETCOUNT, (WORD)0, 0L);
    if (count > 0)
    {
           ShowWindow(m_hAddressList, SW_SHOW);
           SendMessage(m_hAddressList, LB_SETSEL, TRUE, 0L);

           bool result = BringWindowToTop(m_hAddressList);
           result = SetForegroundWindow(m_hAddressList);
     }
     return hr;
}


I think I'm using the right ListBox window handle. If I'm doing something wrong, can you please point it out to me?

Thank you very much for all your help,
Rakefet
I'm working through another problem right now, so I can't really devote myself to yours, but just a quick observation... you might try HIDING the edit control while you display the listbox.
AFAIK, SetForegroundWindow() is for top-level windows only.

BringWindowToTop() should work OK. Your use, however, is incorrect if m_hAddressList is the list box's window handle. If it is the handle already, you do:

BringWindowToTop(m_hAddressList);

You only use GetDlgItem() when you have the control identifier only.
That's why I told him *IF* he hadn't already gotten a handle to the window, but you are right on SetForeGroundWindow().

Rafeket, have you tried making your hAddressList window static??? i.e.,

static HWND hAddressList;
Thanks very much Lamblion and webJose for responding. m_hAddressList is the window handle of the ListBox. I think I'm using it correctly by passing it to BringWindowToTop.

I tried making it static but the behavior was the same, i.e. The ListBox was not fully visible because it was cropped by other controls. Is there a way to include screenshots in this forum so I can show you my exact problem?

Right now I'm not sure what else to try.

Thank you,
Rakefet

p.s. I'm a "she."
Try this --

ShowWindow(m_hSubject,SW_HIDE);
Last edited on
Yes, both of these work (I was using the disable EditBox one).

1
2
3
4
5
ShowWindow(m_hSubject,SW_HIDE);

or

Edit_Enable(m_hSubject,FALSE);


But I can't use this. It looks really ugly for one, and I have additional controls below the Subject EditBox that I can't hide.

Thank you very much for your help,
Rakefet
Oh, from debugging I see that the Subject EditBox handler gets a WM_PAINT message after the ListBox is shown. I need to prevent that WM_PAINT from going to the Subject EditBox (and other controls) or somehow ignore them in the other control' process handlers.

Do you know why the other controls are getting WM_PAINT messages after the ListBox is displayed? Is there anything I can do about that?

Thank you,
Rakefet
I'm not too good with WM_PAINT (I almost never use it), but you might try to reverse the order in which you create your windows, i.e., create your listbox AFTER you create the edit box.

If that works, then you can manipulate the zorder by using SetWindowPos(). In fact, you might want to use SetWindowPos() anyway, instead of ShowWindow(), as SetWindowPos has a great deal more flexibility.

Even if reversing the order of creation doesn't work, look into SetWindowPos() and see if you can find a flag in there that works. That is how I almost always solve my window/control problems.

http://msdn.microsoft.com/en-us/library/ms633545(v=VS.85).aspx
Topic archived. No new replies allowed.