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

📄 mainwin.cpp

📁 fastcopy是一个非常快速的数据拷贝软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		return	TRUE;

	case SRC_FILE_BUTTON:
		BrowseDirDlgV(this, SRC_COMBO, GetLoadStrV(IDS_SRC_SELECT), BRDIR_VQUOTE|BRDIR_FILESELECT);
		return	TRUE;

	case DST_FILE_BUTTON:
		BrowseDirDlgV(this, DST_COMBO, GetLoadStrV(IDS_DST_SELECT), BRDIR_BACKSLASH);
		return	TRUE;

	case TOPLEVEL_CHECK:
		cfg.isTopLevel = IsDlgButtonChecked(TOPLEVEL_CHECK);
		SetWindowPos(cfg.isTopLevel ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOMOVE);
		cfg.WriteIni();
		break;

	case MODE_COMBO:
		if (wNotifyCode == CBN_SELCHANGE) {
			BOOL	is_delete = GetCopyMode() == FastCopy::DELETE_MODE;
			if (is_delete && isNetPlaceSrc) {
				SetDlgItemTextV(SRC_COMBO, EMPTY_STR_V);
				isNetPlaceSrc = FALSE;
			}
			SetItemEnable(is_delete);
		}
		return	TRUE;

	case FILTER_CHECK:
		ReflectFilterCheck();
		return	TRUE;

	case OPENDIR_MENUITEM:
		::ShellExecute(NULL, NULL, cfg.execDir, 0, 0, SW_SHOW);
		return	TRUE;

	case USERDIR_MENUITEM:
		{
			char	buf[MAX_PATH];
			if (TMakeVirtualStorePath(cfg.execDir, buf)) {
				::ShellExecute(NULL, NULL, buf, 0, 0, SW_SHOW);
			}
		}
		return	TRUE;

	case SETUP_MENUITEM:
		if (setupDlg.Exec() == IDOK) {
			SetDlgItemInt(BUFSIZE_EDIT, cfg.bufSize);
			CheckDlgButton(IGNORE_CHECK, cfg.ignoreErr);
			CheckDlgButton(ESTIMATE_CHECK, cfg.estimateMode);
			SetSpeedLevelLabel(this, speedLevel = cfg.speedLevel);
			UpdateSpeedLevel();
			CheckDlgButton(OWDEL_CHECK, cfg.enableOwdel);
			CheckDlgButton(ACL_CHECK, cfg.enableAcl);
			CheckDlgButton(STREAM_CHECK, cfg.enableStream);
			isErrLog = cfg.isErrLog;
			isUtf8Log = cfg.isUtf8Log;
			isReparse = cfg.isReparse;
			skipEmptyDir = cfg.skipEmptyDir;
			forceStart = cfg.forceStart;
		}
		return	TRUE;

	case SHELLEXT_MENUITEM:
		shellExtDlg.Exec();
		return	TRUE;

	case ABOUT_MENUITEM:
		aboutDlg.Exec();
		return	TRUE;

	case FASTCOPYURL_MENUITEM:
		::ShellExecute(NULL, NULL, GetLoadStr(IDS_FASTCOPYURL), NULL, NULL, SW_SHOW);
		return	TRUE;

	case AUTODISK_MENUITEM: case SAMEDISK_MENUITEM: case DIFFDISK_MENUITEM:
		diskMode = wID - AUTODISK_MENUITEM;
		UpdateMenu();
		break;

	case IDR_DISKMODE:
		diskMode = (diskMode + 1) % 3;
		UpdateMenu();
		break;

	case JOB_MENUITEM:
		jobDlg.Exec();
		UpdateMenu();
		return	TRUE;

	case RUNAS_BUTTON: case ADMIN_MENUITEM:
		if (!fastCopy.IsStarting())
			RunAsAdmin();
		break;

	case HELP_BUTTON: case HELP_MENUITEM:
		ShowHelp(hWnd, cfg.execDir, GetLoadStr(IDS_FASTCOPYHELP), wID == HELP_BUTTON ? "#usage" : NULL);
		return	TRUE;

	default:
		if (wID >= JOBOBJ_MENUITEM_START && wID <= JOBOBJ_MENUITEM_END) {
			int idx = wID - JOBOBJ_MENUITEM_START;
			if (idx < cfg.jobMax) {
				SetJob(idx);
			}
			return TRUE;
		}
		break;
	}
	return	FALSE;
}

