Solved

CStatusBar and the CBRS_TOP style...

Posted on 1998-12-01
7
950 Views
Last Modified: 2013-11-20
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).
0
Comment
Question by:stefanr
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:migel
Comment Utility
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
 
LVL 3

Author Comment

by:stefanr
Comment Utility
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
 
LVL 1

Expert Comment

by:Fargo
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:stefanr
Comment Utility
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
 
LVL 3

Author Comment

by:stefanr
Comment Utility
Adjusted points to 200
0
 
LVL 1

Accepted Solution

by:
Fargo earned 200 total points
Comment Utility
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
 
LVL 3

Author Comment

by:stefanr
Comment Utility
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Smart Camera scanning and reading information 3 86
bigDiff challenge 17 74
Fibonacci challenge 11 82
Thin secure Windows 10 5 46
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now