For favorites of Internet Explorer, two common problems are to call the "Sort favorites" dialog box and "add to Favorites" dialog box. There are many calling methods, but some of them are worth discussing.
Keywords: Add to favorites, organize favorites, doaddtofavdlg, doorganizefavdlg
1, Sort favorites
Calling the "Sort favorites" dialog box (as shown below) basically uses the same method, that is, calling"Shdocvw. dll"In"Doorganizefavdlg"Function to pass in the parent window handle and favorites path as parameters.
2,Code
The code example is as follows. It is worth noting that the processing of "shdocvw. dll" should be checked first to avoid repeated calls.
Void cmyhtmlview: onfavorganizefav ()
{
Typedef uint (callback * lpfnorgfav) (hwnd, lptstr );
Bool bresult = false;
Hmodule hmod =: getmodulehandle (_ T ("shdocvw. dll "));
If (hmod = NULL) // If "shdocvw. dll" is not loaded, load it
{
Hmod =: loadlibrary (_ T ("shdocvw. dll "));
If (hmod = NULL)
{< br> MessageBox (_ T (" the dynamic link library shdocvw. DLL cannot be found. "),
_ T (" error "), mb_ OK | mb_iconstop);
return;
}< br> lpfnorgfav lpfndoorganizefavdlg = (lpfnorgfav)
: getprocaddress (hmod, "doorganizefavdlg");
If (lpfndoorganizefavdlg = NULL)
{
MessageBox (_ T ("the entry point doorganizefavdlg cannot be found/N ")
_ T ("in the dynamic link library shdocvw. dll ."),
_ T ("error"), mb_ OK | mb_iconstop );
Return;
}
Tchar szpath [max_path];
Hresult hr;
HR =: shgetspecialfolderpath (m_hwnd, szpath, csidl_favorites, true );
If (failed (HR ))
{
MessageBox (_ T ("The path of the favorites folder cannot be found ."),
_ T ("error"), mb_ OK | mb_iconstop );
Return;
}
Bresult = (* lpfndoorganizefavdlg) (m_hwnd, szpath )? True: false;
: Freelibrary (hmod );
}
Else // If "shdocvw. dll" is already in the caller's process address space, it is used directly.
{
Lpfnorgfav lpfndoorganizefavdlg = (lpfnorgfav)
: Getprocaddress (hmod, "doorganizefavdlg ");
If (lpfndoorganizefavdlg = NULL)
{
MessageBox (_ T ("the entry point doorganizefavdlg cannot be found/N ")
_ T ("in the dynamic link library shdocvw. dll ."),
_ T ("error"), mb_ OK | mb_iconstop );
Return;
}
Tchar szpath [max_path];
Hresult hr;
HR =: shgetspecialfolderpath (m_hwnd, szpath, csidl_favorites, true );
If (failed (HR ))
{
MessageBox (_ T ("The path of the favorites folder cannot be found ."),
_ T ("error"), mb_ OK | mb_iconstop );
Return;
}
Bresult = (* lpfndoorganizefavdlg) (m_hwnd, szpath )? True: false;
}
Return;
}
3, Discussion
In fact,Doorganizefavdlg"Function prototype Declaration we can see that because a path is required, the" Sort favorites "dialog box can be used not only to sort favorites, but also to sort the directories on the disk. In addition, the so-called organization is convenient to provide a dialog box for users, and there is no substantial difference between it and the arrangement in the resource manager directly. Therefore, call the "Sort favorites" dialog box fromIe4.0It has not changed since the beginning, except that the layout of the dialog box has changed.
Typedef uint (callback * lpfnorgfav) (hwnd, lptstr );
IE 4.0"Sort favorites" dialog box
IE 4.0"Sort favorites" dialog box (original design)
"Add to Favorites" is different. The "doaddtofavdlg" function is no longer like"Doorganizefavdlg"Functions are the same for allIE.
References:
Msdn:Adding Internet Explorer favorites to your application
Reference address: Internet Explorer programming Overview (3) "organizing favorites" dialog box