Solved

Bitmap on statusbarPane

Posted on 1998-02-08
9
838 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
Comment Utility
You should override CStatusBarCtrl::DrawItem function.
0
 

Author Comment

by:Amaresh080997
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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 …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

11 Experts available now in Live!

Get 1:1 Help Now