Пример #1
0
// **************************************************************************
// OnInitDialog ()
//
// Description:
//	Called immediately before the dialog box is displayed.  Use opportunity
//	to initialize controls.
//
// Parameters:
//  none
//
// Returns:
//	BOOL - Result of base class processing.
// **************************************************************************
BOOL CKItemPropertiesDlg::OnInitDialog () 
	{
	CString strText;

	// Limit the access path to 255 chars:
	((CEdit *)GetDlgItem (IDC_ACCESSPATH))->LimitText (255);
	
	// Allow 10 levels of 32 character names plus a tag name of 31 characters:
	((CEdit *)GetDlgItem (IDC_ITEMID))->LimitText (10*32 + 31);

	// Subclass image buttons:
	m_cNext.SubclassDlgItem (IDC_NEXT, this);
	m_cPrev.SubclassDlgItem (IDC_PREVIOUS, this);

	// Create tool tips for image buttons:
	m_cToolTip.Create (this);
	m_cToolTip.AddWindowTool (&m_cNext);
	m_cToolTip.AddWindowTool (&m_cPrev);

	// Intialize IItemProperties 2.0 list control headings:
	CListCtrl *pList = (CListCtrl *) GetDlgItem (IDC_LIST);
	ASSERT (pList != NULL);

	// Get rectangle that bounds list control:
	CRect rc;
	pList->GetWindowRect (&rc);

	// Calculate the width of the list control:
	int nTotalWidth;
	nTotalWidth = rc.right - rc.left;
	
	// Create the list control columns.  Headers will be loaded from
	// string resources and widths will be a function of total width
	// of list control:
	for (int i = 0; i < NUMCOLUMNS; i++)
		{
		int nWidth;

		switch (i)
			{
			case 0:	// ID
				strText.LoadString (IDS_ID);
				nWidth = nTotalWidth / 8;
				break;

			case 1: // Description
				strText.LoadString (IDS_DESCRIPTION);
				nWidth = nTotalWidth / 3;
				break;

			case 2:	// Value
				strText.LoadString (IDS_VALUE);
				nWidth = nTotalWidth / 6;
				break;

			case 3: // Item ID
				strText.LoadString (IDS_ITEMID);
				nWidth = nTotalWidth / 3;
				break;

			default:
				ASSERT (FALSE);
				break;
			}

		// Insert the column:
		pList->InsertColumn (i, strText, LVCFMT_LEFT, nWidth);
		}

	// Enable/disable the window based on whether or not the 2.0 
	// functionality is available. (If m_pIItemProps interface
	// pointer is NULL, we can assume functionality is not available.)
	pList->EnableWindow (m_pIItemProps != NULL);

	// Select the first item:
	SelectItem (0);

	// return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
	return (CDialog::OnInitDialog ());  
	}