Click here to Skip to main content
14,606,525 members
Rate this:
Please Sign up or sign in to vote.
See more:
After creating the list view.. items are there i can select them but they have transparent brush or something like that.. and I only see a selection of that item but the item itself isn't there..
Anyone knows why.. ?


I have like 8 hours I look around this code can't figure out why my text doesn't show up..
Maybe I can show you the function the header and the window class I use in my project.

Theese are resource.h, main.cpp and the resource.rc. I took the code that refers to the listview ..sorry my code has 16.000+ lines can't copy all of it
// constants
#define ID_LISTVIEW         1000
#define NUM_ITEMS           30
#define NUM_COLUMNS         2
#define MAX_ITEMLEN         64
#define MAX_SYMBOLS         16
#define MAX_DESCRIPTION     64

// stringtable defines
#define IDS_SYMBOLS         1
#define IDS_DESCRIPTION     2

//Functions from resources.cpp
HWND CreateListView(HWND hWndParent);
LRESULT NotifyHandler(HWND, UINT, WPARAM, LPARAM);

// structures
typedef struct tagABRINFO
{
    char szSymbol[MAX_SYMBOLS];
    char szDescription[MAX_DESCRIPTION];
} ABRINFO;
====================================================|

#define _WIN32_IE 0x300

#include <windows.h>
#include <commctrl.h>
#include "resources.h"
#include <string.h>
#include <mmsystem.h>
#include <cstdio>

#define case ID_ABBREV 50

ABRINFO argsAbrInfo[] =
{
	{"LoD", "Lord of Destruction"},
	{"PvP", "Player versus Player"},
	{"XP", "Experience"},
	{"Javazon", "Javelin build Amazon"},
	{"HOTO", "Hart of the Oak Runeword"},
	{"Assa", "Assassin Character"},
	{"Andy", "Final Boss Act 1 Andariel"},
	{"D2", "Diablo 2 Classic"},
	{"PVM", "Player versus Monsters"},
	{"HP/MP", "Healing Potion/Mana Potion"}
};
HWND CreateListView(HWND hWndParent)
{
	HWND hWndList;
	int index;
	LV_COLUMN lvC;
	char szText[MAX_PATH];
	LV_ITEM lvI;
	int iSubItem;

	InitCommonControls();

	hWndList = CreateWindowEx(0L, WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD | WS_BORDER |
                           LVS_REPORT | LVS_SINGLESEL, 0, 32, 795, 448,
                            hWndParent, (HMENU)ID_LISTVIEW, hInst, NULL);

    ListView_SetExtendedListViewStyle(hWndList, LVS_EX_FULLROWSELECT | LVM_ENSUREVISIBLE | LVM_SETOUTLINECOLOR);

	if (hWndList == NULL)
		return NULL;

	lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvC.fmt = LVCFMT_LEFT;
	lvC.cx = 0x100;
	lvC.pszText = szText;

	for (index = 0; index <= NUM_COLUMNS; index++)
	{
		lvC.iSubItem = index;
		LoadString(hInst, IDS_SYMBOLS + index, szText, sizeof(szText));
		if (ListView_InsertColumn(hWndList, index, &lvC) == -1)
			return NULL;
	}

	lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
	lvI.state = 0;
	lvI.stateMask = 0;

	for (index = 0; index < NUM_ITEMS; index++)
	{
		lvI.iItem = index;
		lvI.iSubItem = 0;
		lvI.pszText = LPSTR_TEXTCALLBACK;
		lvI.cchTextMax = MAX_ITEMLEN;
		lvI.lParam = (LPARAM)&argsAbrInfo[index];

		if (ListView_InsertItem(hWndList, &lvI) == -1)
			return NULL;

		for (iSubItem = 1; iSubItem < NUM_COLUMNS; iSubItem++)
		{
			ListView_SetItemText(hWndList, index, iSubItem, LPSTR_TEXTCALLBACK);
		}
	}
	return (hWndList);
}
LRESULT NotifyHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;
	ABRINFO *pAbr = (ABRINFO *)(pLvdi->item.lParam);

	if (wParam != ID_LISTVIEW)
		return 0L;

	switch(pLvdi->hdr.code)
	{
		case LVN_GETDISPINFO:
			switch (pLvdi->item.iSubItem)
			{
				case 0:
					pLvdi->item.pszText = pAbr->szSymbol;
					break;
				case 1:
					pLvdi->item.pszText = pAbr->szDescription;
					break;
				default:
					break;
			}
			break;
		default:
			break;
	}
	return 0L;
}
//Main Vindow
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
    InitCommonControls();

    WNDCLASSW wc = {0};

    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.hIcon         = (HICON)LoadImage(GetModuleHandle(NULL),
                        MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, 32, 32, 0);
    wc.hInstance     = hInst;
    wc.lpfnWndProc   = MainWndProc;
    wc.lpszClassName = L"myMainClass";
    wc.style         = 0;
    wc.lpszMenuName  = MAKEINTRESOURCEW(IDR_MENU);

    if(!RegisterClassW(&wc))
        return -1;

    registerCloseClass(hInst);
    registerVersionClass(hInst);

    hMainWindow = CreateWindowW(L"myMainClass", L"My app",
                                WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION,
                                300, 100, 800, 550, NULL, NULL, NULL, NULL);

    ShowWindow(hMainWindow, nCmdShow);
    UpdateWindow(hMainWindow);

    MSG msg = {0};

    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}
