Skip to content

Commit

Permalink
Issues spotted by static code analysis
Browse files Browse the repository at this point in the history
1) Some header files were not needed
2) Added initalizer lists (compiles in older versions of Visual Studio unlike initialization in declarations)
3) Added a number of 'explicit', 'static' and 'const' specifiers
4) Corrected format specificifiers in PLACEMENT_FMT

Other issues.
1) It would be safer to use CWnd::FromHandlePermanent() instead of CWnd::FromHandle()
2) In ResizableLayout::CalcNewChildPosition()  pass flags by pointer instead of by reference - simplifies code.
3) In ResizableGrip create and destroy m_wndGrip automatically. Otherwise debug buids failed in CResizableGrip::UpdateSizeGrip()
  • Loading branch information
irwir committed Jul 23, 2016
1 parent f83f3c9 commit 900bedc
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 149 deletions.
17 changes: 9 additions & 8 deletions ResizableLib/ResizableComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static char THIS_FILE[] = __FILE__;
// CResizableComboBox

CResizableComboBox::CResizableComboBox()
: m_rectDropDown(), m_iExtent(0)
{
m_bClipMaxHeight = TRUE;
m_bIntegralHeight = TRUE;
Expand All @@ -49,10 +50,10 @@ END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CResizableComboBox message handlers

HBRUSH CResizableComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH CResizableComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);

if (nCtlColor == CTLCOLOR_LISTBOX)
{
if (!(GetStyle() & CBS_SIMPLE)
Expand All @@ -69,7 +70,7 @@ HBRUSH CResizableComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
return hbr;
}

LRESULT CResizableComboBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CResizableComboBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
Expand Down Expand Up @@ -110,7 +111,7 @@ void CResizableComboBox::InitHorizontalExtent()
CFont* pOldFont = dc.SelectObject(GetFont());

CString str;

m_iExtent = 0;
int n = GetCount();
for (int i=0; i<n; i++)
Expand Down Expand Up @@ -144,16 +145,16 @@ void CResizableComboBox::UpdateHorizontalExtent(LPCTSTR szText)
dc.SelectObject(pOldFont);
}

void CResizableComboBox::PreSubclassWindow()
void CResizableComboBox::PreSubclassWindow()
{
ASSERT(GetStyle() & CBS_NOINTEGRALHEIGHT);

InitHorizontalExtent();

GetDroppedControlRect(&m_rectDropDown);
::MapWindowPoints(NULL, GetSafeHwnd(),
(LPPOINT)&m_rectDropDown, 2);

CComboBox::PreSubclassWindow();
}

Expand All @@ -167,7 +168,7 @@ int CResizableComboBox::MakeIntegralHeight(const int height)

if (!m_bIntegralHeight || n == 0)
return inth;

if (dwStyle & CBS_OWNERDRAWVARIABLE)
{
inth = 0; // try to reach availh by integral steps
Expand Down
17 changes: 9 additions & 8 deletions ResizableLib/ResizableComboLBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static char THIS_FILE[] = __FILE__;
// CResizableComboLBox

CResizableComboLBox::CResizableComboLBox()
: m_nHitTest(0), m_pOwnerCombo(NULL)
{
m_dwAddToStyle = WS_THICKFRAME;
m_dwAddToStyleEx = 0;//WS_EX_CLIENTEDGE;
Expand Down Expand Up @@ -56,7 +57,7 @@ END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CResizableComboLBox message handlers

void CResizableComboLBox::PreSubclassWindow()
void CResizableComboLBox::PreSubclassWindow()
{
CWnd::PreSubclassWindow();

Expand Down Expand Up @@ -90,7 +91,7 @@ void CResizableComboLBox::InitializeControl()
SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE);
}

void CResizableComboLBox::OnMouseMove(UINT nFlags, CPoint point)
void CResizableComboLBox::OnMouseMove(UINT nFlags, CPoint point)
{
CPoint pt = point;
MapWindowPoints(NULL, &pt, 1); // to screen coord
Expand Down Expand Up @@ -136,7 +137,7 @@ void CResizableComboLBox::OnMouseMove(UINT nFlags, CPoint point)
SWP_NOACTIVATE|SWP_NOZORDER|nCopyFlag);
}

void CResizableComboLBox::OnLButtonDown(UINT nFlags, CPoint point)
void CResizableComboLBox::OnLButtonDown(UINT nFlags, CPoint point)
{
CPoint pt = point;
MapWindowPoints(NULL, &pt, 1); // to screen coord
Expand All @@ -156,7 +157,7 @@ void CResizableComboLBox::OnLButtonDown(UINT nFlags, CPoint point)
CWnd::OnLButtonDown(nFlags, point);
}

