CStatusBar and the CBRS_TOP style...

Is it possible to use the CBRS_TOP style when creating a CStatusBar? In this case in a MDI child frame window. It seems to be no way of getting rid of the grip, which is unnecessary and even ugly used with the CBRS_TOP style. I have tried to create an overloaded CStatusBar::Create member function to prevent the function to add the SBARS_SIZEGRIP style when creating the status bar, but it is a hack, and I'm not sure if it is allowed since someone said that the consequences of removing the SBARS_SIZEGRIP style could be terrible (even though I haven't seen any yet).
LVL 3
stefanrAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
FargoConnect With a Mentor Commented:
OK, you have to use the overloaded CStatusBar::Create function(without calling the base class' Create function) in order to "get rid" of the sizing grip. Here's some code... It's simillar to your CStatusBar2::Create function but differs a little bit => I don't set the SBARS_SIZEGRIP if the window border is a "thick frame type" (take a look at your func).

Here's the Create function - I tested it, and it works...

BOOL CStatusBar2::Create(CWnd* pParentWnd, DWORD dwStyle /*= WS_CHILD | WS_VISIBLE | CBRS_BOTTOM*/, UINT nID /*= AFX_IDW_STATUS_BAR*/)
{
   ASSERT_VALID(pParentWnd);   // must have a parent

   // save the style (some of these style bits are MFC specific)
   m_dwStyle = (UINT)dwStyle;

   // translate MFC style bits to windows style bits
   dwStyle &= ~CBRS_ALL;
   dwStyle |= CCS_NOPARENTALIGN|CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE;

   //Here was the code setting the sizing grip style.
   //I just removed it...

   // initialize common controls
   VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));

   // create the HWND
   CRect rect;
   rect.SetRectEmpty();
   return CWnd::Create(STATUSCLASSNAME, NULL, dwStyle, rect, pParentWnd, nID);
}

Like I said in my previous answer - you have nothing to worry about, when removing the sizing grip style.

Good luck!
Fargo
0
 
migelCommented:
CBRS_SIZEGRIP added automaticlly by CreateEx functionof CStatusBar class if parent window have WS_THICKFRAME style. So, I think that best way is overload PreCreateWindow and modify styles (dwStyle &= ~CBRS_SIZEGRIP) after calling CStatusBar::PreCreateWindow(...)
If it will not work try override OnCreate (WM_CREATE message handler) and call ModifyStyle();
0
 
stefanrAuthor Commented:
I tried both of your suggestions. Strangely enough, none of my overrided PreCreateWindow or OnCreate was called. Only the overrided Create member function was called, like before. And why is there no way to tell the CStatusBar itself to not add the SBARS_SIZEGRIP style? So I don't have to override at all? Is it because there is something dangerous about it? Here is my code that tested your suggestions:

class CStatusBar2 : public CStatusBar
{
      DECLARE_DYNAMIC(CStatusBar2)

public:
   CStatusBar2() { }
   virtual ~CStatusBar2() { }
   BOOL Create(CWnd* pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, UINT nID = AFX_IDW_STATUS_BAR);

protected:
   virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

   //{{AFX_MSG(CStatusBar)
   afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
};

-----xxxx-----
/*
#define AFX_WND_REG             (0x0001)
#define AFX_WNDCONTROLBAR_REG   (0x0002)
#define AFX_WNDMDIFRAME_REG     (0x0004)
#define AFX_WNDFRAMEORVIEW_REG  (0x0008)
#define AFX_WNDCOMMCTLS_REG     (0x0010)
#define AFX_WNDOLECONTROL_REG   (0x0020)

#define AfxDeferRegisterClass(fClass) \
      ((afxRegisteredClasses & fClass) ? TRUE : AfxEndDeferRegisterClass(fClass))

extern BOOL AFXAPI AfxEndDeferRegisterClass(short fClass);
*/

IMPLEMENT_DYNAMIC(CStatusBar2, CStatusBar)

