我的输出在编辑控件框中被覆盖并仅显示最后一个值 [英] my output gets overwrite in edit control box and displays only last value

查看:54
本文介绍了我的输出在编辑控件框中被覆盖并仅显示最后一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们我正在开发一个mfc vc ++用户界面应用程序,其中我想在只读模式的编辑控制框中显示值。我面临的问题是我希望输出显示所有计划任务的列表。但是通过我的代码,所有值都被覆盖,因此它只显示最后一个计划任务而不是计划任务列表。任何人都可以告诉我我错在哪里。我的代码是:



hey guys i am developing an mfc vc++ user iterface application in which i want to display values in edit control box with read only mode. the problem i am facing is i want the output to be displayed the list of all scheduled task.But through my code all values get override and hence forth it displays only last scheduled task instead of list of scheduled task. can any one tell me where i am mistaken.here is my code :

BOOL CoriginalDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	
	//------------------------------task-------------------------------------------------------------------------
	HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
	if (FAILED(hr))
	{
		printf("\nCoInitializeEx failed: %x", hr);
		return 1;
	}

	//  Set general COM security levels.
	hr = CoInitializeSecurity(
		NULL,
		-1,
		NULL,
		NULL,
		RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
		RPC_C_IMP_LEVEL_IMPERSONATE,
		NULL,
		0,
		NULL);

	if (FAILED(hr))
	{
		printf("\nCoInitializeSecurity failed: %x", hr);
		CoUninitialize();
		return 1;
	}

	//  ------------------------------------------------------
	//  Create an instance of the Task Service. 
	ITaskService *pService = NULL;
	hr = CoCreateInstance(CLSID_TaskScheduler,
		NULL,
		CLSCTX_INPROC_SERVER,
		IID_ITaskService,
		(void**)&pService);
	if (FAILED(hr))
	{
		printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
		CoUninitialize();
		return 1;
	}

	//  Connect to the task service.
	hr = pService->Connect(_variant_t(), _variant_t(),
		_variant_t(), _variant_t());
	if (FAILED(hr))
	{
		printf("ITaskService::Connect failed: %x", hr);
		pService->Release();
		CoUninitialize();
		return 1;
	}

	//  ------------------------------------------------------
	//  Get the pointer to the root task folder.
	ITaskFolder *pRootFolder = NULL;
	hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder);

	pService->Release();
	if (FAILED(hr))
	{
		printf("Cannot get Root Folder pointer: %x", hr);
		CoUninitialize();
		return 1;
	}

	//  -------------------------------------------------------
	//  Get the registered tasks in the folder.
	IRegisteredTaskCollection* pTaskCollection = NULL;
	hr = pRootFolder->GetTasks(NULL, &pTaskCollection);

	pRootFolder->Release();
	if (FAILED(hr))
	{
		printf("Cannot get the registered tasks.: %x", hr);
		CoUninitialize();
		return 1;
	}

	LONG numTasks = 0;
	hr = pTaskCollection->get_Count(&numTasks);

	if (numTasks == 0)
	{
		//printf("\nNo Tasks are currently running");
		pTaskCollection->Release();
		CoUninitialize();
		return 1;
	}

	//printf("\nNumber of Tasks : %d", numTasks);
	cout << "Task Names:";
	TASK_STATE taskState;


	for (LONG i = 0; i < numTasks; i++)
	{
		IRegisteredTask* pRegisteredTask = NULL;
		hr = pTaskCollection->get_Item(_variant_t(i + 1), &pRegisteredTask);

		if (SUCCEEDED(hr))
		{
			BSTR taskName = NULL;
			hr = pRegisteredTask->get_Name(&taskName);
			if (SUCCEEDED(hr))
			{
				printf("\t  %S", taskName);
				SysFreeString(taskName);
			    
				m_users.SetWindowTextW(taskName);
				 

							
				
				
				hr = pRegisteredTask->get_State(&taskState);
				if (SUCCEEDED(hr))
					printf("", taskState);

				if (taskState == 1)
					printf(": disable \n");

				else	if (taskState == 2)
					printf(": queued \n ");

				else	if (taskState == 3)
					printf(": ready\n");

				else if (taskState == 4)
					printf(": running \n ");

				else
					printf("\n\tCannot get the registered task state: %x", hr);
			}
			else
			{
				printf("\nCannot get the registered task name: %x", hr);
			}
			pRegisteredTask->Release();
		}
		else
		{
			printf("\nCannot get the registered task item at index=%d: %x", i + 1, hr);
		}
	}

	pTaskCollection->Release();
	CoUninitialize();
	
	//------------------------------------------------------------------------------------------------------
	return TRUE;  // return TRUE  unless you set the focus to a control
}







注意:

m_user是成员变量




Note:
m_user is member variable

推荐答案

错误是这段代码:



The error is this code:

m_users.SetWindowTextW(taskName);





您想要的可能是:





What you want is possibly something like:

CString str = m_users.GetWindowTextW();
str += "\r\n";
str += taskName;
m_users.SetWindowTextW(str);


这篇关于我的输出在编辑控件框中被覆盖并仅显示最后一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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