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

📄 tabbedmdisave.cpp

📁 These listed libraries are written in WTL. But it s really hard to mix both MFC & WTL together. Obvi
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			return TRUE;
		}
	}
	bHandled = FALSE;
	return 0;
}

LRESULT CSaveModifiedItemsDialog::OnHeaderTrack(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& bHandled)
{
	// NOTE: See http://support.microsoft.com/?kbid=183258
	//  "INFO: HDN_TRACK Notifications and Full Window Drag Style"
	//  We only get this if the HDS_FULLDRAG style is not set
	//  (in which case, we won't get HDN_ITEMCHANGING).

	// If HDS_FULLDRAG is NOT set, the list view won't show the contents
	// as the user is dragging the divider to resize a column.
	// So we won't update the column widths as they drag,
	// but will in "End Track" when they're done

	bHandled = FALSE;
	return 0;
}

LRESULT CSaveModifiedItemsDialog::OnHeaderEndTrack(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
	if((m_header.GetStyle() & HDS_FULLDRAG) == 0)
	{
		// HDS_FULLDRAG is not set, so the contents aren't updated as they
		// drag the column header divider until they let up on the mouse.
		NMHEADER* headerInfo = (NMHEADER*)pnmh;
		if(	headerInfo && 
			headerInfo->pitem &&
			(headerInfo->pitem->mask & HDI_WIDTH) == HDI_WIDTH)
		{
			if(m_trackColumnIndex == headerInfo->iItem)
			{
				int columnRight = headerInfo->iItem + 1;
				// Find the first column to the right that isn't being hidden.
				while((columnRight < m_lastVisibleColumn) && !m_showColumn[columnRight])
				{
					++columnRight;
				}

				if(columnRight <= m_lastVisibleColumn)
				{
					int widthLeft = headerInfo->pitem->cxy;
					int widthRight = m_list.GetColumnWidth(columnRight);
					int newWidth = widthRight - (widthLeft - m_trackColumnWidth);
					if((widthLeft > eMinimumColumnWidth) && (newWidth > eMinimumColumnWidth))
					{
						// TODO: When making the right column bigger before the
						//  left column has gotten smaller, the scroll bars flash
						//  visible.  Do something to prevent that.
						m_list.SetColumnWidth(columnRight, newWidth);

						m_trackColumnWidth = widthLeft;
					}
					else
					{
						headerInfo->pitem->cxy = m_trackColumnWidth;
					}
				}
			}
		}
	}

	m_list.Invalidate();
	m_trackColumnIndex = -1;
	m_trackColumnWidth = 0;

	bHandled = FALSE;
	return 0;
}

LRESULT CSaveModifiedItemsDialog::OnHeaderItemChanging(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
	if((m_header.GetStyle() & HDS_FULLDRAG) == HDS_FULLDRAG)
	{
		// HDS_FULLDRAG is set, so the contents are updated as they
		// drag the column header divider.
		NMHEADER* headerInfo = (NMHEADER*)pnmh;
		if(	headerInfo && 
			headerInfo->pitem &&
			(headerInfo->pitem->mask & HDI_WIDTH) == HDI_WIDTH)
		{
			if(m_trackColumnIndex == headerInfo->iItem)
			{
				int columnRight = headerInfo->iItem + 1;
				// Find the first column to the right that isn't being hidden.
				while((columnRight < m_lastVisibleColumn) && !m_showColumn[columnRight])
				{
					++columnRight;
				}

				if(columnRight <= m_lastVisibleColumn)
				{
					int widthLeft = headerInfo->pitem->cxy;
					int widthRight = m_list.GetColumnWidth(columnRight);
					int newWidth = widthRight - (widthLeft - m_trackColumnWidth);
					if((widthLeft > eMinimumColumnWidth) && (newWidth > eMinimumColumnWidth))
					{
						// TODO: When making the right column bigger before the
						//  left column has gotten smaller, the scroll bars flash
						//  visible.  Do something to prevent that.
						m_list.SetColumnWidth(columnRight, newWidth);

						m_trackColumnWidth = widthLeft;
					}
					else
					{
						// Don't allow the change
						bHandled = TRUE;
						return TRUE;
					}
				}
			}
		}
	}
	bHandled = FALSE;
	return 0;
}