BOOL TMainDlg::EvSysCommand(WPARAM uCmdType, POINTS pos)
{
	switch (uCmdType)
	{
	case SC_RESTORE: case SC_MAXIMIZE:
		return	TRUE;

	case SC_MINIMIZE:
		PostMessage(WM_FASTCOPY_HIDDEN, 0, 0);
		return	TRUE;
	}
	return	FALSE;
}

BOOL TMainDlg::EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight)
{
	if (fwSizeType != SIZE_RESTORED && fwSizeType != SIZE_MAXIMIZED)
		return	FALSE;

	RefreshWindow();
	return	TRUE;
}

void TMainDlg::RefreshWindow(BOOL is_start_stop)
{
	GetWindowRect(&rect);
	int	xdiff = (rect.right - rect.left) - (orgRect.right - orgRect.left);
	int ydiff = (rect.bottom - rect.top) - (orgRect.bottom - orgRect.top) + (isErrEditHide ? normalHeight - miniHeight : 0);

	HDWP	hdwp = ::BeginDeferWindowPos(max_dlgitem);	// MAX item number
	UINT	dwFlg		= SWP_SHOWWINDOW | SWP_NOZORDER;
	UINT	dwHideFlg	= SWP_HIDEWINDOW | SWP_NOZORDER;
	DlgItem	*item;
	int		*target;
	BOOL	is_delete = GetCopyMode() == FastCopy::DELETE_MODE;

	int	slide_y[] = { errstatus_item, errstatic_item, -1 };
	for (target=slide_y; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y + ydiff, item->wpos.cx, item->wpos.cy, isErrEditHide ? dwHideFlg : dwFlg);
	}

	item = dlgItems + erredit_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y + ydiff, item->wpos.cx + xdiff, item->wpos.cy, isErrEditHide ? dwHideFlg : dwFlg);

	item = dlgItems + path_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, item->wpos.cy + ydiff, dwFlg);

	item = dlgItems + filter_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x + xdiff, item->wpos.y, item->wpos.cx, item->wpos.cy, dwFlg);

	int	harf_growslide_x[] = { exccombo_item, excstatic_item, -1 };
	for (target=harf_growslide_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x + xdiff/2, item->wpos.y, item->wpos.cx + xdiff/2, item->wpos.cy, dwFlg);
	}

	int	harf_glow_x[] = { inccombo_item, incstatic_item, -1 };
	for (target=harf_glow_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff/2, item->wpos.cy, dwFlg);
	}

	BOOL	is_exec = fastCopy.IsStarting() || isDelay;

	int	slide_x[] = { ok_item, list_item, samedrv_item, top_item, estimate_item, speed_item, speedstatic_item, ignore_item, bufedit_item, bufstatic_item, help_item, mode_item, -1 };
	for (target=slide_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x + xdiff, item->wpos.y, item->wpos.cx, item->wpos.cy,
			is_exec && (*target == list_item && !IsListing() || *target == ok_item && IsListing()) ||
			is_delete && *target == estimate_item ? dwHideFlg : dwFlg);
	}

	int	grow_x[] = { srccombo_item, dstcombo_item, -1 };
	for (target=grow_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, item->wpos.cy, dwFlg);
	}

	item = dlgItems + atonce_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, item->wpos.cy, !isDelay ? dwHideFlg : dwFlg);

	item = dlgItems + status_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, (!isDelay ? dlgItems[atonce_item].wpos.y + dlgItems[atonce_item].wpos.cy - item->wpos.y : item->wpos.cy), dwFlg);

	EndDeferWindowPos(hdwp);

	if (is_start_stop) {
		BOOL	flg = !fastCopy.IsStarting();
		::EnableWindow(dlgItems[estimate_item].hWnd, flg);
		::EnableWindow(dlgItems[ignore_item].hWnd, flg);
		::EnableWindow(dlgItems[owdel_item].hWnd, flg);
		::EnableWindow(dlgItems[acl_item].hWnd, flg);
		::EnableWindow(dlgItems[stream_item].hWnd, flg);
	}
}

void TMainDlg::SetDlgItem(UINT ctl_id, DlgItem *item)
{
	WINDOWPLACEMENT wp;
	wp.length = sizeof(wp);

	item->hWnd = GetDlgItem(ctl_id);
	::GetWindowPlacement(item->hWnd, &wp);
	item->wpos.x = wp.rcNormalPosition.left;
	item->wpos.y = wp.rcNormalPosition.top;
	item->wpos.cx = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
	item->wpos.cy = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
}

