Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 894
  • Last Modified:

Bitmap on statusbarPane

Hello everyone!
      I want to put bitmaps on two of my status bar panes. I have included two Ids in my mainframe.cpp file as follows:

static UINT indicators[] =
      ID_SEPARATOR,           // status line indicator
      ID_INDICATOR_ACCESS,     // Needs bitmap
      ID_INDICATOR_ALARM       // Needs bitmap
I set the style of my last two panes to "SBT_OWNERDRAWN", by calling "SetPaneStyle".
I derived a class "CMyStatusBar" from CStatusBar, and am overriding "OnDrawItem". But the control doesnt come to "OnDrawItem". The data member "m_wndStatusBar" is now a member of "CMyStatusBar". The control goes to the constructor of "CMyStatusBar", but the "OnDrawItem" is not called. Hence I am unable to put the bitmap on the status bar panes. Can any of you let me know the possible causes?
Thanks in advance
1 Solution
You should override CStatusBarCtrl::DrawItem function.
Amaresh080997Author Commented:
Hello Galkin,
      Thanks for your answer.But, I do not know what you mean by this. Do you mean to say that "CMyStatusBar" should be derived from "CStatusBarCtrl"? If yes, my variable "m_wndStatusBar" in the "mainfrm.h" will be pointing to "CStatusBarCtrl" derived class.Now, if you see the "Create" function of the status bar in the mainframe.cpp, it takes only one arguement.If I make my variable "m_wndStatusBar" point to  to  "CStatusBarCtrl", I have to change all these. The syntax fior the "Create" function is different for "CStatusBarCtrl" and "CStatusBar". Moreover, there is no "SetpaneStyle" in the CStatusBarCtrl.How do I fix the style of my last two panes to Ownerdarwn?
Kindly elaborate your answer.
Thanks in advance
You may need to do this to correctly set the owner draw style in your status bar initialization:

/*  nPane is the pane
    nStyle includes SBT_OWNERDRAW
    hBitmap is the handle to the bitmap, so when you get
    the WM_DRAWITEM message, you can just use it.  */
m_wndStatusBar.SendMessage(SB_SETTEXT, (WPARAM)(nPane | nStyle), (LPARAM)hBitmap);

The reason for this is that CStatusBar::SetPaneStyle() doesn't send the right style.  SetPaneStyle accepts the SBPS_* styles.

Hope this helps.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Amaresh080997Author Commented:
Hello Igroove,
      Thanks for your answer. I did what you have suggested, but still, the control doesnt go to "OnDrawItem".The first thing is, there is some thing called "SBPS_OWNERDRAW" declared in the "AfxExt.h". I tried using "setPaneStyle()" passing this "SBPS_OWNERDRAW".But there was no result. I implemented the method that you suggested. But that also is not working.
But, I believe, the style is set properly to Ownerdraw.The reason is, the program crashes when I set the style to owner draw, and the control goes to "DrawItem" of "Barstat.cpp". But the control doesnt come to my source code's "OnDrawItem". I do not know what is going wrong.
Kindly suggest me the way to do it.
Thanks for your answer
Try it this way:
DrawItem is thr rigth function to override
void CMyStatusBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    case 1:
        // Attach to a CDC object
        CDC dc;

        // Get the pane rectangle and calculate text coordinates
        CRect rect(&lpDrawItemStruct->rcItem);
            CBitmap Bitmap;
            Bitmap.LoadBitmap(UINT nIDResource );
        CDC srcDC; // select current bitmap into a compatible CDC
        CBitmap* pOldBitmap = srcDC.SelectObject(&Bitmap);
                  &srcDC, 0, 0, SRCCOPY); // BitBlt to pane rect

        // Detach from the CDC object, otherwise the hDC will be
        // destroyed when the CDC object goes out of scope



Amaresh080997Author Commented:
Hello Cmay,
      Thanks for your answer. But if you read my comments for the previous answer, you will understand the difficulty I am facing.My problem is, the control doesnt go to "OnDrawItem".I am doing some thing similar to your code. Only thing is, instead of BitBlt, I am using "StrtchBlt". But thats not the problem. The problem is,the program doesnt enter "OnDrawItem" function.
Please see if you can figure out what is going wrong..
Thanks and Regards

The framework calls this member function for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed.

Amaresh080997Author Commented:
Hello Cmay,
      Thanks for your answer. But the thing is, the CStatusBar is a "control". It is derived from "CStatusBarCtrl". And more over, you can set the style of a status bar pane by calling "SetPaneStyle(SBPS_OWNERDRAW)". This "SBPS_OWNERDRAW" has been "#define"ed to "SBT_OWNERDRAW" in MFC source.
So, I believe, the frame work should call "OnDrawItem". If it is not so, how do you think I can handle "OnDrawItem"? Do you mean to say that I should "SendMessage(WM_DRAWITEM)"? If so, what is "lpDrawItemStruct"?
Kindly let me know if you have the answer to these qns
Thanks and regards
Tommy HuiEngineerCommented:
OnDrawItem is called when the entire control is set to owner draw. This aplies to buttons, comboboxes, listboxes, and menu as cmay mentioned. You do not get WM_DRAWITEM messages when a scrollbar's pane is set to owner draw. For that, the status bar class has a virtual member function called DrawItem that does that. Override DrawItem and put the code in there and that will get called.

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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now