| 发表于:2007-12-11 13:00:50 楼主 |
以下代码解决如题的问题,不过不知道为什么总是捕捉不到wm_drawitem消息,还望高人不吝赐教!! option explicit '以下在module1 public type rect left as long top as long right as long bottom as long end type public type drawitemstruct ctltype as long ctlid as long itemid as long itemaction as long itemstate as long hwnditem as long hdc as long rcitem as rect itemdata as long end type public declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination as any, source as any, byval length as long) public declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long public declare function callwindowproc lib "user32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as long public declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long public declare function createsolidbrush lib "gdi32" (byval crcolor as long) as long public declare function deleteobject lib "gdi32" (byval hobject as long) as long public declare function setbkcolor lib "gdi32" (byval hdc as long, byval crcolor as long) as long public declare function settextcolor lib "gdi32" (byval hdc as long, byval crcolor as long) as long public declare function textout lib "gdi32" alias "textouta" (byval hdc as long, byval x as long, byval y as long, byval lpstring as string, byval ncount as long) as long public declare function drawfocusrect lib "user32" (byval hdc as long, lprect as rect) as long public declare function getsyscolor lib "user32" (byval nindex as long) as long public declare function fillrect lib "user32" (byval hdc as long, lprect as rect, byval hbrush as long) as long public const color_highlight = 13 public const color_highlighttext = 14 public const color_window = 5 public const color_windowtext = 8 public const lb_gettext = &h189 public const wm_drawitem = &h2b public const gwl_wndproc = (-4) public const ods_focus = &h10 public const odt_listbox = 2 public lprevwndproc as long public function subclassedlist(byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as long dim titem as drawitemstruct dim sbuff as string * 255 dim sitem as string dim hbrush as long if msg = wm_drawitem then copymemory titem, byval lparam, len(titem) if titem.ctltype = odt_listbox then sendmessage titem.hwnditem, lb_gettext, titem.itemid, byval sbuff sitem = left(sbuff, instr(sbuff, chr(0) - 1)) if (titem.itemstate and ods_focus) then hbrush = createsolidbrush(getsyscolor(color_highlight)) fillrect titem.hdc, titem.rcitem, hbrush setbkcolor titem.hdc, getsyscolor(color_highlight) settextcolor titem.hdc, getsyscolor(color_highlighttext) textout titem.hdc, titem.rcitem.left, titem.rcitem.top, byval sitem, len(sitem) drawfocusrect titem.hdc, titem.rcitem else hbrush = createsolidbrush(getsyscolor(color_window)) fillrect titem.hdc, titem.rcitem, hbrush setbkcolor titem.hdc, getsyscolor(color_window) settextcolor titem.hdc, titem.itemdata textout titem.hdc, titem.rcitem.left, titem.rcitem.top, byval sitem, len(sitem) end if deleteobject hbrush subclassedlist = 0 exit function end if end if subclassedlist = callwindowproc(lprevwndproc, hwnd, msg, wparam, lparam) end function option explicit '以下在form1(需要一个listbox) private sub form_load() dim i as integer for i = 0 to 15 list1.additem "color" & i list1.itemdata(list1.newindex) = qbcolor(i) next i lprevwndproc = setwindowlong(list1.hwnd, gwl_wndproc, addressof subclassedlist) end sub private sub form_unload(cancel as integer) setwindowlong list1.hwnd, gwl_wndproc, lprevwndproc end sub |
|
|
|
|