void TMainDlg::SetSize(void)
{
	SetDlgItem(SRC_FILE_BUTTON,	&dlgItems[srcbutton_item]);
	SetDlgItem(DST_FILE_BUTTON,	&dlgItems[dstbutton_item]);
	SetDlgItem(SRC_COMBO,		&dlgItems[srccombo_item]);
	SetDlgItem(DST_COMBO,		&dlgItems[dstcombo_item]);
	SetDlgItem(STATUS_EDIT,		&dlgItems[status_item]);
	SetDlgItem(MODE_COMBO,		&dlgItems[mode_item]);
	SetDlgItem(BUF_STATIC,		&dlgItems[bufstatic_item]);
	SetDlgItem(BUFSIZE_EDIT,	&dlgItems[bufedit_item]);
	SetDlgItem(HELP_BUTTON,		&dlgItems[help_item]);
	SetDlgItem(IGNORE_CHECK,	&dlgItems[ignore_item]);
	SetDlgItem(ESTIMATE_CHECK,	&dlgItems[estimate_item]);
	SetDlgItem(SPEED_SLIDER,	&dlgItems[speed_item]);
	SetDlgItem(SPEED_STATIC,	&dlgItems[speedstatic_item]);
	SetDlgItem(TOPLEVEL_CHECK,	&dlgItems[top_item]);
	SetDlgItem(LIST_BUTTON,		&dlgItems[list_item]);
	SetDlgItem(IDOK,			&dlgItems[ok_item]);
	SetDlgItem(ATONCE_BUTTON,	&dlgItems[atonce_item]);
	SetDlgItem(OWDEL_CHECK,		&dlgItems[owdel_item]);
	SetDlgItem(ACL_CHECK,		&dlgItems[acl_item]);
	SetDlgItem(STREAM_CHECK,	&dlgItems[stream_item]);
	SetDlgItem(SAMEDRV_STATIC,	&dlgItems[samedrv_item]);
	SetDlgItem(INC_STATIC,		&dlgItems[incstatic_item]);
	SetDlgItem(EXC_STATIC,		&dlgItems[excstatic_item]);
	SetDlgItem(INCLUDE_COMBO,	&dlgItems[inccombo_item]);
	SetDlgItem(EXCLUDE_COMBO,	&dlgItems[exccombo_item]);
	SetDlgItem(FILTER_CHECK,	&dlgItems[filter_item]);
	SetDlgItem(PATH_EDIT,		&dlgItems[path_item]);
	SetDlgItem(ERR_STATIC,		&dlgItems[errstatic_item]);
	SetDlgItem(ERRSTATUS_STATIC,&dlgItems[errstatus_item]);
	SetDlgItem(ERR_EDIT,		&dlgItems[erredit_item]);

	GetWindowRect(&rect);
	orgRect = rect;
}

/*
	DropFiles Event CallBack
*/
BOOL TMainDlg::EvDropFiles(HDROP hDrop)
{
	PathArray	pathArray;
	WCHAR	path[MAX_PATH_EX];
	BOOL	isDstDrop = IsDestDropFiles(hDrop);
	BOOL	isDeleteMode = GetCopyMode() == FastCopy::DELETE_MODE;
	int		max = isDstDrop ? 1 : ::DragQueryFileV(hDrop, 0xffffffff, 0, 0), max_len = 0;

	// CTL 偑墴偝傟偰偄傞応崌丄尰嵼偺撪梕傪壛嶼
	if (!isDstDrop) {
		if (::GetAsyncKeyState(VK_CONTROL) & 0x8000) {
			max_len = ::GetWindowTextLengthV(GetDlgItem(SRC_COMBO)) + 1;
			WCHAR	*buf = new WCHAR [max_len];
			GetDlgItemTextV(SRC_COMBO, buf, max_len);
			pathArray.RegisterMultiPath(buf);
			delete [] buf;
		}
		else
			isNetPlaceSrc = FALSE;
	}

	for (int i=0; i < max; i++) {
		if (::DragQueryFileV(hDrop, i, path, sizeof(path) / CHAR_LEN_V) <= 0)
			break;

		if (isDstDrop || !isDeleteMode) {
			if (NetPlaceConvertV(path, path) && !isDstDrop)
				isNetPlaceSrc = TRUE;
		}
		max_len += strlenV(path) + 3;
		pathArray.RegisterPath(path);
	}
	::DragFinish(hDrop);

	if (max_len > 0) {
		WCHAR	*buf = new WCHAR [max_len += pathArray.Num() * 2];	// 暥帤楍楢寢梡椞堟

		if (isDstDrop) {
			DWORD	attr = ::GetFileAttributesV(pathArray.Path(0));
			if (attr & FILE_ATTRIBUTE_DIRECTORY) {	// 0xffffffff 傕擣傔傞(for 95宯OS偺root懳嶔)
				MakePathV(path, pathArray.Path(0), EMPTY_STR_V);
				SetDlgItemTextV(DST_COMBO, path);
			}
		}
		else {
			if (pathArray.GetMultiPath(buf, max_len))
				SetDlgItemTextV(SRC_COMBO, buf);
		}
		delete [] buf;
	}
	return	TRUE;
}

