⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interfaceview.cpp

📁 You imagine? Right, there s more than one possibility, this time I ll give you tree. One for your pr
💻 CPP
字号:
// InterfaceView.cpp : Implementierung der Klasse CInterfaceView
//

#include "stdafx.h"
#include "Interface.h"

#include "InterfaceDoc.h"
#include "InterfaceView.h"
#include "OtherDropDialogThread.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInterfaceView

IMPLEMENT_DYNCREATE(CInterfaceView, CFormView)

BEGIN_MESSAGE_MAP(CInterfaceView, CFormView)
	//{{AFX_MSG_MAP(CInterfaceView)
	ON_COMMAND(ID_FILE_MODELESS, OnModeless)
	ON_COMMAND(ID_FILE_OTHERMODELESS, OnFileOthermodeless)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInterfaceView Konstruktion/Destruktion

CInterfaceView::CInterfaceView()
	: CFormView(CInterfaceView::IDD)
{
	//{{AFX_DATA_INIT(CInterfaceView)
		// HINWEIS: Der Klassenassistent f黦t hier Member-Initialisierung ein
	//}}AFX_DATA_INIT
	m_bInitiated=false;
	m_pModeless=NULL;
	m_pDlgThread=NULL;
}

CInterfaceView::~CInterfaceView()
{
	if (m_pModeless)
	{
		if (::IsWindow(m_pModeless->GetSafeHwnd()))
			m_pModeless->EndDialog(IDCANCEL);

		delete m_pModeless;
	}

	if (AfxIsValidAddress(m_pDlgThread, sizeof(CWinThread)) &&
		AfxIsValidAddress(m_pDlgThread->m_pMainWnd, sizeof(CWnd)))
	{
		// retrieve the threads main window
		CDialog *pDlg = (CDialog *)m_pDlgThread->m_pMainWnd;
		
		if (::IsWindow(pDlg->GetSafeHwnd()))
		{
			// make sure we have a CDialog-derived main 
			// thread window then terminate it
			ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CDialog)));
			pDlg->EndDialog(IDCANCEL);

			// now give the thread some time to end, 
			// 2 second should be enough. You may 
			// able to use INFINITE as wait value, if you dare...
			WaitForSingleObject(m_pDlgThread->m_hThread, 2000);
			m_pDlgThread=NULL;
		}
	}
}

void CInterfaceView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInterfaceView)
	DDX_Control(pDX, IDC_LIST1, m_Table);
	//}}AFX_DATA_MAP
}

BOOL CInterfaceView::PreCreateWindow(CREATESTRUCT& cs)
{
	return CFormView::PreCreateWindow(cs);
}

void CInterfaceView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	if (!m_bInitiated)
	{
		// I know, I know, this could be easear
		CString t1 = "Item\nSubitem1\nSubitem2\nSubitem3\nSubitem4\n",
				t2;

		int idx = t1.Find('\n'), i = 0;

		while (idx != -1 && i<5)
		{	
			t2 = t1.Left(idx);
			t1 = t1.Mid(idx+1);
			m_Table.InsertColumn(i, t2, LVCFMT_LEFT, 75);
			i++;
			idx = t1.Find('\n');
		}
		m_bInitiated = true;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CInterfaceView Diagnose

#ifdef _DEBUG
void CInterfaceView::AssertValid() const
{
	CFormView::AssertValid();
}

void CInterfaceView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CInterfaceDoc* CInterfaceView::GetDocument() // Die endg黮tige (nicht zur Fehlersuche kompilierte) Version ist Inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CInterfaceDoc)));
	return (CInterfaceDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CInterfaceView Message-Handler

void CInterfaceView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	m_Table.DeleteAllItems();

	int count = GetDocument()->m_Strings.GetUpperBound();

	for (int i=0; i<=count; i++)
		InsertRow(GetDocument()->m_Strings[i]);
}

int CInterfaceView::InsertRow(CString TabSeparated)
{
	CString t1(TabSeparated), t2;
	int idx = t1.Find('\t'), i = 1, row=LB_ERR;

	if (idx !=-1)
	{
		t2 = t1.Left(idx);
		t1 = t1.Mid(idx+1);
		row = m_Table.InsertItem(m_Table.GetItemCount()+1, t2);
		idx = t1.Find('\t');
	}

	while (idx != -1 && i < 5 && row != LB_ERR)
	{	
		t2 = t1.Left(idx);
		t1 = t1.Mid(idx+1);
		m_Table.SetItemText(row, i, t2);
		CString deb = m_Table.GetItemText(row, i);
		i++;
		idx = t1.Find('\t');
	}
	return row;
}

void CInterfaceView::OnModeless() 
{
	// Display the modal dialog box
	if (!m_pModeless)
		m_pModeless = new CDropDialog;
	
	if (!::IsWindow(m_pModeless->GetSafeHwnd()))
		m_pModeless->Create(IDD_DIALOG1, this);

	m_pModeless->ShowWindow(SW_SHOW);	
}

void CInterfaceView::OnFileOthermodeless() 
{
	if (AfxIsValidAddress(m_pDlgThread, sizeof(CWinThread)) &&
		AfxIsValidAddress(m_pDlgThread->m_pMainWnd, sizeof(CWnd)))
	{
		if (::IsWindow(m_pDlgThread->m_pMainWnd->GetSafeHwnd()))
		{	m_pDlgThread->GetMainWnd()->SetWindowPos(&wndTop, 0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
			return;
		}
	}

	m_pDlgThread=AfxBeginThread( RUNTIME_CLASS(COtherDropDialogThread) );	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -