| 发表于:2007-04-21 19:33:283楼 得分:20 |
在vb里面如何得到外部程序的listbox内容 以下代码掩饰在得知两个listbox句柄时,把其中一个里面的内容复制到另外一个里面 duplicatelistbox参数解释: sourcehwnd=源listbox句柄(hwnd) targethwnd=目标listbox句柄(hwnd) appendmode=是否对源listbox的content进行校验,true就可以了 ======================================================================== private declare function sendmessage lib "user32 " alias "sendmessagea " (byval _ hwnd as long, byval wmsg as long, byval wparam as long, _ lparam as any) as long private declare function lockwindowupdate lib "user32 " (byval hwndlock as long) _ as long const lb_resetcontent = &h184 const lb_getcount = &h18b const lb_gettext = &h189 const lb_addstring = &h180 const lb_getitemdata = &h199 const lb_setitemdata = &h19a sub duplicatelistbox(sourcehwnd as long, targethwnd as long, _ optional appendmode as boolean) dim index as long dim itmdata as long dim numitems as long dim sitemtext as string ' prepare the receiving buffer sitemtext = space$(512) ' temporarily prevent updating lockwindowupdate targethwnd ' reset target contents, if not in append mode if not appendmode then sendmessage targethwnd, lb_resetcontent, 0, byval 0& end if ' get the number of items in the source list numitems = sendmessage(sourcehwnd, lb_getcount, 0&, byval 0&) for index = 0 to numitems - 1 ' get the item text sendmessage sourcehwnd, lb_gettext, index, byval sitemtext ' get the item data itmdata = sendmessage(sourcehwnd, lb_getitemdata, index, byval 0&) ' add the item text to the target list sendmessage targethwnd, lb_addstring, 0&, byval sitemtext ' add the item data to the target list sendmessage targethwnd, lb_setitemdata, index, byval itmdata next ' allow redrawing lockwindowupdate 0 end sub 调用 duplicatelistbox sourcehwnd, targethwnd, true | | |
|