Re: Changing values in a list view column
- Posted by Derek Parnell <ddparnell at bigpond.com> Apr 26, 2002
- 412 views
----- Original Message ----- From: <euman at bellsouth.net> To: "EUforum" <EUforum at topica.com> Subject: Re: Changing values in a list view column > > Hello Jonas, > > The easier way would be to only code in API and use a typical listbox > and not the listview control at all. > by using > LBS_OWNERDRAWFIXED = 16, or > LBS_OWNERDRAWVARIABLE = 32, > > you would have total control over your listbox and because earlier versions > of windows dont have some of the great listview features you could code the > listbox to act anyway a listview could and also work on the old Win O/S's. > > There may be other ways to do what you want other than what I present but > this seemed easiest for me. > > the below code is in no way optimized for size or speed but should give a good > idea how this all fits together. This code only adds bitmaps to listboxs but with > very little change you could setup grids. > > if iMsg = WM_CREATE then > <snip...> > > hList = CreateWindow(WS_EX_CLIENTEDGE,"listbox",0,or_all({WS_CHILD,WS_TABSTOP,LBS_OW NERDRAWFIXED,LBS_HASSTRINGS}), > 230, 240, 290, 110, hwnd, ID_hList, hInst, 0) > > itemDC = c_func(xGetDC, {hList}) > hListmem = c_func(xCreateCompatibleDC,{itemDC}) > c_proc(xReleaseDC, {hList, itemDC}) > > junk = SendMessage(hList, WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), 0) > > -- you guess what Im doing here? > AddItem(hList, "Core Files (Interpreter and Include files)", dacheck) > AddItem(hList, "Documentation and Tutorials", checked) > AddItem(hList, "Demonstration source code", checked) > > junk = SendMessage(hList, LB_SETCURSEL, 0, 0) > > elsif iMsg = WM_DRAWITEM then > action = peek4u(lParam+12) > itemDC = peek4u(lParam+24) > > if action = ODA_DRAWENTIRE then > if peek4u(lParam+20) = hList then > > junk = SendMessage(hList, LB_GETITEMDATA, peek4u(lParam+8), 0) > hListbmp = c_func(xSelectObject,{hListmem, junk}) > > rect_left = peek4u(lParam+28) > rect_top = peek4u(lParam+32) > rect_right = peek4u(lParam+36) > rect_bottom= peek4u(lParam+40) > > junk = c_func(xBitBlt,{itemDC, 1, rect_top, 15,rect_top+16, hListmem, 0, 0, SRCCOPY}) > > if SendMessage(hList, LB_GETSEL, peek4u(lParam+8), 0) then > poke4(lParam+28, rect_left + 20) > c_proc(xDrawFocusRect,{itemDC, lParam+28}) > FillRect(itemDC,{rect_left+20, rect_top, rect_right, rect_bottom}, hbrush) > SetTextColor(itemDC, 16777215) > junk = c_func(xSetBkColor,{itemDC, 3670016}) > else > SetTextColor(itemDC, 3670016) > junk = c_func(xSetBkColor,{itemDC, 16777215}) > > end if > > txtbuff = allocate(256) > junk = SendMessage(hList, LB_GETTEXT, peek4u(lParam+8), txtbuff) > c_proc(xGetTextMetrics,{itemDC, txtmetrics}) > y = floor(rect_top + 8 - peek4u(txtmetrics) / 2) > c_proc(xTextOut,{itemDC,26,y,txtbuff,c_func(xlstrlen,{txtbuff})}) > free(txtbuff) > > end if > > elsif action = ODA_SELECT then > > junk = SendMessage(hList, LB_GETCURSEL, 0, 0) > > if desel then > rect_left = peek4u(lParam+28) > rect_top = peek4u(lParam+32) > rect_right = peek4u(lParam+36) > rect_bottom= peek4u(lParam+40) > > FillRect(itemDC,{rect_left+20, rect_top, rect_right, rect_bottom}, wbrush) > hListbmp = c_func(xSelectObject,{hListmem, uncheck}) > junk = c_func(xBitBlt,{itemDC, 1, rect_top, 15,rect_top+16, hListmem, 0, 0, SRCCOPY}) > > txtbuff = allocate(256) > junk = SendMessage(hList, LB_GETTEXT, peek4u(lParam+8), txtbuff) > c_proc(xGetTextMetrics,{itemDC, txtmetrics}) > y = floor(rect_top + 8 - peek4u(txtmetrics) / 2) > c_proc(xTextOut,{itemDC,26,y,txtbuff,c_func(xlstrlen,{txtbuff})}) > free(txtbuff) > > desel = 0 > else > rect_left = peek4u(lParam+28) > rect_top = peek4u(lParam+32) > rect_right = peek4u(lParam+36) > rect_bottom= peek4u(lParam+40) > > FillRect(itemDC,{rect_left+20, rect_top, rect_right, rect_bottom}, hbrush) > hListbmp = c_func(xSelectObject,{hListmem, uncheck}) > junk = c_func(xBitBlt,{itemDC, 1, rect_top, 15,rect_top+16, hListmem, 0, 0, SRCCOPY}) > > txtbuff = allocate(256) > junk = SendMessage(hList, LB_GETTEXT, peek4u(lParam+8), txtbuff) > c_proc(xGetTextMetrics,{itemDC, txtmetrics}) > y = floor(rect_top + 8 - peek4u(txtmetrics) / 2) > SetTextColor(itemDC, 16777215) > junk = c_func(xSetBkColor,{itemDC, 3670016}) > c_proc(xTextOut,{itemDC,26,y,txtbuff,c_func(xlstrlen,{txtbuff})}) > free(txtbuff) > > desel = 1 > end if > end if > > elsif iMsg = WM_MEASUREITEM then > if peek4u(lParam) = ODT_LISTBOX then > if peek4u(lParam+4) = ID_hList then > junk = SendMessage(hList, LB_SETITEMHEIGHT, 0, 16) > end if > end if > > > Maybe helpfull to someone. > Euman > Gee, Euman! That does look easy. Why would anyone use win32lib if one could do it this easily.