LRESULT CSaveModifiedItemsDialog::OnHeaderDividerDoubleClick(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& bHandled)
{
	// TODO: Deal with this (and with Ctrl + NumPad+)
	bHandled = FALSE;
	return 0;
}

// CDialogResize overrides
void CSaveModifiedItemsDialog::DlgResize_UpdateLayout(int cxWidth, int cyHeight)
{
	//m_list.SetRedraw(FALSE);
	resizeClass::DlgResize_UpdateLayout(cxWidth, cyHeight);
	if(m_list.IsWindow())
	{
		// Adjust width of the description column to account for resizing the dialog
		CRect rcList;
		m_list.GetClientRect(&rcList);

		int headerCount = m_header.GetItemCount();
		int columnWidths = 0;
		for(int i=0; i<headerCount; ++i)
		{
			columnWidths += m_list.GetColumnWidth(i);
		}

		int difference = (rcList.Width() - columnWidths);
		if(difference != 0)
		{
			// Make up the difference by resizing the description column (if its visible).
			// If the description column isn't visible, make up the difference with the name column.
			int columnIndexToMakeUpDifference = eColumn_Description;
			if(m_showColumn[eColumn_Description])
			{
				columnIndexToMakeUpDifference = eColumn_Description;
			}
			else
			{
				columnIndexToMakeUpDifference = eColumn_Name;
			}

			int columnWidth = m_list.GetColumnWidth(columnIndexToMakeUpDifference);
			columnWidth += difference;
			if(columnWidth > eMinimumColumnWidth)
			{
				m_list.SetColumnWidth(columnIndexToMakeUpDifference, columnWidth);
			}
			else
			{
				m_list.SetColumnWidth(columnIndexToMakeUpDifference, eMinimumColumnWidth);
			}

			// TODO: When resizing the dialog smaller, the scroll bars
			//  flash visible.  Do something about that.
		}
	}
	//m_list.SetRedraw(TRUE);
	//m_list.Invalidate();
}

