1.可能是为了方便吧(照顾不同的使用习惯)
2.应该是在程序的执行退出GetDlgItem()所在的模块时释放。
CWnd::GetDlgItem
CWnd* GetDlgItem( int nID ) const;void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;Return ValueA pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL. The returned pointer may be temporary and should not be stored for later use. ----from MSDN
2.应该是在程序的执行退出GetDlgItem()所在的模块时释放。
CWnd::GetDlgItem
CWnd* GetDlgItem( int nID ) const;void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;Return ValueA pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL. The returned pointer may be temporary and should not be stored for later use. ----from MSDN
CHistoryCurve::GetDlgItems()
{
//得到各控件对象的指针
int i,j;
for(i=1;i<=12;i++)
m_pRadios[i]=(CButton*) GetDlgItem(IDC_HISTORY_CURVE_RADIO_01-1+i);
for(j=1;j<=10;j++)
m_pChecks[j]=(CButton*) GetDlgItem(IDC_HISTORY_CURVE_CHECK_01-1+j);}
CWinApp::OnIdle负责清除所有临时句柄映射。
如果代码没有执行到CWinApp::OnIdle,则此映射有效,否则……
之所以要定义一个智能指针类,主要的原因是简化COM编程,这样可以屏蔽许多COM中繁琐却必须的细节,例如AddRef、ReleaseRef;可以将多个接口封装在同一个类中,向用户屏蔽这些接口的区别,提供一种统一访问的手段。
另外,除了->操作符外,智能指针还重载了许多其他的操作符,例如*,&等等。潘爱民翻译的《COM技术内幕》一书中有比较详细的描述。