Re: Help needed with Listview controls
On Thu, 29 Jul 1999 10:25:21 -0400, Bernie Ryan <bwryan at PCOM.NET> wrote:
>Terry:
> I looked up ListView in my C++ compiler samples and I think that you
> will find that it is going to be a serious task to use it with
> the win32lib.ew because you will have to handle a lot of callbacks
> and codes that are not yet implemented in win32lib which was written
> to handle the basic standard controls used in win32.
Thanks for the reply Bernie.
Der! Disegard the part of my earlier posting where I was wondering how to
poke an unlimited-length string into a dword. I really should wait until I
wake before posting.
I'm not using David's win32lib for the exact reasons you mention (although I
have stolen a lot of his code, for which he will be thanked). Catching any
callbacks (i.e. LVN_COLUMNCLICK) isn't really a problem for me. My main
difficulty is understanding C code, as it is a language I have never used.
My background would be more in assembly.
I like taking on things which I don't know how to do, because I have more of
a chance of remebering anything I learn then.
I'm including below the complete C code example of what I posted earlier.
Maybe if you (or anybody) has the chance, they could compare my Eu procedure
with the C code to see where I am going wrong
Thanks
Terry
argh!!! C code ahead -->
// InitListViewItems - adds items and subitems to a list view.
// Returns TRUE if successful or FALSE otherwise.
// hwndLV - handle of the list view control
// pfData - text file containing list view items with columns
// separated by semicolons
BOOL WINAPI InitListViewItems(HWND hwndLV, FILE *pfData)
{
extern char g_achTemp[256]; // temporary buffer
PSTR pszStart;
PSTR pszEnd;
int iItem;
int iSubItem;
LV_ITEM lvi;
// Initialize LV_ITEM members that are common to all items.
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
lvi.state = 0;
lvi.stateMask = 0;
lvi.pszText = LPSTR_TEXTCALLBACK; // app. maintains text
lvi.iImage = 0; // image list index
// Read each line in the specified file.
for (iItem = 0;
fgets(g_achTemp, sizeof(g_achTemp), pfData);
iItem++) {
// Allocate an application-defined structure to store the
// item label and the text of each subitem.
MYITEM *pItem = LocalAlloc(LPTR, sizeof(MYITEM));
// Copy the first string (the label).
pszEnd = strchr(g_achTemp, ';');
*pszEnd = '\0';
pItem->aCols[0] = DupString(g_achTemp);
// Copy subsequent strings (subitems).
for (iSubItem = 1;
iSubItem < C_COLUMNS && pszEnd != NULL;
iSubItem++) {
pszStart = pszEnd + 1;
if ((pszEnd = strchr(pszStart, ';')) != NULL)
*pszEnd = '\0';
pItem->aCols[iSubItem] = DupString(pszStart);
}
// Initialize item-specific LV_ITEM members.
lvi.iItem = iItem;
lvi.iSubItem = 0;
lvi.lParam = (LPARAM) pItem; // item data
// Add the item.
ListView_InsertItem(hwndLV, &lvi);
// There is no need to set the text of the subitems. They
// default to LPSTR_TEXTCALLBACK.
}
return TRUE;
}
// DupString - allocates a copy of a string.
// lpsz - address of the null-terminated string to copy
LPSTR DupString(LPSTR lpsz)
{
int cb = lstrlen(lpsz) + 1;
LPSTR lpszNew = LocalAlloc(LMEM_FIXED, cb);
if (lpszNew != NULL)
CopyMemory(lpszNew, lpsz, cb);
return lpszNew;
}
phew, that's the end of the C
=======================================================
Now for the nice safe Eu -->
procedure fill_listview()
constant LPSTR_TEXTCALLBACK = -1
atom lv_struct
integer ok
sequence lv_data, string_struct, temp_str, struct_members
struct_members = {}
lv_struct = allocate(36)
lv_data = {{"7-6","1","2","3"},{"2-9","1","2","3"},{"4-8","1","2","3"}}
for iitem = 1 to length(lv_data) do
string_struct = {}
temp_str = lv_data[iitem]
for j = 1 to length(temp_str) do
string_struct = string_struct & temp_str[j] & 0
end for
ok = allocate_string(string_struct)
struct_members = struct_members & ok
poke4(lv_struct + 00, or_all({LVIF_TEXT, LVIF_IMAGE,
LVIF_PARAM, LVIF_STATE})) --mask;
poke4(lv_struct + 04, iitem-1) -- 0 based --iItem;
poke4(lv_struct + 08, 0) --iSubItem;
poke4(lv_struct + 12, 0) --state;
poke4(lv_struct + 16, 0) --stateMask;
poke4(lv_struct + 20, LPSTR_TEXTCALLBACK) --pszText;
poke4(lv_struct + 24, length(string_struct)) --cchTextMax;
poke4(lv_struct + 28, 0) --iImage;
poke4(lv_struct + 32, ok) --pointer to string_struct --lParam;
ok = c_func(SendMessage, {window_handle[listview_win],
LVM_INSERTITEM, 0, lv_struct})
end for
c_proc(UpdateWindow, {window_handle[listview_win]})
end procedure
|
Not Categorized, Please Help
|
|