Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting QmGrid - row height, Font, Color
#9
Function dialog_grid_cell_color_icon2
Code:
Copy      Help
DlgGrid g
__ImageList il.Load("$qm$\il_dlg.bmp")

str csv=
;A1,B1
;A2,B2
;A3,B3

;array for colors etc of all cells
type __Cell8256 textColor backColor iconIndex
ARRAY(__Cell8256) c.create(2 3) ;;2 columns, 3 rows

;set default colors etc
sub.SetDefautCellFormatForAll
sub.SetCellFormat(0 1 4 0 0 4)
sub.SetCellFormat(0 2 2|4 0 0xe0c0c0 8)
sub.SetCellFormat(1 1 1|2|4 0xff 0xc0e0c0 6)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x2,0,0,0,0x0[]A,,,[]B,,,"
;4 Button 0x54032000 0x0 4 116 48 14 "Change"
;5 Button 0x54032000 0x0 56 116 48 14 "Clear"
;END DIALOG
;DIALOG EDITOR: "" 0x2040800 "*" "" "" ""

str controls = "3"
str qmg3x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4 ;;Change
,sub.SetCellFormat(0 1 1 0x00aa00) ;;change text color
,sub.SetCellFormat(0 2 2|0x100 0 0xa0ffa0) ;;change background color, clear text color and icon
,sub.SetCellFormat(1 1 0x100) ;;clear all attributes
,sub.Redraw
,case 5 ;;Clear
,sub.SetDefautCellFormatForAll
ret 1
;_______________________

;gInit

g.Init(hDlg 3)
g.SetImagelist(il)
SendMessage g LVM_SETEXTENDEDLISTVIEWSTYLE LVS_EX_SUBITEMIMAGES LVS_EX_SUBITEMIMAGES
g.FromCsv(csv ",")

ret
;_______________________

int row col

;gNotify
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,sel nh.code
,,case NM_CUSTOMDRAW goto gCustomDraw
,,case LVN_GETDISPINFOW goto gGetDispInfo
ret

;_______________________

;gCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
int R ;;the return value
sel cd.dwDrawStage
,case CDDS_PREPAINT
,R=CDRF_NOTIFYITEMDRAW ;;notify to draw items
,
,case CDDS_ITEMPREPAINT ;;now draw item
,R=CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW ;;notify to draw subitems
,
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM ;;now draw subitem
,row=cd.dwItemSpec; col=cd2.iSubItem
,cd2.clrText=c[col row].textColor
,cd2.clrTextBk=c[col row].backColor

ret DT_Ret(hDlg R)

;_______________________

;gGetDispInfo
NMLVDISPINFOW& di=+nh
LVITEMW& u=di.item
if u.mask&LVIF_IMAGE
,row=u.iItem; col=u.iSubItem
,u.iImage=c[col row].iconIndex

ret


#sub SetDefautCellFormatForAll v
int i j
for(i 0 c.len)
,for(j 0 c.len(1))
,,c[j i].textColor=0
,,c[j i].backColor=0xffffff
,,c[j i].iconIndex=I_IMAGENONE
if(g) InvalidateRect g 0 1


#sub SetCellFormat v
function column row flags [textColor] [backColor] [iconIndex] ;;flags: 1 text, 2 back, 4 icon, 0x100 clear
__Cell8256& r=c[column row]
if(flags&0x100) r.textColor=0; r.backColor=0xffffff; r.iconIndex=I_IMAGENONE
if(flags&1) r.textColor=textColor
if(flags&2) r.backColor=backColor
if(flags&4) r.iconIndex=iconIndex


#sub Redraw v
InvalidateRect g 0 1


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)