CString CMy601DemoClientView::GetConfigIniFile()
{
	CString strFileName;
	AfxGetModuleFileName(NULL,strFileName);
	strFileName = strFileName.Left(strFileName.GetLength() -3);
	strFileName  += "ini";
	return strFileName;

}
示例#2
0
void CJumpListTab::UpdateRegistration(BOOL isRegister)
{
    CString params;
    
    CString applicationPath;
    AfxGetModuleFileName(0, applicationPath);
    
    params.Format(L"%s \"%s\" \"%s\" \"%s\" %s %s", 
        isRegister ? L"TRUE" : L"FALSE",
        L"Microsoft.Samples.TaskbarDemo", // ProgId
        applicationPath, // Path
        L"TaskbarDemo Document", // friendly doc name
        L"TaskbarDemo.AppID.1.0.0.0", // Taskbar AppUserModeID
        L".jpg"); // extensions
 
    CString shortFileNameParam;    
    AfxGetModuleShortFileName(0, shortFileNameParam);

    CString exeFileName = applicationPath;
    exeFileName.Replace(L"TaskbarDemo.exe", L"RegistrationHelper.exe");

    SHELLEXECUTEINFO shex;

    memset( &shex, 0, sizeof( shex) );

    shex.cbSize         = sizeof( SHELLEXECUTEINFO );
    shex.fMask          = 0;
    shex.hwnd           = this->GetSafeHwnd();
    shex.lpVerb         = _T("runas");
    shex.lpFile         = exeFileName;
    shex.lpParameters   = params;
    shex.lpDirectory    = _T(".");
    shex.nShow          = SW_NORMAL;

    ::ShellExecuteEx( &shex );
}
示例#3
0
void CHexFileList::SetupJumpList()
{
#if _MFC_VER >= 0x0A00  // earlier versions of MFC do not support CJumpList
	CJumpList jumpList;

	if (!jumpList.InitializeList()) return;
	int maxSlots = jumpList.GetMaxSlots();

	// We need to get three list, the total size of which adds up to maxSlots (or less):
	// recent files: just the last n files of the recent file list
	// frequent files: the files that have been opened the most (using the open_count_ array)
	//   - we use a priority queue that stores the most frequently opened files
	//   - note that the "highest" priority are the least frequently opened so we can pop them off the top
	// favorite: the last n files that have CATEGORY of favorite or favourite
	//   - we just store these in a vector and stop when we have enough
	// Note that we build the recent and frequent lists ourselves, rather than relying on
	// KDC_RECENT and KDC_FREQUENT so we know what file extensions need to be registered.

	// This class is a functor used to compare elements added to the frequency priority queue
	class freq_compare
	{
	private:
		CHexFileList *pfl;
	public:
		freq_compare(CHexFileList *pfl): pfl(pfl) { }
		bool operator() (const int &lhs, const int &rhs) const
		{
			return pfl->GetOpenedCount(lhs) > pfl->GetOpenedCount(rhs);
		}
	};
	// This stores the first "favourite" files found
	std::vector<int> fav;
	// This stores the files that have been opened the most
	typedef std::priority_queue<int, std::vector<int>, freq_compare> freq_type;
	freq_type freq(freq_compare(this));

	for (int ii = name_.size() - 1; ii >= 0; ii--)
	{
		if (open_count_[ii] <= 1)
		{
			// We don't consider that a single open is "frequent"
		}
		else if (freq.size() < maxSlots/3)  // fill up to 1/3 of total slots available
		{
			freq.push(ii);
		}
		else if (open_count_[ii] > open_count_[freq.top()])
		{
			// First get rid of all the lowest frequency elements
			// Note: This can result in the size of freq dropping unexpectedly (eg: from 10 to 1) if
			//       there are a large number of files with the same open count. This is NOT a bug.
			int lowest = open_count_[freq.top()];
			while (freq.size() > 0 && open_count_[freq.top()] == lowest)
			{
				freq.pop();
			}
			freq.push(ii);
		}

		if (fav.size() < maxSlots/2)      // may fill up to 1/2 of all slots available
		{
			CString ss = GetData(ii, CATEGORY);
			if (ss.CompareNoCase("Favourites") == 0 || ss.CompareNoCase("Favorites") == 0)
				fav.push_back(ii);
		}
	}

	// work out how many of each to use
	int numFreq = freq.size(), numFav = fav.size();
	ASSERT(numFreq <= maxSlots/3);
	if (numFreq + numFav > (2*maxSlots)/3)         // make sure freq + fav is not more than 2/3 of total
		numFav = (2*maxSlots)/3 - numFreq;
	int numRecent = maxSlots - numFreq - numFav;
	if (numRecent > name_.size())
		numRecent = name_.size();

	ASSERT(numRecent + numFreq + numFav <= maxSlots);

	// Make sure we are associated with the extensions of all the files we are adding to the jump list
	CaseInsensitiveSet ext;

	// Get extensions of recent files
	for (int ii = name_.size() - 1; ii >= (int)name_.size() - numRecent; ii--)
	{
		ext.insert(CString(::PathFindExtension(name_[ii])));
	}

	// Get extensions of frequently opened files
	freq_type temp = freq;
	while (temp.size() > 0)
	{
		ext.insert(CString(::PathFindExtension(name_[temp.top()])));
		temp.pop();
	}

	// Get extensions of favourite files
	for (int ii = 0; ii < fav.size(); ++ii)
	{
		ext.insert(CString(::PathFindExtension(name_[fav[ii]])));
	}

	// Check if appid or exe name is wrong in "HKCR\HexEdit.file"
	bool need_reg = false;
	HKEY hkey;

	// Check that our "file" registry setting is present in the registry and APPID is correct
    if (RegOpenKeyEx(HKEY_CLASSES_ROOT,
	                 CString(CHexEditApp::ProgID), 
	                 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS)
	{
		need_reg = true;  // HexEdit file registry setting is not present
	}
	else
	{
		char buf[1024];
		DWORD len = sizeof(buf)-1;
		CString ss = theApp.m_pszAppID;
		if (RegQueryValueEx(hkey, "AppUserModelID", NULL, NULL, (LPBYTE)buf, &len) != ERROR_SUCCESS ||
			ss.CompareNoCase(buf) != 0)
		{
			need_reg = true;   // command line setting is not present or it is using a different .exe
		}
        RegCloseKey(hkey);
	}

	if (!need_reg)
	{
		// Also check that command setting is present and points to our .exe
		if (RegOpenKeyEx(HKEY_CLASSES_ROOT,
						 CString(CHexEditApp::ProgID) + "\\shell\\open\\command", 
						 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS)
		{
			need_reg = true;  // HexEdit file command setting is not present
		}
		else
		{
			char buf[1024];
			DWORD len = sizeof(buf)-1;
			CString ss;
			AfxGetModuleFileName(0, ss);   // new in MFC 10?
			ss += " %1";
			if (RegQueryValueEx(hkey, NULL, NULL, NULL, (LPBYTE)buf, &len) != ERROR_SUCCESS ||
				ss.CompareNoCase(buf) != 0)
			{
				need_reg = true;   // command line setting is not present or it is using a different .exe
			}
			RegCloseKey(hkey);
		}
	}

	// Put all extensions (that have yet to be registered) into a string for RegisterExtensions
	CString strExt;
	for (CaseInsensitiveSet::const_iterator pext = ext.begin(); pext != ext.end(); ++pext)
	{
        if (RegOpenKeyEx(HKEY_CLASSES_ROOT, *pext + "\\OpenWithProgids", 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS &&
			!pext->IsEmpty() )
		{
			strExt += *pext + "|";
			need_reg = true;
		}
		else
		{
			if (RegQueryValueEx(hkey, CHexEditApp::ProgID, NULL, NULL, NULL, NULL) != ERROR_SUCCESS &&
				!pext->IsEmpty() )
			{
				strExt += *pext + "|";
				need_reg = true;
			}
			RegCloseKey(hkey);
		}
	}

	static const char * explanation =
		"\nJump Lists were introduced with Windows 7. They are lists of items that are "
		"quickly accessed by right-clicking the HexEdit icon on the Task Bar. HexEdit "
		"supports lists of most recently opened items, frequently opened items, and "
		"those that you mark as favorites.\n\n"
		"However, for jump lists to work the type(s) of the files in the jump lists "
		"must be registered as \"openable\" with HexEdit. To associate the above file "
		"types with HexEdit requires starting a separate application with Administrator "
		"privileges in order to add registry setting for all users.\n\n"
		"When prompted please select \"Yes\" in the User Account Control window.";

	// Only fire up reghelper if need to register something (need_reg is true)
	// (ie, there are extensions to register OR the appid or exe path is wrong)
	if (need_reg && !strExt.IsEmpty())
	{
		CString strTmp = strExt;
		strTmp.Replace("|", "   ");
		if (AvoidableTaskDialog(IDS_REG_REQUIRED,
		                        "To use jump lists HexEdit needs to register some file types.\n\n"
		                           "Do you wish to associate HexEdit with these files extensions?\n\n"
								   + strTmp,
								explanation,
								"File Registration",
		                        TDCBF_YES_BUTTON | TDCBF_NO_BUTTON) != IDYES ||
			!theApp.RegisterExtensions(strExt))
		{
			// There is no point in doing anything else if we could not register the file extensions since
			// even jump list categories KDC_RECENT and KDC_FREQUENT require the extensions to be registered.
			return;
		}

		// TODO: xxx We need keep track of all extensions we have registered in a reg string
		//       xxx so we can unregister them all if necessary.  (Perhaps this can be done in 
		//       xxx RegHelper.exe, so we know if we added the .ext or just the OpenWithProgids entry)
	}
	else if (need_reg)
	{
		if (AvoidableTaskDialog(IDS_REG_REQUIRED,
		                        "Should HexEdit modify some global registry settings?\n\n",
								explanation,
								"Registry Settings",
		                        TDCBF_YES_BUTTON | TDCBF_NO_BUTTON) == IDYES)
		{
			theApp.RegisterExtensions("");  // set up registry settings without registering any file extensions
			return;                         // no need to 
		}
	}

	// Add the 3 types of files to the task list
	CString strCategory;

	if (theApp.is_us_)
		strCategory = "Favorites";
	else
		strCategory = "Favourites";
	for (int ii = 0; ii < numFav; ++ii)
		jumpList.AddDestination(strCategory, name_[fav[ii]]);

//#define USE_KNOWN_CATEGORIES 1
#ifdef USE_KNOWN_CATEGORIES
	jumpList.AddKnownCategory(KDC_FREQUENT);
	jumpList.AddKnownCategory(KDC_RECENT);
#else
	strCategory = "Frequent Files";
	for (temp = freq; temp.size() > 0; temp.pop())
		jumpList.AddDestination(strCategory, name_[temp.top()]);

	strCategory = "Recent Files";
	for (int ii = name_.size() - 1; ii >= (int)name_.size() - numRecent; ii--)
		jumpList.AddDestination(strCategory, name_[ii]);
#endif

	jumpList.CommitList();
#endif // _MFC_VER >= 0x0A00
}