在对话框中没有获取列表视图(列表控件) [英] Not getting List view(List Control) in DialogBox

查看:98
本文介绍了在对话框中没有获取列表视图(列表控件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// This is the the file for list view. I am passing handle of List Control to this function.

#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);
}


//This is my Dialog Procedure
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 ;
}

// This is the function which i am calling in my dialog Procedure
void GetTCPConn(HWND hTcpDlg)
{

	//handle to list view
	hwndLV = GetDlgItem(hTcpDlg, IDC_LIST2);

	// Setup the list box
	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)"));
}



当我删除列表控件对话框显示但在对话框中添加列表视图(列表控件)后,它不起作用.
在Windows 7中同样可以正常工作.请尽快帮助我.必须在明天早上之前完成我的项目.

帮帮我

预先感谢您



添加了前置标记和缺少的字符()



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



Pre Tags and missing (") added

推荐答案

您是否呼叫了InitCommonControlsEx()?

希望这会有所帮助,

Pablo.
Did you call InitCommonControlsEx()?

Hope this helps,

Pablo.


这应该放在您的InitInstance函数中:

This is what should go into your InitInstance function:

// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles.  Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);



我认为自动生成的注释说明了它的作用.在Windows 7下,操作系统会自动为您执行此操作.在XP下,必须按上述步骤进行操作,否则创建通用控件的任何窗口都会失败.



I think the automatically generated comments explain what it does. Under Windows 7 the operating system does this automatically for you. Under XP it needs to be done as shown above, otherwise any window creation of a common control will fail.


这篇关于在对话框中没有获取列表视图(列表控件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