对话框中增加状态栏,并且鼠标在不同位置可以显示不同数据

王朝vc·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//---------------------------

//------本程序主要是在对话框中增加状态栏,自己绘制,主要有开始就可以显示数据

//------还可以当移动到一个控件上面,也可以在状态栏中显示数据,变化

//---------使用button 可以在程序中动态改变状态栏的中的信息

//------------本陈不都写在---- ****Dlg.cpp 文件里面,不需要其他的

//---------2005年1月6日----9:49:00----made in haerbin of china

//-----------------刘莉莉 or liulili eMail: liulili995@163.com

//-----------------------------------------------------------------------------------------

//----------------------start---------****Dlg.h file

public:

int count; //在button 点击以后,使用count传递变量,使得状态栏文字发生变化

CStatusBar m_status; //申明两个变量 状态栏

//----------------------end------------****Dlg.h file

//

//

//-----------------------start----------****Dlg.cpp file

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

// No message handlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//-----------my code--------------------------

//----for statusbar 下面的小格格个数----------

static UINT status_id[]=

{

//-------设置5个小格格

ID_SEPARATOR,

ID_SEPARATOR, //可以多个

ID_INDICATOR_CAPS, //可以没有

ID_INDICATOR_NUM, //

ID_INDICATOR_SCRL //

};

//------------------------------------

/////////////////////////////////////////////////////////////////////////////

// CMyDlg dialog

//-----------------------------------

BOOL CMyDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

this->count =0;

// IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}

}

// Set the icon for this dialog. The framework does this automatically

// when the application's main window is not a dialog

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

//-------------my code----------------------

//-----------初始化 状态栏 -----------------

if(!this->m_status.Create(this)||!this->m_status.SetIndicators(status_id,sizeof(status_id)/sizeof(UINT)))

{

return -1;

}

//-----------设置 状态兰的大小 和显示的文字-----------

UINT nID; //控制状态栏里面的小格格

//-----------设置 小格格的具体信息

//--------------第一个格格,100,大小,样式

m_status.SetPaneInfo(0,nID,SBPS_STRETCH,100);

m_status.SetPaneText(0,"Hello!,welcome");

//--------------第二个格格,100,大小,样式

m_status.SetPaneInfo(1,nID,SBPS_STRETCH,100);

m_status.SetPaneText(1,"A Gril");

m_status.SetPaneInfo(2,nID,SBPS_STRETCH,100);

m_status.SetPaneText(2,"This is Chinese");

m_status.SetPaneInfo(3,nID,SBPS_STRETCH,100);

m_status.SetPaneText(3,"1000");

//----------------让这个状态栏最终显示在对话框中-------------

RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);

//-------------------------------------------

return TRUE; // return TRUE unless you set the focus to a control

}

//-------------------------------

BOOL CMyDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)

{

// TODO: Add your message handler code here and/or call default

//-------------MY CODE---------------------

//-----------让我的鼠标移动到控件上面,就有相应的提示和变化

switch(message)

{

case WM_MOUSEMOVE:

{

if(pWnd!=this)

{

switch(pWnd->GetDlgCtrlID())

{

case IDC_EDIT1:

{

m_status.SetPaneText(0,"编辑框");

break;

}

case IDC_COMBO1:

{

{

m_status.SetPaneText(0,"组合框");

break;

}

}

case IDC_BUTTON1: //当鼠标移动到button 按钮上面的时候

{

if(this->count ==1)

{

m_status.SetPaneText(1,"你好,中国人");

break;

}

}

default:

{

m_status.SetPaneText(0,"也没有数据");

m_status.SetPaneText(1,"现在没有数据");

break;

}

}

}

}

}

//-------------------------------------------

return CDialog::OnSetCursor(pWnd, nHitTest, message);

}

//button 控制

void CMyDlg::OnButton1()

{

this->count =1;

}

//-----------------------end----------****Dlg.cpp file

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航