Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bitmap on statusbarPane

Posted on 1998-02-08
9
Medium Priority
?
879 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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 60 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

916 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