#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
int fInsertListViewColumn(HWND hwndListView, long lCol, int iPercent, TCHAR text[])
{
LVCOLUMN lvcolumn;
RECT rect;
GetClientRect(hwndListView, &rect);
int iResult;
iPercent = iPercent > 10 ? min(iPercent, 90) : 10;
int iWidth = (int) (rect.right * (iPercent / 100.0));
if (hwndListView == NULL)
{
MessageBox(NULL, TEXT("! Handle of ListView NULL (fInsertListViewColumn)"), TEXT("fire"), MB_OK | MB_ICONEXCLAMATION);
return(0);
}
memset(&lvcolumn, 0, sizeof(lvcolumn));
lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
lvcolumn.fmt = LVCFMT_LEFT;
lvcolumn.pszText = text;
lvcolumn.iSubItem = lCol;
lvcolumn.cx = iWidth;
if (SendMessage((HWND) hwndListView, (UINT) LVM_INSERTCOLUMN, (WPARAM) (int) lCol, (LPARAM) &lvcolumn) == -1) iResult = 0; else iResult = 1;
InvalidateRect(hwndListView, &rect, TRUE);
return(iResult);
}
int fInsertListViewItem(HWND hwndListView, long lLin, long lCol, int iSubItemYesNo, TCHAR text[])
{
LVITEM lvi;
RECT rect;
GetClientRect(hwndListView, &rect);
int iResult;
if (hwndListView == NULL)
{
MessageBox(NULL, TEXT("! Handle of ListView NULL (fInsertListViewItem)"),TEXT("fire"), MB_OK | MB_ICONEXCLAMATION);
return(0);
}
memset(&lvi, 0, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.state = 0;
lvi.stateMask = 0;
lvi.pszText = text;
lvi.iItem = lLin;
lvi.iSubItem = lCol;
switch(iSubItemYesNo)
{
case 0:
if (SendMessage((HWND) hwndListView, (UINT) LVM_INSERTITEM, (WPARAM) 0, (LPARAM) &lvi) == -1) iResult = 0; else iResult = 1;
break;
case 1:
if (SendMessage((HWND) hwndListView, (UINT) LVM_SETITEM, (WPARAM) 0, (LPARAM) &lvi) == FALSE) iResult = 0; else iResult = 1;
break;
default:
MessageBox(NULL, TEXT("! Unexpected iSubItemYesNo (fInsertListViewItem)"), TEXT("fire"), MB_OK | MB_ICONEXCLAMATION);
return(0);
break;
}
InvalidateRect(hwndListView, &rect, TRUE) ;
return(iResult);
}
BOOL CALLBACK TcpDlgProc (HWND hTcpDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG :
GetTCPConn(hTcpDlg);
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
case IDCANCEL :
EndDialog (hTcpDlg, 0);
return TRUE ;
}
case WM_DESTROY:
EndDialog(hTcpDlg,0);
return TRUE ;
break ;
}
return FALSE ;
}
void GetTCPConn(HWND hTcpDlg)
{
hwndLV = GetDlgItem(hTcpDlg, IDC_LIST2);
fInsertListViewColumn(hwndLV, 0, 30, TEXT("A (column)"));
fInsertListViewColumn(hwndLV, 1, 30, TEXT("B (column)"));
fInsertListViewItem(hwndLV, 0, 0, 0, TEXT("A1(item)"));
fInsertListViewItem(hwndLV, 1, 0, 0, TEXT("A2 (item)"));
}
When i remove List control Dialog Box display but as soon as i add List view(List Control) in dialog box it doesn't work.
Same is working fine in windows 7. Please help me asap. Have to complete my project by tomorrow morning.
Help me
Thank you in Advance
Edit: Pre Tags and missing (") added