Author | Message | Time |
---|---|---|
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. | August 5, 2003, 5:16 AM |
Skywing | [quote author=Maddox link=board=5;threadid=2211;start=0#msg17074 date=1060060617] 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. [/quote] 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. | August 5, 2003, 6:38 AM |
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? | August 5, 2003, 6:06 PM |
Skywing | [quote author=DarkMinion link=board=5;threadid=2211;start=0#msg17112 date=1060106814] 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? [/quote] 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). | August 5, 2003, 6:17 PM |
DarkMinion | Ah, I knew I wasn't crazy! | August 5, 2003, 6:59 PM |
Maddox | [quote author=Skywing link=board=5;threadid=2211;start=0#msg17078 date=1060065489] [quote author=Maddox link=board=5;threadid=2211;start=0#msg17074 date=1060060617] 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. [/quote] 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. [/quote] I've already tried this and it draws the rect only when the cursor is over an item. | August 5, 2003, 9:51 PM |
Adron | Maybe you have some kind of modern listbox? Normally focus will stay on an item you've clicked | August 6, 2003, 12:21 PM |
Skywing | [quote author=Adron link=board=5;threadid=2211;start=0#msg17194 date=1060172465] Maybe you have some kind of modern listbox? Normally focus will stay on an item you've clicked [/quote] To my knowledge there's no built in way to do that with class "LISTBOX". Here's what I use: [code] 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); [/code] 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. | August 6, 2003, 6:12 PM |