//Main Loop
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    static HWND hWndListView;
    switch(msg)
    {
      case WM_NOTIFY:
        {
            return (NotifyHandler(hWnd, msg, wp, lp));
            break;
        }
      case WM_COMMAND:
        switch(wp)
        {
           case ID_ABBREV:
                 {
                      hWndListView = CreateListView(hWnd);
                      PlaySound(MAKEINTRESOURCE(IDW_CLICK), NULL, SND_RESOURCE | SND_ASYNC);
                      return DefWindowProcW(hWnd, msg, wp, lp);
                  }
        }
      case WM_DESTROY:
        {
            PostQuitMessage(0);
        }
        break;
    default:
        return DefWindowProcW(hWnd, msg, wp, lp);
    }
    return 0;
}
====================================================|

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE DISCARDABLE
BEGIN
    IDS_SYMBOLS             "Symbols"
    IDS_DESCRIPTION         "Description"
END


What I have tried:

Don't know what else to provide.. I wrote this code with another WNDCLASS and it works..
Class Ex is working and the Class W not. Anyone can help me understand why Ex class can I see the items in the list and the W doesn't show up ?..

The example below is almost identical with the one is shown in the MSDN..
Posted
Updated 1-Jul-20 21:56pm
v2
Comments
Rick York 1-Jul-20 22:36pm
   
What is the list view supposed to be? Is it a pop-up window? Part of dialog? A new component in the main window?
M@gelearn 2-Jul-20 4:13am
   
The list view should appear when user clicks on the Menu item. Is a new component in the window. The code that I show is the one from MSDN but I only cut the parts that I don't really need in my project so.. the images, other columns, the view style icons small icons etc.. and I first tried the code in the MSDN project and was working, the code showed up what I wrote to show , but when I transpose the code in my project all was fine olumns head columns name , but what was in the list under everything is invisible.. I can select the raws but the text doesn't appear..

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

list-view is a system control, Although use CreateWindowExA, but is a Unicode Window
in CreateListView you can use code test:
bUnicode = IsWindowUnicode(hWndList);

so in fun NotifyHandler you need case the LVN_GETDISPINFOW
example:
case LVN_GETDISPINFOW:
    pLvdi->item.pszText = (CHAR *)L"LVN_GETDISPINFOW";
    break;
   
Comments
M@gelearn 2-Jul-20 3:49am
   
Actually I have that case in my NotifyHandler.. and it doesn't work
Yofoo 2-Jul-20 4:31am
   
i has confirm the code work well on my pc(win7 x32)
the LVN_GETDISPINFOW found form debug the app, you can add trace code in NotifyHandler
example:

uCode = pLvdi->hdr.code;
ATLTRACE("NotifyHandler: %d\r\n", (int)uCode);

my pc show: NotifyHandler: -177
-177 just is LVN_GETDISPINFOW

in addition in CreateWindowEx you can add style LVS_OWNERDATA
LVN_GETDISPINFO need virtual list-view,
LPSTR_TEXTCALLBACK cause LVN_GETDISPINFO may diff on OS
M@gelearn 2-Jul-20 5:11am
   
Problem Event Name: APPCRASH
Application Name: MyApp.exe
Application Version: 0.0.0.0
Application Timestamp: 00050000
Fault Module Name: COMCTL32.DLL
Fault Module Version: 5.82.7601.18837
Fault Module Timestamp: 553a83e2
Exception Code: c0000005
Exception Offset: 0000c7d1
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
M@gelearn 2-Jul-20 5:11am
   
when I use LVS_OWNERDATA
M@gelearn 2-Jul-20 5:13am
   
My Pc (win 7 x32)
M@gelearn 2-Jul-20 4:41am
   
Hmmm.. I just saw something right away in your message the LVN_GETDISPINFOW, I use LVN_GETDISPINFO only so I add W right away... now list display but I see only signs or something like chinese language..
Yofoo 2-Jul-20 5:24am
   
LVN_GETDISPINFOW need Unicode, if direct use asc chars cause invalid, like chinese language, also possible cause exception
you can use this code to check:
pLvdi->item.pszText = (CHAR *)L"LVN_GETDISPINFOW";

Unicode convert you can use: MultiByteToWideChar
M@gelearn 2-Jul-20 4:47am
   
and I add LVS_OWNERDATA and right away I touch the item on menu that show the listview the App. crush with an error that refers to comctrl.dll
M@gelearn 2-Jul-20 5:41am
   
Yes I used pLvdi->item.pszText = (CHAR *)L"LVN_GETDISPINFOW"; and is shows Corecly..
M@gelearn 2-Jul-20 6:03am
   
Ok I think I found the Solution
I change to Wide Char in typedef struct
// structures
typedef struct tagABRINFO
{
WCHAR szSymbol[MAX_SYMBOLS];
WCHAR szDescription[MAX_DESCRIPTION];
} ABRINFO;
first was char

then I added L to each element L"" in the structure
and change this line also to
LV_DISPINFOW *pLvdi = (LV_DISPINFOW *)lParam;
first was
LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;

Ty again.. :)
M@gelearn 2-Jul-20 6:04am
   
works perfectly...
M@gelearn 2-Jul-20 6:11am
   
Ohh now that this work thanks to your help I wanna ask another question.

So in my view list I have all I need but, One thing I miss I don't know how to make resize every column the size of it is set early , but takes effect on all of the columns I have.. and How do I set a had raw like first line, second line to have a number in my list..
Thank you..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100