#include #include #include "resource.h" #include "defs.h" HWND gDlv_hWnd; HWND DlvCreate(HWND hWnd) { HWND hListView; LVCOLUMN lvc; gDlv_hWnd = hWnd; hListView = LvCreate(hWnd, (HMENU)IDC_DATALISTVIEW); lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = 0; lvc.pszText = TEXT("Key"); lvc.cx = 42; ListView_InsertColumn(hListView, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TEXT("Value"); lvc.cx = 500; ListView_InsertColumn(hListView, 1, &lvc); return hListView; } /* Show episode data. */ void DlvShowEpisode(int iEpisode) { HWND hListView; int r; LVITEM lviKey, lviValue; term_t t; hListView = GetDlgItem(gDlv_hWnd, IDC_DATALISTVIEW); ListView_DeleteAllItems(hListView); lviKey.mask = LVIF_TEXT; lviValue.mask = LVIF_TEXT; t = PL_new_term_refs(3); if(!PL_put_integer(t+0, iEpisode)) return; r = PL_call_predicate(NULL, PL_Q_NORMAL, PL_predicate("lookup_episode_local", 3, "episode_data"), t); if (!r) return; /* The episode data is a list of unary compounds, * whose functor is the key and whose argument is the value. */ { term_t tHead, tList; tHead = PL_new_term_ref(); tList = PL_copy_term_ref(t+2); for (int i = 0; PL_get_list(tList, tHead, tList); i++) { atom_t aKey; const char *szKey; char *szValue; TCHAR *tszKey, *tszValue; term_t tValue; size_t iArity; if (!PL_get_name_arity(tHead, &aKey, &iArity)) continue; szKey = PL_atom_chars(aKey); if (!szKey) continue; if (!PL_get_arg(1, tHead, tValue)) continue; if (!PL_get_atom_chars(tValue, &szValue)) continue; tszKey = TSZFromSZ(szKey, CP_UTF8); if (!tszKey) continue; tszValue = TSZFromSZ(szValue, CP_UTF8); if (!tszValue) continue; lviKey.mask = LVIF_TEXT; lviKey.iItem = i; lviKey.iSubItem = 0; lviKey.pszText = tszKey; lviKey.lParam = iEpisode; ListView_InsertItem(hListView, &lviKey); lviValue.iItem = i; lviValue.iSubItem = 1; lviValue.pszText = tszValue; ListView_SetItem(hListView, &lviValue); free(tszKey); free(tszValue); } } }