void TMainDlg::SetPriority(DWORD new_class)
{
	if (curPriority != new_class) {
		::SetPriorityClass(::GetCurrentProcess(), curPriority = new_class);
		if (IsWinVista()) {
			::SetPriorityClass(::GetCurrentProcess(), curPriority == IDLE_PRIORITY_CLASS ? PROCESS_MODE_BACKGROUND_BEGIN : PROCESS_MODE_BACKGROUND_END);
		}
	}
}

BOOL TMainDlg::EventScroll(UINT uMsg, int Code, int nPos, HWND hwndScrollBar)
{
	speedLevel = SetSpeedLevelLabel(this);
	UpdateSpeedLevel();

	if (fastCopy.IsStarting()) {
		SetPriority(speedLevel != SPEED_FULL ? IDLE_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS);
	}

	return	TRUE;
}

FastCopy::Mode TMainDlg::GetCopyMode(void)
{
	return	COPYINFO_LIST[SendDlgItemMessage(MODE_COMBO, CB_GETCURSEL, 0, 0)].mode;
}

void TMainDlg::ReflectFilterCheck(BOOL is_invert)
{
	BOOL	is_show_filter = GetCopyMode() != FastCopy::MOVE_MODE;
	BOOL	is_checked = IsDlgButtonChecked(FILTER_CHECK);
	BOOL	new_status = (is_invert ? !is_checked : is_checked) && is_show_filter;

//	::ShowWindow(GetDlgItem(FILTER_CHECK), is_show_filter ? SW_SHOW : SW_HIDE);
//	::ShowWindow(GetDlgItem(INCLUDE_COMBO), is_show_filter ? SW_SHOW : SW_HIDE);
//	::ShowWindow(GetDlgItem(EXCLUDE_COMBO), is_show_filter ? SW_SHOW : SW_HIDE);
//	if (is_show_filter)
		CheckDlgButton(FILTER_CHECK, new_status);
	::EnableWindow(GetDlgItem(FILTER_CHECK), is_show_filter);
	::EnableWindow(GetDlgItem(INCLUDE_COMBO), new_status);
	::EnableWindow(GetDlgItem(EXCLUDE_COMBO), new_status);
}

BOOL TMainDlg::IsDestDropFiles(HDROP hDrop)
{
	POINT	pt;
	RECT	dst_rect;

	if (::DragQueryPoint(hDrop, &pt) == FALSE || ::ClientToScreen(hWnd, &pt) == FALSE)
		return	FALSE;

	if (::GetWindowRect(GetDlgItem(DST_COMBO), &dst_rect) == FALSE || PtInRect(&dst_rect, pt) == FALSE)
		return	FALSE;

	return	TRUE;
}


BOOL TMainDlg::ExecCopy(DWORD exec_flags)
{
	int		idx = SendDlgItemMessage(MODE_COMBO, CB_GETCURSEL, 0, 0);
	BOOL	is_delete_mode = COPYINFO_LIST[idx].mode == FastCopy::DELETE_MODE;
	BOOL	is_filter = IsDlgButtonChecked(FILTER_CHECK);
	BOOL	is_listing = (exec_flags & LISTING_EXEC) ? TRUE : FALSE;

	info.ignoreErr		= IsDlgButtonChecked(IGNORE_CHECK);
	info.mode			= COPYINFO_LIST[idx].mode;
	info.overWrite		= COPYINFO_LIST[idx].overWrite;
	info.isPhysLock		= IS_WINNT_V ? TRUE : FALSE;
	info.lcid			= cfg.lcid > 0 && IS_WINNT_V ? ::GetThreadLocale() : 0;
	info.flags			= cfg.copyFlags /*| FastCopy::REPORT_ACL_ERROR | FastCopy::REPORT_STREAM_ERROR */
		| (IsDlgButtonChecked(ACL_CHECK) && IS_WINNT_V ? FastCopy::WITH_ACL : 0)

⌨️ 快捷键说明

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