Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues spotted by static code analysis and other minor code changes #2

Merged
merged 4 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 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 All @@ -132,7 +133,7 @@ void CResizableComboBox::UpdateHorizontalExtent(LPCTSTR szText)
CClientDC dc(this);
CFont* pOldFont = dc.SelectObject(GetFont());

int cx = dc.GetTextExtent(szText, lstrlen(szText)).cx;
int cx = dc.GetTextExtent(szText, static_cast<int>(_tcslen(szText))).cx;
if (cx > m_iExtent)
{
m_iExtent = cx;
Expand All @@ -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
19 changes: 10 additions & 9 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 All @@ -170,7 +171,7 @@ LRESULT CResizableComboLBox::OnNcHitTest(CPoint point)
MapWindowPoints(NULL, &rcClient);

// ask for default hit-test value
UINT ht = CWnd::OnNcHitTest(point);
LRESULT ht = CWnd::OnNcHitTest(point);

// disable improper resizing (based on layout setting)
switch (ht)
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 @@ -58,7 +58,7 @@ class CResizableComboLBox : public CWnd, public CResizableGrip
CPoint m_ptBeforeSizing; // screen coords
CRect m_rcBeforeSizing; // screen coords
CSize m_sizeAfterSizing; // screen coords
UINT m_nHitTest; // current resize operation
LRESULT m_nHitTest; // current resize operation
BOOL m_bSizing;

void InitializeControl();
Expand Down
4 changes: 2 additions & 2 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
13 changes: 3 additions & 10 deletions ResizableLib/ResizableFormView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void CResizableFormView::OnDestroy()
LRESULT CResizableFormView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_INITDIALOG)
return (LRESULT)OnInitDialog();
return static_cast<LRESULT>(OnInitDialog());

if (message != WM_NCCALCSIZE || wParam == 0)
return CFormView::WindowProc(message, wParam, lParam);
Expand All @@ -198,7 +198,7 @@ BOOL CResizableFormView::OnInitDialog()
{
const MSG* pMsg = GetCurrentMessage();

BOOL bRet = (BOOL)CFormView::WindowProc(pMsg->message, pMsg->wParam, pMsg->lParam);
BOOL bRet = CFormView::WindowProc(pMsg->message, pMsg->wParam, pMsg->lParam) != 0;

// we need to associate member variables with control IDs
UpdateData(FALSE);
Expand All @@ -213,12 +213,5 @@ BOOL CResizableFormView::OnInitDialog()

BOOL CResizableFormView::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
{
if (!CFormView::OnNcCreate(lpCreateStruct))
return FALSE;

// create and init the size-grip
if (!CreateSizeGrip())
return FALSE;

return TRUE;
return CFormView::OnNcCreate(lpCreateStruct) && CreateSizeGrip(); // create and init the size-grip
}
6 changes: 3 additions & 3 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 Down
19 changes: 7 additions & 12 deletions ResizableLib/ResizableGrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void CResizableGrip::HideSizeGrip(DWORD* pStatus, DWORD dwMask /*= 1*/)
}
}

BOOL CResizableGrip::IsSizeGripVisible()
BOOL CResizableGrip::IsSizeGripVisible() const
{
// NB: visibility is effective only after an update
return (m_nShowCount > 0);
Expand Down Expand Up @@ -139,7 +139,7 @@ BOOL CResizableGrip::CreateSizeGrip(BOOL bVisible /*= TRUE*/,
m_wndGrip.SetTriangularShape(bTriangular);
m_wndGrip.SetTransparency(bTransparent);
SetSizeGripVisibility(bVisible);

// update position
UpdateSizeGrip();
}
Expand All @@ -155,15 +155,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 @@ -184,11 +184,7 @@ LRESULT CResizableGrip::CSizeGrip::WindowProc(UINT message,

case WM_NCHITTEST:
// choose proper cursor shape
if (IsRTL())
return HTBOTTOMLEFT;
else
return HTBOTTOMRIGHT;
break;
return IsRTL() ? HTBOTTOMLEFT : HTBOTTOMRIGHT;

case WM_SETTINGCHANGE:
{
Expand Down Expand Up @@ -249,7 +245,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 All @@ -262,7 +258,6 @@ LRESULT CResizableGrip::CSizeGrip::WindowProc(UINT message,
EndPaint(&ps);
return 0;
}
break;
}

return CScrollBar::WindowProc(message, wParam, lParam);
Expand Down Expand Up @@ -323,4 +318,4 @@ void CResizableGrip::CSizeGrip::SetTriangularShape(BOOL bEnable)
{
SetWindowRgn((HRGN)NULL, IsWindowVisible());
}
}
}
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 Down Expand Up @@ -73,7 +74,7 @@ class CResizableGrip
BOOL CreateSizeGrip(BOOL bVisible = TRUE,
BOOL bTriangular = TRUE, BOOL bTransparent = FALSE);

BOOL IsSizeGripVisible(); // TRUE if grip is set to be visible
BOOL IsSizeGripVisible() const; // TRUE if grip is set to be visible
void SetSizeGripVisibility(BOOL bVisible); // set default visibility
void UpdateSizeGrip(); // update the grip's visibility and position
void ShowSizeGrip(DWORD* pStatus, DWORD dwMask = 1); // temp show the size grip
Expand Down
Loading