关于在对话框中增加状态栏的问题。

mazee 2001-07-25 09:44:49
我在对话框中增加了一个状态栏,但是在创建后总是要我重载CStatusBarCtrl::DrawItem函数,我不知道该如何重载它,我的代码大概如下
class CMyDlg : public CDialog
{
// Construction
public:
CMyDlg(CWnd* pParent = NULL); // standard constructor
CStatusBarCtrl m_StatBar;

...................................
......................................
}

// Microsoft Developer Studio generated include file.
#define IDM_ABOUTBOX 0x0010
#define IDC_STATUSBAR 32500
.....................................
...................................
......................................


在CMyDlg::OnInitDialog() 中增加如下代码
int nTotWide; // total width of status bar

CRect rect;
this->GetWindowRect(&rect);
rect.top = rect.bottom- 25;
m_bRvStatOk = m_StatBar.Create(WS_CHILD | WS_BORDER | WS_VISIBLE ,rect,this,
IDC_STATUSBAR);

if (m_bRvStatOk == NULL)
{
AfxMessageBox ("Status Bar not created!", NULL, MB_OK );
}

CRect rWin;
this->GetWindowRect(&rWin);
nTotWide = rWin.right-rWin.left;

m_Widths[0] = nTotWide / 4;
m_Widths[1] = nTotWide / 2;
m_Widths[2] = nTotWide - m_Widths[0];
m_Widths[3] = -1;

m_StatBar.SetMinHeight(25);
m_StatBar.SetParts( 4, m_Widths);


m_StatBar.SetText("WITH BORDER.", 0,0);
m_StatBar.SetText("WITHOUT BORDER.",1,SBT_NOBORDERS);
m_StatBar.SetText("POPUP.",2,SBT_POPOUT);

m_StatBar.SetText(NULL,3, SBT_OWNERDRAW);

hBmp = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));

并重载下面函数
void CMyDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{

//
// Draw bitmap in status bar
//

HDC hdcMem; // device context for memory
HGDIOBJ hbmOld; // old bitmap area we're over-writing
BITMAP bm; // bitmap we're using

//
// Create a compatible DC in memory
//

hdcMem = CreateCompatibleDC(lpDrawItemStruct->hDC);
// Select the "logo.bmp" bitmap into the DC.
hbmOld = ::SelectObject(hdcMem, hBmp);
// Get the size of the bitmap
::GetObject(hBmp, sizeof(bm), &bm);
// Blt the bitmap to the part.

BitBlt(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.top, bm.bmWidth, bm.bmHeight,
hdcMem, 0, 0,SRCCOPY);


//
// Add some text..1st. get bounding rectangle, then position & display text
//

char szText[16];
RECT rText; // text rectangle
rText.left = lpDrawItemStruct->rcItem.left+24;
rText.top = lpDrawItemStruct->rcItem.top;
rText.right = lpDrawItemStruct->rcItem.right-20;
rText.bottom = lpDrawItemStruct->rcItem.bottom;

//
// add some text after the logo bitmap here
//

memset(szText,0,sizeof(szText));
strcpy(szText,"LOGO"); // text to draw

SelectObject( lpDrawItemStruct->hDC, GetStockObject( ANSI_VAR_FONT ) );
::SetBkColor(lpDrawItemStruct->hDC, 0x00c0c0c0); // set background color
ExtTextOut(lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.left+24, lpDrawItemStruct->rcItem.top+4, ETO_OPAQUE, &rText, szText,
strlen(szText),NULL ); // draw the text in the rectangle rText

//
// End adding text. Reselect the original object into the DC.
//

SelectObject(hdcMem, hbmOld);
// Delete the compatible DC.
DeleteDC(hdcMem);
}
编译完全通过,不过执行时到

void CStatusBarCtrl::DrawItem(LPDRAWITEMSTRUCT)
{
ASSERT(FALSE); // must override for self draw status bars
}
时出错,提示需要我重载该函数。
...全文
74 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ahphone 2001-07-25
  • 打赏
  • 举报
回复
http://www.codeguru.com/dialog/toolbars.shtml
ahphone 2001-07-25
  • 打赏
  • 举报
回复
太长,没看明白,请你先去这个地方看看,我不想贴代码:
http://www.codeguru.com/dialog/GirishStatusBar.shtml
mazee 2001-07-25
  • 打赏
  • 举报
回复
为什么没有人答复呢?

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