OSDN Git Service

Update CWindowsManagerDialog - check some pointers for null and made … (#824)
authorFlaviu_ <37621568+flaviu22@users.noreply.github.com>
Sun, 13 Jun 2021 12:35:39 +0000 (15:35 +0300)
committerGitHub <noreply@github.com>
Sun, 13 Jun 2021 12:35:39 +0000 (21:35 +0900)
* Update CWindowsManagerDialog - check some pointers for null and made safe casts

* Update WindowsManagerDialog.cpp

Src/WindowsManagerDialog.cpp

index 6f2791b..857ba81 100644 (file)
@@ -115,15 +115,18 @@ void CWindowsManagerDialog::PopulateList()
        const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* pArrChild = m_pFrame->GetChildArray();
        for (int i = 0; i < pArrChild->GetSize(); ++i)
        {
-               HICON hIcon = pArrChild->GetAt(i)->GetIcon(TRUE);
+               sText.Empty();
+               HICON hIcon = pArrChild->GetAt(i)->GetIcon(FALSE);
                if (NULL == hIcon)
                        hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
                m_pIL->Add(hIcon);
-               sText = pArrChild->GetAt(i)->GetActiveDocument()->GetPathName();
-               if(sText.IsEmpty())
+               const CDocument* pDoc = pArrChild->GetAt(i)->GetActiveDocument();
+               if (nullptr != pDoc)
+                       sText = pDoc->GetPathName();
+               if (sText.IsEmpty())
                        pArrChild->GetAt(i)->GetWindowText(sText);
                m_List.InsertItem(i, sText, m_pIL->GetImageCount() - 1);
-               m_List.SetItemData(i, (DWORD_PTR)pArrChild->GetAt(i));
+               m_List.SetItemData(i, reinterpret_cast<DWORD_PTR>(pArrChild->GetAt(i)));
        }
 }
 // adjust size to listctrl column and dialog
@@ -223,7 +226,7 @@ void CWindowsManagerDialog::OnDestroy()
 
        const int nIndex = m_List.GetNextItem(-1, LVNI_SELECTED);
        if (nIndex >= 0 && nIndex < m_List.GetItemCount())
-               ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEACTIVATE, 0, (LPARAM)m_List.GetItemData(nIndex));
+               ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEACTIVATE, 0, static_cast<LPARAM>(m_List.GetItemData(nIndex)));
 }
 
 LRESULT CWindowsManagerDialog::OnIsOpen(WPARAM wParam, LPARAM lParam)