Solved

Bitmap on statusbarPane

Posted on 1998-02-08
9
857 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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: 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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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