Second, implement the collection menu
General IE users have a habit, that is, save your favorite URL, so that the future is fast login, in order to make our browser to display the URL collected by IE, a "Favorites" menu is set in the program. To operate the HKEY_CURRENT_USER / / SOFTWARE // Microsoft // Windows // USER SHELL Folders item in Windows // Explorer // USER SHELL Folders entry in Windows // Explorer // User Shell Folders items, and displays the collected URLs on the menu. To this end, the author defines two functions and implements the code as follows:
Tchar getdir () // Get the directory of the user collection site; {tchar sz [max_path]; tchar szpath [max_path]; hkey hkey; dWord dwsize; cmenu * pmenu; // Get the "Favorites" menu, and delete blank son Menu item; pmenu = getMenu () -> getSubmenu (3); while (pmenu-> deletemenu (0, mf_byposition)); // Find out from the registry where the favorage is located.if (REGOPENKEY (HKEY_CURRENT_USER, _T (" Software // Microsoft // Windows // CurrentVersion // Explorer // User Shell Folders ")") "), & HKEY)! = Error_suCcess) {trace0 (" Favorites Folder Not Found / N); Return 0;} DWSIZE = SizeOf (SZ) ; RegQueryValueEx (hKey, _T ( "Favorites"), NULL, NULL, (LPBYTE) sz, & dwSize); ExpandEnvironmentStrings (sz, szPath, MAX_PATH); RegCloseKey (hKey); Return szPath} int CMainFrame :: BuildFavoritesMenu (LPCTSTR pszPath, int nStartPos, CMenu * pMenu) {CString strPath (pszPath); CString strPath2; CString str; WIN32_FIND_DATA wfd; HANDLE h; int nPos; int nEndPos; int nNewEndPos; int nLastDir; TCHAR buf [INTERNET_MAX_PATH_LENGTH]; CStringArray astrFavorites; CStringArray astrDirs; CMenu * psubmenu; if (strpath [strpath.getLength () - 1]! = _T ('//') StrPath = _t ('//'); strpath2 = strpath; strpath = "*. *"; // Scan the current directory, first search the * .url file, then the subdirectory that may contain the * .url file; h = FindFirstFile (strPath, & wfd); if (h = INVALID_HANDLE_VALUE!) {nEndPos = nStartPos; do {if ((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) == 0) {str = wfd.cFileName; if ( Str.right (4) ==_t (". URL") {/ * URL file and INI file format, so we can use getPrivateProfileString () to get the information we need.
* / :: getPrivateProfileString ("InternetshShortcut"), T ("URL"), _ T (""), buf, internet_max_path_length, str = str.Left (Str.getLength () - 4); / / Decision has been repeated; for (NPOS = NStartPos; NPOS
// call this function recursively.nNewEndPos = BuildFavoritesMenu (strPath2 wfd.cFileName, nEndPos, pSubMenu); if (nNewEndPos = nEndPos!) {// Insert submenu; nEndPos = nNewEndPos; pMenu-> InsertMenu (nPos, MF_BYPOSITION | MF_POPUP | Mf_string, (uint) psubmenu-> m_hmenu, wfd.cfilename); psubmenu-> detach (); astrdirs.insertat (npos, wfd.cfilename); NLASTDIR;} delete psubmenu;}} while (FindnextFile (h, & wfd); FindClose (H);} returnned nendpos;
Third, show hypertext
The NaviGate2 function of the Microsoft ChtmView class can realize the display of hypertext files, and functions such as GOBACK (), goforward () can realize the rollback and advancement of web browsing. In response to the "Favorite" menu item as an example, you need to add a message to the CMAINFRAME class of the program to map ON_COMMAND_RANGE (0xE00, 0xFFF, ONFAVORITE), and message response function onfavorite, to respond to the menu within the range of 0xE00-0xFFF, specifically The implementation code is as follows: void cmainframe :: onfavorite (uint nid) {((cmyieview *) getActiveView ()) -> navigate2 (m_astrfavoriteurls [nid-0xe00], 0, null;}
Fourth, small knot
The above code is relatively, if the use of some functions is unclear, please refer to MSDN, which contains the advanced interface processing, the operation of the registry, maybe it is very difficult, but if the reader is fine If the taste of the taste, you can learn something, help the interface development of future procedures.