bool CSaveModifiedItemsDialog::ConstructDialogResource(void)
{
// For a smaller dialog:
//IDD_SAVEMODIFIEDFILES DIALOGEX 0, 0, 262, 114
//STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | 
//    WS_SYSMENU | WS_THICKFRAME
//EXSTYLE WS_EX_CONTROLPARENT
//CAPTION "Save Modified Files"
//FONT 8, "MS Shell Dlg", 400, 0, 0x1
//BEGIN
//    LTEXT           "Do you want to save changes to the modified files?",
//                    IDC_STATIC,7,7,180,8
//    CONTROL         "",IDC_LIST_FILES,"SysListView32",LVS_REPORT | 
//                    LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | 
//                    WS_TABSTOP,7,20,248,66
//    DEFPUSHBUTTON   "&Yes",IDYES,95,93,50,14
//    PUSHBUTTON      "&No",IDNO,150,93,50,14
//    PUSHBUTTON      "Cancel",IDCANCEL,205,93,50,14
//END

// The dialog template we'll use:
//IDD_SAVEMODIFIEDFILES DIALOGEX 0, 0, 300, 150
//STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | 
//    WS_SYSMENU | WS_THICKFRAME
//EXSTYLE WS_EX_CONTROLPARENT
//CAPTION "Save Modified Files"
//FONT 8, "MS Shell Dlg", 400, 0, 0x1
//BEGIN
//    LTEXT           "Do you want to save changes to the modified files?",
//                    IDC_STATIC,7,7,180,8
//    CONTROL         "",IDC_LIST_FILES,"SysListView32",LVS_REPORT | 
//                    LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | 
//                    WS_TABSTOP,7,20,286,102
//    DEFPUSHBUTTON   "&Yes",IDYES,133,129,50,14
//    PUSHBUTTON      "&No",IDNO,188,129,50,14
//    PUSHBUTTON      "Cancel",IDCANCEL,243,129,50,14
//END

	DynamicDialog::DynamicDialogItemSize itemSizeYes, itemSizeNo, itemSizeCancel;
	DWORD visibleStyle_Cancel = 0;
	if(m_canCancel)
	{
		itemSizeYes.Set(133,129,50,14);
		itemSizeNo.Set(188,129,50,14);
		itemSizeCancel.Set(243,129,50,14);

		visibleStyle_Cancel = WS_VISIBLE;
	}
	else
	{
		itemSizeYes.Set(188,129,50,14);
		itemSizeNo.Set(243,129,50,14);
		itemSizeCancel.Set(243,129,50,14);
	}

	bool success = m_dynamicDialogTemplate.Create(
		300, 150,
		(WS_POPUP | WS_CAPTION | WS_CLIPCHILDREN | WS_SYSMENU | WS_THICKFRAME | DS_3DLOOK | DS_SETFONT),
		WS_EX_CONTROLPARENT,
		L"Save Modified Items", L"MS Shell Dlg", 8);

	if(success)
	{
		// Header text
		m_dynamicDialogTemplate.AddStaticControl(
			(WS_CHILD | WS_VISIBLE | WS_GROUP | SS_LEFT), 0,
			7,7,180,8, (WORD)IDC_STATIC, L"Do you want to save changes to these modified items?");

		// List of items
		m_dynamicDialogTemplate.AddControl(
			(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER |
			LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER), 0,
			7,20,286,102, _IDC_LIST, L"", L"SysListView32");

		// Yes, No, Cancel buttons
		m_dynamicDialogTemplate.AddButtonControl(
			(WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON), 0,
			itemSizeYes, IDYES, L"&Yes");
		m_dynamicDialogTemplate.AddButtonControl(
			(WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON), 0,
			itemSizeNo, IDNO, L"&No");
		m_dynamicDialogTemplate.AddButtonControl(
			(WS_CHILD | visibleStyle_Cancel | WS_TABSTOP | BS_PUSHBUTTON), 0,
			itemSizeCancel, IDCANCEL, L"Cancel");
	}

	return success;
}

bool CSaveModifiedItemsDialog::InitializeControls(void)
{
	//m_list = this->GetDlgItem(_IDC_LIST);
	m_list.SubclassWindow(this->GetDlgItem(_IDC_LIST));
	m_header = m_list.GetHeader();
	// For now, don't allow full drag or drag drop
	m_header.ModifyStyle((HDS_FULLDRAG | HDS_DRAGDROP), 0);

	// NOTE: See MSDN about custom drawing as to this message.
	//  This avoids getting the text clipped if we change the font
	//  during custom drawing.
	m_list.SendMessage(CCM_SETVERSION, 5, 0);

	// NOTE: Instead of using LVS_EX_CHECKBOXES,
	//  we implement the logic ourselves, because we want
	//  to allow for a partial/indeterminate checkbox.
	//m_list.SetExtendedListViewStyle(
	//	(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT),
	//	(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT));
	m_list.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);

	m_images.Create(
		::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON),
		ILC_COLOR32 | ILC_MASK, 4, 4);
	m_list.SetImageList(m_images, LVSIL_SMALL);
	this->CreateDefaultImages();

	m_stateImages.Create(
		::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON),
		ILC_COLOR32 | ILC_MASK, 4, 4);
	m_list.SetImageList(m_stateImages, LVSIL_STATE);
	this->CreateDefaultStateImages();

	this->AutoHideUnusedColumns();

	this->InitializeColumns();

	return true;
}

bool CSaveModifiedItemsDialog::InitializeValues(void)
{
	bool success = true;

	success = this->AddItems(m_modifiedList, 0);

	return success;
}

