Как отключить возможность редактирования, например во 2 и 3 колонках, а в других оставить?
Код:
;{редактируемый LI 1\3 #CCM_SETVERSION = #CCM_FIRST+7 #NM_CUSTOMDRAW = #NM_FIRST-12 #CDDS_ITEM = $10000 #CDDS_SUBITEM = $20000 #CDDS_PREPAINT = $1 #CDDS_ITEMPREPAINT = #CDDS_ITEM|#CDDS_PREPAINT #CDDS_SUBITEMPREPAINT = #CDDS_SUBITEM|#CDDS_ITEMPREPAINT #CDRF_DODEFAULT = $0 #CDRF_NEWFONT = $2 #CDRF_NOTIFYITEMDRAW = $20 #CDRF_NOTIFYSUBITEMDRAW = $20 #LVM_SUBITEMHITTEST = #LVM_FIRST+57 #LVM_GETSUBITEMRECT = #LVM_FIRST+56 Global ListGadget, OldLViewProc, OldEditProc, hEdit, rct.RECT, CellSelectOn, CurItem, CurSubItem, CurSelItem, CurSelSubItem Procedure LoWord(value) ProcedureReturn value & $FFFF EndProcedure Procedure HiWord(value) ProcedureReturn value >> 16 & $FFFF EndProcedure Procedure KillFocus() If hEdit SetGadgetItemText(1, CurItem, GetGadgetText(2), CurSubItem);<<< FreeGadget(2) hEdit = 0 EndIf EndProcedure Procedure DrawRectangle(hwnd, *rc.RECT) hDC = GetDC_(hwnd) OldPen = SelectObject_(hDC, GetStockObject_(#BLACK_PEN)) OldBrush = SelectObject_(hDC, GetStockObject_(#NULL_BRUSH)) Rectangle_(hDC, *rc\left, *rc\top, *rc\right, *rc\bottom) SelectObject_(hDC, OldBrush) SelectObject_(hDC, OldPen) ReleaseDC_(hwnd, hDC) EndProcedure Procedure EditProc(hwnd, uMsg, wParam, lParam) result = 0 Select uMsg Case #WM_KEYDOWN result = CallWindowProc_(OldEditProc, hwnd, uMsg, wParam, lParam) If wParam=#VK_RETURN KillFocus() EndIf Default result = CallWindowProc_(OldEditProc, hwnd, uMsg, wParam, lParam) EndSelect ProcedureReturn result EndProcedure Procedure LViewProc(hwnd, uMsg, wParam, lParam);цвет result = 0 Select uMsg Case #WM_LBUTTONDBLCLK If hwnd<>hEdit KillFocus() pInfo.LVHITTESTINFO pInfo\pt\x = LoWord(lParam) pInfo\pt\y = HiWord(lParam) SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, pInfo) rc.RECT rc\top = pInfo\iSubItem rc\left = #LVIR_BOUNDS SendMessage_(hwnd, #LVM_GETSUBITEMRECT, pInfo\iItem, rc) If hEdit=0 UseGadgetList(hwnd) CurItem = pInfo\iItem CurSubItem = pInfo\iSubItem Text$ = GetGadgetItemText(1, CurItem, CurSubItem);<<< If CurSubItem=0 rc\right = rc\left+SendMessage_(hwnd, #LVM_GETCOLUMNWIDTH, 0, 0) EndIf hEdit = StringGadget(2, rc\left+1, rc\top, rc\right-rc\left-1, rc\bottom-rc\top-1, Text$, #PB_String_BorderLess) If CurSubItem=0 SendMessage_(hEdit, #WM_SETFONT, FontBold, #True) Else SendMessage_(hEdit, #WM_SETFONT, FontReg, #True) EndIf OldEditProc = SetWindowLong_(hEdit, #GWL_WNDPROC, @EditProc()) SetFocus_(hEdit) EndIf Else result = CallWindowProc_(OldLViewProc, hwnd, uMsg, wParam, lParam) EndIf Case #WM_LBUTTONDOWN If hwnd<>hEdit KillFocus() pInfo.LVHITTESTINFO pInfo\pt\x = LoWord(lParam) pInfo\pt\y = HiWord(lParam) SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, pInfo) rc.RECT rc\top = pInfo\iSubItem rc\left = #LVIR_BOUNDS SendMessage_(hwnd, #LVM_GETSUBITEMRECT, pInfo\iItem, rc) rc\left+1 rc\bottom-1 If CellSelectOn InvalidateRect_(hwnd, rct, #True) EndIf CellSelectOn = 1 CurSelItem = pInfo\iItem CurSelSubItem = pInfo\iSubItem If CurSelSubItem=0 rc\right = rc\left+SendMessage_(hwnd, #LVM_GETCOLUMNWIDTH, 0, 0) EndIf DrawRectangle(hwnd, rc) CopyMemory(rc, rct, SizeOf(RECT)) Else SetFocus_(hEdit) result = CallWindowProc_(OldLViewProc, hwnd, uMsg, wParam, lParam) EndIf Case #WM_CTLCOLOREDIT If GetFocus_()=lParam SetBkMode_(wParam, #TRANSPARENT) If CurItem&1=0 TextBkColor = RGB(255, 255, 255);RGB(255, 255, 223);цвет фона при редактировании нечётных строк If CurSubItem=3 TextColor = RGB(255, 0, 0) EndIf Else TextBkColor = RGB(255, 255, 255);RGB(208, 208, 176);цвет фона при редактировании чётных строк If CurSubItem=3 TextColor = RGB(0, 0, 255) EndIf EndIf SetTextColor_(wParam, TextColor) result = CreateSolidBrush_(TextBkColor) Else result = CallWindowProc_(OldLViewProc, hwnd, uMsg, wParam, lParam) EndIf Case #WM_VSCROLL result = CallWindowProc_(OldLViewProc, hwnd, uMsg, wParam, lParam) rc.RECT TopVisibleItem = SendMessage_(hwnd, #LVM_GETTOPINDEX, 0, 0) If CellSelectOn rc\top = CurSelSubItem rc\left = #LVIR_BOUNDS SendMessage_(hwnd, #LVM_GETSUBITEMRECT, CurSelItem, rc) rct\top = rc\top rct\bottom = rc\bottom-1 If TopVisibleItem<=CurSelItem DrawRectangle(hwnd, rct) EndIf EndIf If hEdit If TopVisibleItem<=CurItem ResizeGadget(2,#PB_Ignore, rc\top,#PB_Ignore,#PB_Ignore) HideGadget(2, #False) RedrawWindow_(hEdit, 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) Else HideGadget(2, #True) EndIf SetFocus_(hEdit) EndIf Case #WM_HSCROLL result = CallWindowProc_(OldLViewProc, hwnd, uMsg, wParam, lParam) rc.RECT TopVisibleItem = SendMessage_(hwnd, #LVM_GETTOPINDEX, 0, 0) If CellSelectOn rc\top = CurSelSubItem rc\left = #LVIR_BOUNDS SendMessage_(hwnd, #LVM_GETSUBITEMRECT, CurSelItem, rc) rct\left = rc\left+1 rct\right = rc\right If TopVisibleItem<=CurSelItem DrawRectangle(hwnd, rct) EndIf EndIf If hEdit If TopVisibleItem<=CurItem ResizeGadget(2, rc\left,#PB_Ignore,#PB_Ignore,#PB_Ignore) HideGadget(2, #False) RedrawWindow_(hEdit, 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) Else HideGadget(2, #True) EndIf SetFocus_(hEdit) EndIf Default result = CallWindowProc_(OldLViewProc, hwnd, uMsg, wParam, lParam) EndSelect ProcedureReturn result EndProcedure Procedure WndProc(hwnd, uMsg, wParam, lParam);цвет result = #PB_ProcessPureBasicEvents Select uMsg Case #WM_NOTIFY *pnmh.NMHDR = lParam Select *pnmh\code Case #NM_CUSTOMDRAW *LVCDHeader.NMLVCUSTOMDRAW = lParam If *LVCDHeader\nmcd\hdr\hWndFrom=ListGadget Select *LVCDHeader\nmcd\dwDrawStage Case #CDDS_PREPAINT result = #CDRF_NOTIFYITEMDRAW Case #CDDS_ITEMPREPAINT result = #CDRF_NOTIFYSUBITEMDRAW Case #CDDS_SUBITEMPREPAINT Row = *LVCDHeader\nmcd\dwItemSpec Col = *LVCDHeader\iSubItem If Col=0 SelectObject_(*LVCDHeader\nmcd\hDC, FontBold) Else SelectObject_(*LVCDHeader\nmcd\hDC, FontReg) EndIf If Row&1=0 *LVCDHeader\clrTextBk = RGB(255, 255, 223);цвет нечётных строк LI If Col=3 *LVCDHeader\clrText = RGB(255, 0, 0) Else *LVCDHeader\clrText = RGB(0, 0, 0) EndIf Else *LVCDHeader\clrTextBk = RGB(208, 208, 176);цвет чётных строк LI If Col=3 *LVCDHeader\clrText = RGB(0, 0, 255) Else *LVCDHeader\clrText = RGB(0, 0, 0) EndIf EndIf result = #CDRF_NEWFONT EndSelect EndIf EndSelect EndSelect ProcedureReturn result EndProcedure ;} If OpenWindow(0, 0, 0, 400, 260, "Color List View Rows", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) ListGadget = ListIconGadget(1, 10, 10, 380, 240, "", 70, #PB_ListIcon_GridLines|#LVS_NOSORTHEADER) ;{редактируемый LI 2\3 SendMessage_(ListGadget, #CCM_SETVERSION, 5, 0) SendMessage_(ListGadget, #LVM_SETBKCOLOR, 0, RGB(255, 255, 223));цвет фона LI OldLViewProc = SetWindowLong_(ListGadget, #GWL_WNDPROC, @LViewProc()) SetWindowCallback(@WndProc()) ;} For x = 0 To 9 AddGadgetItem(1, x, Str(x+1)) AddGadgetColumn(1, x, Str(x+1), 35) SendMessage_(1, #LVM_SETCOLUMNWIDTH, i, #LVSCW_AUTOSIZE_USEHEADER);редактируемый LI 3\3 Next x Repeat Event.l = WaitWindowEvent() Select Event Case #PB_Event_Gadget Select EventGadget() ;Case EndSelect EndSelect Until Event = #PB_Event_CloseWindow EndIf