void CResizableComboLBox::OnLButtonUp(UINT nFlags, CPoint point)
void CResizableComboLBox::OnLButtonUp(UINT nFlags, CPoint point)
{
CWnd::OnLButtonUp(nFlags, point);

Expand Down Expand Up @@ -217,7 +218,7 @@ LRESULT CResizableComboLBox::OnNcHitTest(CPoint point)
return ht;
}

void CResizableComboLBox::OnCaptureChanged(CWnd *pWnd)
void CResizableComboLBox::OnCaptureChanged(CWnd *pWnd)
{
EndSizing();

Expand All @@ -232,7 +233,7 @@ void CResizableComboLBox::EndSizing()
m_sizeAfterSizing = rect.Size();
}

void CResizableComboLBox::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
void CResizableComboLBox::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if (!m_bSizing)
{
Expand All @@ -245,13 +246,13 @@ void CResizableComboLBox::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
CWnd::OnWindowPosChanging(lpwndpos);
}

void CResizableComboLBox::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
void CResizableComboLBox::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
// default implementation sends a WM_SIZE message
// that can change the size again to force integral height

// since we do that manually during resize, we should also
// update the horizontal scrollbar
// update the horizontal scrollbar
SendMessage(WM_HSCROLL, SB_ENDSCROLL, 0);

GetWindowRect(&m_pOwnerCombo->m_rectDropDown);
Expand Down
2 changes: 1 addition & 1 deletion ResizableLib/ResizableComboLBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CResizableComboLBox : public CWnd, public CResizableGrip
virtual CWnd* GetResizableWnd() const
{
// make the layout know its parent window
return CWnd::FromHandle(m_hWnd);
return CWnd::FromHandlePermanent(m_hWnd);
};

// Generated message map functions
Expand Down
6 changes: 3 additions & 3 deletions ResizableLib/ResizableDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class CResizableDialog : public CDialog, public CResizableLayout,
// Construction
public:
CResizableDialog();
CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);
CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);
explicit CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);
explicit CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);

// Attributes
private:
Expand Down Expand Up @@ -79,7 +79,7 @@ class CResizableDialog : public CDialog, public CResizableLayout,
virtual CWnd* GetResizableWnd() const
{
// make the layout know its parent window
return CWnd::FromHandle(m_hWnd);
return CWnd::FromHandlePermanent(m_hWnd);
};

// Generated message map functions
Expand Down
8 changes: 4 additions & 4 deletions ResizableLib/ResizableFormView.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class CResizableFormView : public CFormView, public CResizableLayout,

// Construction
protected: // must derive your own class
CResizableFormView(UINT nIDTemplate);
CResizableFormView(LPCTSTR lpszTemplateName);
explicit CResizableFormView(UINT nIDTemplate);
explicit CResizableFormView(LPCTSTR lpszTemplateName);
virtual ~CResizableFormView();

private:
void PrivateConstruct();

// support for temporarily hiding the grip
DWORD m_dwGripTempState;
enum GripHideReason // bitmask
Expand All @@ -62,7 +62,7 @@ class CResizableFormView : public CFormView, public CResizableLayout,
virtual CWnd* GetResizableWnd() const
{
// make the layout know its parent window
return CWnd::FromHandle(m_hWnd);
return CWnd::FromHandlePermanent(m_hWnd);
};


Expand Down
2 changes: 1 addition & 1 deletion ResizableLib/ResizableFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CResizableFrame : public CFrameWnd, public CResizableMinMax,
virtual CWnd* GetResizableWnd() const
{
// make the layout know its parent window
return CWnd::FromHandle(m_hWnd);
return CWnd::FromHandlePermanent(m_hWnd);
};

private:
Expand Down
39 changes: 20 additions & 19 deletions ResizableLib/ResizableGrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ static char THIS_FILE[]=__FILE__;
CResizableGrip::CResizableGrip()
{
m_nShowCount = 0;
m_wndGrip = new CSizeGrip();
}

CResizableGrip::~CResizableGrip()
{

m_wndGrip->DestroyWindow();
delete m_wndGrip;
}

