• Welcome to Valhalla Legends Archive.
 

Drawing a focus rect for an owner-drawn listbox

Started by Maddox, August 05, 2003, 12:16 AM

Previous topic - Next topic

Maddox

I'm trying to draw a focus rect when a user clicks an item in my owner-drawn listbox. So far I've only been able to draw one when a user mouses over an item. I tried processing the ODA_FOCUS and ODA_SELECT messages to no avail. I also tried using DefWindowProc() following the advice of DM, but this did not work either. Any help would be appreciated.
asdf.

Skywing

#1
Quote from: Maddox on August 05, 2003, 12:16 AM
I'm trying to draw a focus rect when a user clicks an item in my owner-drawn listbox. So far I've only been able to draw one when a user mouses over an item. I tried processing the ODA_FOCUS and ODA_SELECT messages to no avail. I also tried using DefWindowProc() following the advice of DM, but this did not work either. Any help would be appreciated.
The best way to handle this is to simply check the item state for the item being currently drawn in WM_DRAWITEM and draw a focus rect there if necessary.

Edit: Use WM_DRAWITEM and not WM_PAINT.

DarkMinion

Sky, I'm curious as to how that works, because in MSDN documentation, it says that both wParam and lParam are unused in WM_PAINT.

I guess the documentation is wrong?

Skywing

Quote from: DarkMinion on August 05, 2003, 01:06 PM
Sky, I'm curious as to how that works, because in MSDN documentation, it says that both wParam and lParam are unused in WM_PAINT.

I guess the documentation is wrong?
No, that should have been WM_DRAWITEM and not WM_PAINT.  Sorry (although you could still use the item-from-point stuff with WM_PAINT).

DarkMinion


Maddox

#5
Quote from: Skywing on August 05, 2003, 01:38 AM
Quote from: Maddox on August 05, 2003, 12:16 AM
I'm trying to draw a focus rect when a user clicks an item in my owner-drawn listbox. So far I've only been able to draw one when a user mouses over an item. I tried processing the ODA_FOCUS and ODA_SELECT messages to no avail. I also tried using DefWindowProc() following the advice of DM, but this did not work either. Any help would be appreciated.
The best way to handle this is to simply check the item state for the item being currently drawn in WM_DRAWITEM and draw a focus rect there if necessary.

Edit: Use WM_DRAWITEM and not WM_PAINT.

I've already tried this and it draws the rect only when the cursor is over an item.
asdf.

Adron

Maybe you have some kind of modern listbox? Normally focus will stay on an item you've clicked

Skywing

#7
Quote from: Adron on August 06, 2003, 07:21 AM
Maybe you have some kind of modern listbox? Normally focus will stay on an item you've clicked
To my knowledge there's no built in way to do that with class "LISTBOX".

Here's what I use:

   if(DrawStruct.itemState & ODS_SELECTED) {
      FillRect(DrawStruct.hDC, &DrawStruct.rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
      TextColor = RGB(0xff, 0xff, 0xff);
   }

   if(DrawStruct.itemState & ODS_FOCUS && GetFocus() == DrawStruct.hwndItem)
      DrawFocusRect(DrawStruct.hDC, &DrawStruct.rcItem);

Note that this only draws the focus rect when your program has focus.  If you activate a window not in the tree which the ListBox is a member of, the focus rect will disappear.