bool CSaveModifiedItemsDialog::InitializeColumns(void)
{
	CRect rcList;
	m_list.GetClientRect(&rcList);

	int nameWidth = 0;
	int descriptionWidth = 0;
	int lastModifiedWidth = 0;

	if(!m_showColumn[eColumn_Description] && !m_showColumn[eColumn_LastModified])
	{
		nameWidth = rcList.Width();
	}
	else if(!m_showColumn[eColumn_Description])
	{
		nameWidth = ::MulDiv(rcList.Width(), 75, 100);
		lastModifiedWidth = rcList.Width() - nameWidth;
	}
	else if(!m_showColumn[eColumn_LastModified])
	{
		nameWidth = ::MulDiv(rcList.Width(), 35, 100);
		descriptionWidth = rcList.Width() - nameWidth;
	}
	else
	{
		nameWidth = ::MulDiv(rcList.Width(), 30, 100);
		descriptionWidth = ::MulDiv(rcList.Width(), 45, 100);
		lastModifiedWidth = rcList.Width() - (nameWidth + descriptionWidth);
	}


	LVCOLUMN lvColumn = {0};
	lvColumn.mask = (LVCF_FMT | LVCF_WIDTH | LVCF_TEXT);
	lvColumn.fmt = LVCFMT_LEFT;
	lvColumn.cx = nameWidth;
	lvColumn.pszText = _T("Name");
	m_list.InsertColumn(eColumn_Name, &lvColumn);

	lvColumn.mask = (LVCF_FMT | LVCF_WIDTH | LVCF_TEXT);
	lvColumn.fmt = LVCFMT_LEFT;
	lvColumn.cx = descriptionWidth;
	lvColumn.pszText = _T("Description");
	m_list.InsertColumn(eColumn_Description, &lvColumn);

	lvColumn.mask = (LVCF_FMT | LVCF_WIDTH | LVCF_TEXT);
	lvColumn.fmt = LVCFMT_LEFT;
	lvColumn.cx = lastModifiedWidth;
	lvColumn.pszText = _T("Last Modified");
	m_list.InsertColumn(eColumn_LastModified, &lvColumn);

	return true;
}

int CSaveModifiedItemsDialog::AutoHideUnusedColumns(void)
{
	int columnsHidden = 0;
	int columnUseCount[eColumn_Count] = {0};

	this->FindUsedColumns(m_modifiedList, columnUseCount);
	for(int i=0; i<eColumn_Count; ++i)
	{
		if(columnUseCount[i] == 0 && i != (int)eColumn_Name)
		{
			++columnsHidden;
			this->HideColumn((ColumnIndex)i);
		}
	}

	return columnsHidden;
}

bool CSaveModifiedItemsDialog::FindUsedColumns(ITabbedMDIChildModifiedList* list, int columnUseCount[eColumn_Count])
{
	if(list == NULL)
	{
		return false;
	}

	bool success = true;

	long count = 0;
	list->get_Count(&count);
	for(long i=0; i<count; ++i)
	{
		ATL::CComPtr<ITabbedMDIChildModifiedItem> item;
		list->get_Item(i, &item);
		if(item)
		{
			if(m_showColumn[eColumn_Name])
			{
				ATL::CComBSTR displayName;
				item->get_DisplayName(&displayName);
				if(displayName.Length() > 0)
				{
					columnUseCount[eColumn_Name] += 1;
				}
			}
			if(m_showColumn[eColumn_Description])
			{
				ATL::CComBSTR description;
				item->get_Description(&description);
				if(description.Length() > 0)
				{
					columnUseCount[eColumn_Description] += 1;
				}
			}
			if(m_showColumn[eColumn_LastModified])
			{
				DATE lastModified = 0;
				item->get_LastModifiedUTC(&lastModified);
				if(lastModified != 0)
				{
					columnUseCount[eColumn_LastModified] += 1;
				}
			}

			ATL::CComPtr<ITabbedMDIChildModifiedList> subItems;
			item->get_SubItems(&subItems);
			if(subItems)
			{
				this->FindUsedColumns(subItems, columnUseCount);
			}
		}
	}

	return success;
}

bool CSaveModifiedItemsDialog::AddItems(ITabbedMDIChildModifiedList* list, int indent)
{
	if(list == NULL)
	{
		return false;
	}

⌨️ 快捷键说明

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