void CResizableGrip::UpdateSizeGrip()
{
if (!::IsWindow(m_wndGrip.m_hWnd))
if (!::IsWindow(m_wndGrip->m_hWnd))
return;

// size-grip goes bottom right in the client area
Expand All @@ -52,11 +54,11 @@ void CResizableGrip::UpdateSizeGrip()
RECT rect;
GetResizableWnd()->GetClientRect(&rect);

rect.left = rect.right - m_wndGrip.m_size.cx;
rect.top = rect.bottom - m_wndGrip.m_size.cy;
rect.left = rect.right - m_wndGrip->m_size.cx;
rect.top = rect.bottom - m_wndGrip->m_size.cy;

// must stay below other children
m_wndGrip.SetWindowPos(&CWnd::wndBottom, rect.left, rect.top, 0, 0,
m_wndGrip->SetWindowPos(&CWnd::wndBottom, rect.left, rect.top, 0, 0,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREPOSITION
| (IsSizeGripVisible() ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
}
Expand Down Expand Up @@ -106,12 +108,12 @@ void CResizableGrip::SetSizeGripVisibility(BOOL bVisible)

BOOL CResizableGrip::SetSizeGripBkMode(int nBkMode)
{
if (::IsWindow(m_wndGrip.m_hWnd))
if (::IsWindow(m_wndGrip->m_hWnd))
{
if (nBkMode == OPAQUE)
m_wndGrip.SetTransparency(FALSE);
m_wndGrip->SetTransparency(FALSE);
else if (nBkMode == TRANSPARENT)
m_wndGrip.SetTransparency(TRUE);
m_wndGrip->SetTransparency(TRUE);
else
return FALSE;
return TRUE;
Expand All @@ -121,25 +123,25 @@ BOOL CResizableGrip::SetSizeGripBkMode(int nBkMode)

void CResizableGrip::SetSizeGripShape(BOOL bTriangular)
{
if (::IsWindow(m_wndGrip.m_hWnd))
m_wndGrip.SetTriangularShape(bTriangular);
if (::IsWindow(m_wndGrip->m_hWnd))
m_wndGrip->SetTriangularShape(bTriangular);
}

BOOL CResizableGrip::CreateSizeGrip(BOOL bVisible /*= TRUE*/,
BOOL bTriangular /*= TRUE*/, BOOL bTransparent /*= FALSE*/)
{
// create grip
CRect rect(0 , 0, m_wndGrip.m_size.cx, m_wndGrip.m_size.cy);
BOOL bRet = m_wndGrip.Create(WS_CHILD | WS_CLIPSIBLINGS
CRect rect(0 , 0, m_wndGrip->m_size.cx, m_wndGrip->m_size.cy);
BOOL bRet = m_wndGrip->Create(WS_CHILD | WS_CLIPSIBLINGS
| SBS_SIZEGRIP, rect, GetResizableWnd(), 0);

if (bRet)
{
// set options
m_wndGrip.SetTriangularShape(bTriangular);
m_wndGrip.SetTransparency(bTransparent);
m_wndGrip->SetTriangularShape(bTriangular);
m_wndGrip->SetTransparency(bTransparent);
SetSizeGripVisibility(bVisible);

// update position
UpdateSizeGrip();
}
Expand All @@ -155,15 +157,15 @@ BOOL CResizableGrip::CSizeGrip::IsRTL()
return GetExStyle() & WS_EX_LAYOUTRTL;
}

BOOL CResizableGrip::CSizeGrip::PreCreateWindow(CREATESTRUCT& cs)
BOOL CResizableGrip::CSizeGrip::PreCreateWindow(CREATESTRUCT& cs)
{
// set window size
m_size.cx = GetSystemMetrics(SM_CXVSCROLL);
m_size.cy = GetSystemMetrics(SM_CYHSCROLL);

cs.cx = m_size.cx;
cs.cy = m_size.cy;

return CScrollBar::PreCreateWindow(cs);
}

Expand All @@ -188,7 +190,6 @@ LRESULT CResizableGrip::CSizeGrip::WindowProc(UINT message,
return HTBOTTOMLEFT;
else
return HTBOTTOMRIGHT;
break;

case WM_SETTINGCHANGE:
{
Expand Down Expand Up @@ -249,7 +250,7 @@ LRESULT CResizableGrip::CSizeGrip::WindowProc(UINT message,
m_dcGrip.SetBkColor(m_dcGrip.GetPixel(0, 0));
m_dcMask.BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcGrip, 0, 0, SRCCOPY);
m_dcGrip.BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcMask, 0, 0, 0x00220326);

// draw transparently
pDC->BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcMask, 0, 0, SRCAND);
pDC->BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcGrip, 0, 0, SRCPAINT);
Expand Down
5 changes: 3 additions & 2 deletions ResizableLib/ResizableGrip.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
/*!
* long_description
*/
class CResizableGrip
class CResizableGrip
{
private:
class CSizeGrip : public CScrollBar
{
public:
CSizeGrip()
: m_size()
{
m_bTransparent = FALSE;
m_bTriangular = FALSE;
Expand All @@ -65,7 +66,7 @@ class CResizableGrip
CBitmap m_bmGrip, m_bmMask;
};

CSizeGrip m_wndGrip; // grip control
CSizeGrip *m_wndGrip; // grip control
int m_nShowCount; // support for hiding the grip

protected:
Expand Down
Loading

0 comments on commit 900bedc

Please sign in to comment.