Jump to content

created listview but have related poblem


Recommended Posts

Guest veeraj_t
Posted

hi

i am not able to add an item or even a string to the list view

plz tell me where to make changes in this code so that i can add any string to the list view

sorry the code is big but no other way to explain my problem

plz do help

following is the code

/****************************************************************************

OnListViewNotify

****************************************************************************/

LRESULT OnListViewNotify(

HWND hwnd,

LPARAM lParam

)

{

NMHDR* pnmh = (NMHDR*) lParam;

LRESULT lResult = 0;

switch(pnmh->code)

{

case LVN_GETDISPINFO:

{

LV_DISPINFO* pdi = (LV_DISPINFO*)lParam;

//

// **** what i need to write here ???, because not still navi in windows programing

//

break;

case LVN_ITEMACTIVATE:

{

NMLISTVIEW* pnmlv = (NMLISTVIEW*)lParam;

// FormattedMessageBox(hwnd, MB_OK, g_hInst, IDS_MB_CAPTION, IDS_MB_FORMAT, pnmlv->iItem + 1);

}

break;

// Handle this notify if you want to use the number keys to select

// items in the view (like how the desktop file explorer lets you

// select files by typing the first few characters of the file name.)

// This notify is also used then the control is sent an LVM_FINDITEM

case LVN_ODFINDITEM:

{

NMLVFINDITEM* pFindItem = (NMLVFINDITEM*)lParam;

// Used if you are trying to find an item in the list view

}

break;

}

return(lResult);

}

/*******************************************

*********************/

BOOL InitMusiclistDlg(const HWND hDlg, UINT nToolBarId)

{

RECT rcClient;

HICON hIcon;

HIMAGELIST himlSmall;

int rgcxCols[3];

int iColumn;

char *rgFoldersInfo[3];

int index;

rgFoldersInfo[0]="item 1";

rgFoldersInfo[1]="item 2";

rgFoldersInfo[2]="item 3";

/// create dlg

SHINITDLGINFO shidi;

ZeroMemory(&shidi, sizeof(shidi));

shidi.dwMask = SHIDIM_FLAGS;

shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;

shidi.hDlg = hDlg;

//

// create the menu bar

//

SHMENUBARINFO mbi;

ZeroMemory(&mbi, sizeof(SHMENUBARINFO));

mbi.cbSize = sizeof(SHMENUBARINFO);

mbi.hwndParent = hDlg;

mbi.nToolBarId = nToolBarId;

mbi.hInstRes = g_hInst;

if (!(SHInitDialog(&shidi) && SHCreateMenuBar(&mbi))) {

//DebugOut (TEXT("Failed to make menubarn"));

EndDialog(hDlg,-1);

return TRUE;

}

//

SetWindowText(hDlg, UseString(IDS_LISTVIEW));

UpdateWindow(hDlg);

// Load some random strings needed later.

//

// helpful hint - see documentation of LoadString on how

// to load strings without needing to copy them to a

// buffer.

/* if(0 == LoadString(g_hInst, IDS_COLUMN0FORMAT, g_szColumn0Format, ARRAYSIZE(g_szColumn0Format)) ||

0 == LoadString(g_hInst, IDS_COLUMNNFORMAT, g_szColumnNFormat, ARRAYSIZE(g_szColumnNFormat)))

{

// Couldn't load a needed string.

goto Error;

}

*/

//

// create the ListView control

//

// On the Smartphone platform you should only use LVS_REPORT.

// Although the other styles do work, they are not very

// usable.

//

// Avoid column headers unless they are absolutely

// needed. They take up a row of the UI that could otherwise

// be used to display data.

GetClientRect(hDlg, &rcClient);

g_hwndListView = CreateWindow(WC_LISTVIEW, NULL,

WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_OWNERDATA,

rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top - MENU_HEIGHT,

hDlg, (HMENU)ID_LISTVIEW, g_hInst,NULL);

if(!g_hwndListView)

{

goto Error;

}

// Put the list view in full row select mode

ListView_SetExtendedListViewStyle(g_hwndListView,

ListView_GetExtendedListViewStyle(g_hwndListView) | LVS_EX_FULLROWSELECT);

//create an image list for the ListView

himlSmall = ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 0, 0);

if(NULL == himlSmall)

{

goto Error;

}

//set up the small image list

hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_POOMTASKS));

