Started adding image support.

This commit is contained in:
Pietro Gagliardi 2014-10-21 14:31:44 -04:00
parent ae122b892d
commit 41d143d509
1 changed files with 37 additions and 2 deletions

View File

@ -43,6 +43,7 @@ struct table {
HWND header; HWND header;
int headerHeight; int headerHeight;
intptr_t nColumns; intptr_t nColumns;
HIMAGELIST imagelist;
}; };
static LONG rowHeight(struct table *t) static LONG rowHeight(struct table *t)
@ -350,6 +351,7 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
WCHAR msg[100]; WCHAR msg[100];
RECT headeritem; RECT headeritem;
intptr_t j; intptr_t j;
LRESULT xoff;
// TODO verify these two // TODO verify these two
background = (HBRUSH) (COLOR_WINDOW + 1); background = (HBRUSH) (COLOR_WINDOW + 1);
@ -373,6 +375,8 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
if (FillRect(dc, &rsel, background) == 0) if (FillRect(dc, &rsel, background) == 0)
abort(); abort();
xoff = SendMessageW(t->header, HDM_GETBITMAPMARGIN, 0, 0);
// now draw the cells // now draw the cells
if (SetTextColor(dc, GetSysColor(textColor)) == CLR_INVALID) if (SetTextColor(dc, GetSysColor(textColor)) == CLR_INVALID)
abort(); abort();
@ -381,7 +385,29 @@ static void drawItems(struct table *t, HDC dc, RECT cliprect)
for (j = 0; j < t->nColumns; j++) { for (j = 0; j < t->nColumns; j++) {
if (SendMessageW(t->header, HDM_GETITEMRECT, (WPARAM) j, (LPARAM) (&headeritem)) == 0) if (SendMessageW(t->header, HDM_GETITEMRECT, (WPARAM) j, (LPARAM) (&headeritem)) == 0)
abort(); abort();
rsel.left = headeritem.left + SendMessageW(t->header, HDM_GETBITMAPMARGIN, 0, 0);
if (j == 1) { // TODO
IMAGELISTDRAWPARAMS ip;
ZeroMemory(&ip, sizeof (IMAGELISTDRAWPARAMS));
ip.cbSize = sizeof (IMAGELISTDRAWPARAMS);
ip.himl = t->imagelist;
ip.i = 0;
ip.hdcDst = dc;
ip.x = headeritem.left + xoff;
ip.y = y;
ip.cx = 0; // draw whole image
ip.cy = 0;
ip.xBitmap = 0;
ip.yBitmap = 0;
ip.rgbBk = CLR_NONE;
ip.fStyle = ILD_NORMAL | ILD_SCALE; // TODO alpha-blend; ILD_DPISCALE?
// TODO ILS_ALPHA?
if (ImageList_DrawIndirect(&ip) == 0)
abort();
continue;
}
rsel.left = headeritem.left + xoff;
rsel.top = y; rsel.top = y;
rsel.right = headeritem.right; rsel.right = headeritem.right;
rsel.bottom = y + tm.tmHeight; rsel.bottom = y + tm.tmHeight;
@ -449,7 +475,16 @@ item.pszText = L"Column 2";
item.fmt = HDF_LEFT | HDF_STRING; item.fmt = HDF_LEFT | HDF_STRING;
if (SendMessage(t->header, HDM_INSERTITEM, 1, (LPARAM) (&item)) == (LRESULT) (-1)) if (SendMessage(t->header, HDM_INSERTITEM, 1, (LPARAM) (&item)) == (LRESULT) (-1))
abort(); abort();
t->nColumns=2;} t->nColumns=2;
t->imagelist = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32, 1, 1);
if(t->imagelist==NULL)abort();
{
HICON icon;
icon = LoadIconW(NULL, IDI_ERROR);
if(icon == NULL)abort();
if (ImageList_AddIcon(t->imagelist, icon) == -1)abort();
}
}
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t); SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) t);
} }
// even if we did the above, fall through // even if we did the above, fall through