本篇文章属于《518超市播音软件开发日志》系列文章的一部分。
我在开发《518超市播音软件》(http://www.518boyin.com/)的时候,在一个音乐播放列表里面,需要一个打开文件所在文件夹的功能,经过研究,下面的代码还可以。

 

static void do_openFileLocation()
{
	int idx = ListView_GetNextItem(try_hLv, -1, LVNI_SELECTED);
	if (idx < 0) {
		MessageBox(try_hDlg, L"打开所在文件夹 - 请先选中音乐", g_title, MB_OK | MB_ICONINFORMATION);
		return;
	}

	if (PathFileExists(try_musics[idx].file))
	{
		WCHAR params[MAX_PATH + 64] = { 0 };
		swprintf(params, L"/select,%s", try_musics[idx].file);
		g_app.MyShellExecute(NULL, L"open", L"explorer.exe", params, NULL, SW_NORMAL);
		return;
	}

	WCHAR folder[MAX_PATH] = { 0 };
	wcscpy(folder, try_musics[idx].file);
	PathRemoveFileSpec(folder);
	if (PathIsDirectory(folder))
		g_app.MyShellExecute(NULL, L"open", folder, NULL, NULL, SW_NORMAL);
	else
	{
		WCHAR msg[MAX_MSG] = { 0 };
		swprintf(msg, L"音乐不存在:\n%s", try_musics[idx].file);
		MessageBox(try_hDlg, msg, g_title, MB_OK | MB_ICONWARNING);
	}

}