if(NULL == hIcon)

{

goto Error;

}

if(-1 == ImageList_AddIcon(himlSmall, hIcon))

{

goto Error;

}

ListView_SetImageList(g_hwndListView, himlSmall, LVSIL_SMALL);

//

// Create the columns.

//

// column 2 is 35 pixels wide

rgcxCols[2] = 0;

// column 1 is 40 pixels wide

rgcxCols[1] = 0;

// column 0 is the remaining space left in the control

rgcxCols[0] = (rcClient.right - rcClient.left) -

(GetSystemMetrics(SM_CXVSCROLL) + rgcxCols[1] + rgcxCols[2]);

for(iColumn = 0; iColumn < ARRAYSIZE(rgcxCols); iColumn++)

{

LV_COLUMN lvColumn;

lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH;

lvColumn.fmt = LVCFMT_LEFT;

lvColumn.cx = rgcxCols[iColumn];

if(-1 == ListView_InsertColumn(g_hwndListView, iColumn, &lvColumn))

{

// goto Error;

}

}

for (index = 0; index < 5; index++)

{

lvI.mask = LVIF_TEXT ;

lvI.iItem = index;

lvI.iSubItem = 0;

lvI.pszText = rgFoldersInfo[index];

lvI.cchTextMax = 32;

lvI.iImage = index;

//lvI.lParam = (LPARAM)&rgFoldersInfo[index];

if (ListView_InsertItem(g_hwndListView, &lvI) == -1)

return FALSE;

}

//set the number of items in the list

SetVirtualItemCount(5);

return(0);

Error:

return(-1);

}

/*******************************************************************************

call back listview

********************************************/

LRESULT CALLBACK MusicListDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

long lResult = 0;

switch(message)

{

case WM_INITDIALOG:

// create the dialog

InitMusiclistDlg(hDlg,IDR_LISTMENU) ;

break;

case WM_NOTIFY:

if(ID_LISTVIEW == wParam)

{

lResult = OnListViewNotify(hDlg, lParam);

}

else

{

goto DoDefault;

}

break;

case WM_COMMAND:

switch(GET_WM_COMMAND_ID(wParam, lParam))

{

case IDM_5_ITEMS:

SetVirtualItemCount(5);

break;

case IDM_5000_ITEMS:

SetVirtualItemCount(5000);

break;

case IDM_EXIT:

// Note that real applications should not have a quit option.

// It should be left to the system to shut them down when

// memory is low or a process slot is needed.

// This code is in samples to make it easier to try things.

DestroyWindow(hDlg);

break;

default:

goto DoDefault;

}

break;

case WM_INITMENUPOPUP:

if(0 == (UINT)LOWORD(lParam))

{

// This is menu 0 from IDM_MAIN_MENU

// Put a check next to the selected

// item count and uncheck the other

// item.

CheckMenuItem((HMENU)wParam, IDM_5_ITEMS,

MF_BYCOMMAND | (5 == g_cItems ? MF_CHECKED : MF_UNCHECKED));

CheckMenuItem((HMENU)wParam, IDM_5000_ITEMS,

MF_BYCOMMAND | (5000 == g_cItems ? MF_CHECKED : MF_UNCHECKED));

lResult = 0;

}

else

{

goto DoDefault;

}

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

case WM_ACTIVATE:

{

DWORD dwFlags = LOWORD(wParam);

if(dwFlags != WA_INACTIVE)

{

SetFocus(g_hwndListView);

}

}

break;

DoDefault:

default:

lResult = DefWindowProc(hDlg, message,wParam, lParam);

break;

}

return lResult;

}

/******************************************************/

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.