Solved

Bitmap on statusbarPane

Posted on 1998-02-08
9
841 Views
Last Modified: 2013-11-19
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_STATUS,
      ID_INDICATOR_TRENDING,
      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
Regards
Amaresh
0
Comment
Question by:Amaresh080997
9 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1315759
You should override CStatusBarCtrl::DrawItem function.
0
 

Author Comment

by:Amaresh080997
ID: 1315760
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
Regards
Amaresh
0
 
LVL 2

Expert Comment

by:igroove
ID: 1315761
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.
0
 

Author Comment

by:Amaresh080997
ID: 1315762
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
Regards
Amaresh
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:cmay062697
ID: 1315763
Try it this way:
DrawItem is thr rigth function to override
void CMyStatusBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    switch(lpDrawItemStruct->itemID)
    {
    case 1:
        // Attach to a CDC object
        CDC dc;
        dc.Attach(lpDrawItemStruct->hDC);

        // 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
        srcDC.CreateCompatibleDC(NULL);
        CBitmap* pOldBitmap = srcDC.SelectObject(&Bitmap);
        dc.BitBlt(rect.left, rect.top,rect.Width(),rect.Height(),
                  &srcDC, 0, 0, SRCCOPY); // BitBlt to pane rect
        srcDC.SelectObject(pOldBitmap);

        // Detach from the CDC object, otherwise the hDC will be
        // destroyed when the CDC object goes out of scope
        dc.Detach();

        return;
    }

    CStatusBar::DrawItem(lpDrawItemStruct);
}

0
 

Author Comment

by:Amaresh080997
ID: 1315764
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
Amaresh

0
 

Expert Comment

by:cmay062697
ID: 1315765
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.

NOT FOR AN CStatusBar OBJECT!!
Regards
CMAY
0
 

Author Comment

by:Amaresh080997
ID: 1315766
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
Amaresh
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 30 total points
ID: 1315767
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.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 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

21 Experts available now in Live!

Get 1:1 Help Now