BOOL CStatusBar2::Create(CWnd* pParentWnd, DWORD dwStyle /*= WS_CHILD | WS_VISIBLE | CBRS_BOTTOM*/, UINT nID /*= AFX_IDW_STATUS_BAR*/)
{
   /*ASSERT_VALID(pParentWnd);   // must have a parent

   // save the style (some of these style bits are MFC specific)
   m_dwStyle = (UINT)dwStyle;

   // translate MFC style bits to windows style bits
   dwStyle &= ~CBRS_ALL;
   dwStyle |= CCS_NOPARENTALIGN|CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE;
   if ((pParentWnd->GetStyle() & WS_THICKFRAME) && CBRS_BOTTOM == (dwStyle & CBRS_BOTTOM))
      dwStyle |= SBARS_SIZEGRIP;

   // initialize common controls
   VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));

   // create the HWND
   CRect rect; rect.SetRectEmpty();
   return CWnd::Create(STATUSCLASSNAME, NULL, dwStyle, rect, pParentWnd, nID);*/

   return CStatusBar::Create(pParentWnd, dwStyle, nID);
}

BOOL CStatusBar2::PreCreateWindow(CREATESTRUCT& cs)
{
   cs.style &= ~LONG(SBARS_SIZEGRIP);

   return CStatusBar::PreCreateWindow(cs);
}

BEGIN_MESSAGE_MAP(CStatusBar2, CStatusBar)
      //{{AFX_MSG_MAP(CStatusBar2)
      ON_WM_CREATE()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

int CStatusBar2::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CStatusBar::OnCreate(lpCreateStruct) == -1)
      return -1;

   ModifyStyle(SBARS_SIZEGRIP, 0);

   return 0;
}

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
FargoCommented:
Stefanr, here is some info that (I think) will be in help:

The CStatusBar class is not so important when speaking of sizing grips. This class wraps the Win32 common control, represented in MFC by the class CStatusBarCtrl. This is the REAL status bar control and you should apply the style ~SBARS_SIZEGRIPS to it, not to its container - CStatusBar.
Here's a way I recommend:
In your child frame's OnCreate (where the status bar is created), after you create the CStatusBar window include the next piece of code:
.....
.....
  CStatusBarCtrl *pSCtl = &(m_wndStatusBar.GetStatusBarCtrl());
  pSCtl->ModifyStyle(SBARS_SIZEGRIP,0);
.....
.....

For your fears that "something terrible" will happen if you remove the SIZEGRIP style => you have nothing to worry about. The official MS documentation for the status bar control states that "combining the CCS_TOP and SBARS_SIZEGRIP styles is not recommended, because the resulting sizing grip is not functional even though the system draws it in the status window".
As you can see, not only you can remove that style, but it is recommended to remove it.

Hope I ws help,
Fargo
0
 
stefanrAuthor Commented:
Thank you, but that didn't help. I really thought that this would work, but it seems that when the CStatusBar(Ctrl) window is created, changing its style doesn't matter. The grip is still there, despite the fact that the style is changed. I did this at the end of "CChildFrame"::OnCreate:

CStatusBarCtrl* pCtrl = &(m_wndStatusBar.GetStatusBarCtrl());
LONG lStyle = ::GetWindowLong(pCtrl->GetSafeHwnd(), GWL_STYLE);
if (!pCtrl->ModifyStyle(SBARS_SIZEGRIP, 0))
{
   return -1;
}
LONG lNewStyle = ::GetWindowLong(pCtrl->GetSafeHwnd(), GWL_STYLE);
LONG lDiff = (lStyle ^ lNewStyle);

I can see that the style is changed, but it doesn't matter for what is actually happening with the status bar at all.

I Microsoft recommends that the SBARS_SIZEGRIP style is removed, why can't it be done?
0
 
stefanrAuthor Commented:
Adjusted points to 200
0
 
stefanrAuthor Commented:
OK, I'll take your word for that it is harmless to remove this annoying style. Still, I had hoped that I didn't have to overload CStatusBar at all. The Create function I used was directly copied from the MFC source, with my addition of the CBRS_BOTTOM style check. Whatever way, it works now. Thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.