如何通过程序实现资源管理器的刷新功能
发布网友
发布时间:2022-04-30 04:14
我来回答
共1个回答
热心网友
时间:2023-10-11 20:04
一 最简单的办法
1.进入主键〔HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Update〕。
2.将二进制值“UpdateMode”改为“00 00 00 00”。
二 编程实现
用SHDocVw::IShellWindowsPtr来实现。
简单的核心代码:
class CAutoRefreshDlg : public CDialog
{
...........
CListCtrlm_ctrlIE;
SHDocVw::IShellWindowsPtr m_spSHWinds;
...........
};
BOOL CAutoRefreshDlg::OnInitDialog()
{
CoInitialize(NULL);
...............
if (m_spSHWinds == NULL){
if (m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) != S_OK){
MessageBox("Failed");
CoUninitialize();
EndDialog(1);
}
}
m_ctrlIE.SetExtendedStyle(LVS_EX_CHECKBOXES|LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_ctrlIE.InsertColumn(0, "IE", LVCFMT_LEFT, 500, -1);
OnButtonRefresh();
m_uTimerRefresh = SetTimer(1, m_uFreq*1000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CAutoRefreshDlg::OnButtonRefresh()
{
// TODO: Add your control notification handler code here
int n = m_ctrlIE.GetItemCount();//GetCount();
for (int i = 0; i < n; i ++){
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_ctrlIE.GetItemData(i);
if (pBrowser){
pBrowser->Release();
}
}
m_ctrlIE.DeleteAllItems();
if (m_spSHWinds){
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++){
_variant_t v = (long)i;
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser){
_bstr_t bsName = spBrowser->GetLocationName();
int nPos = m_ctrlIE.InsertItem(0, bsName);
spBrowser->AddRef();
void * pData = spBrowser;
m_ctrlIE.SetItemData(nPos, (DWORD)(pData));
}
}
}
}
void CAutoRefreshDlg::DoClose()
{
int n = m_ctrlIE.GetItemCount();//GetCount();
for (int i = 0; i < n; i ++){
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_ctrlIE.GetItemData(i);
if (pBrowser){
pBrowser->Release();
}
}
m_ctrlIE.DeleteAllItems();
if (m_spSHWinds){
m_spSHWinds.Release();
m_spSHWinds = 0;
}
CoUninitialize();
EndDialog(0);
}
void CAutoRefreshDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == 1){
int n = m_ctrlIE.GetItemCount();
for (int i = 0; i < n; i++){
if (m_ctrlIE.GetCheck(i)){
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_ctrlIE.GetItemData(i);
if (pBrowser){
pBrowser->Refresh();
}
}
}
}
CDialog::OnTimer(nIDEvent);
}