MyStatusBar.cpp
上传用户:szcysw
上传日期:2013-03-11
资源大小:6752k
文件大小:4k
- // BitmapStatusBar.cpp : implementation file
- #include "stdafx.h"
- #include "MyStatusBar.h"
- #include "resource.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- ////////////////////////////////////////////////////////////////////////////
- // CMyStatusBar
- CMyStatusBar::CMyStatusBar()
- {
- }
- CMyStatusBar::~CMyStatusBar()
- {
- }
- //事件响应申明
- BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)
- //{{AFX_MSG_MAP(CMyStatusBar)
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_CBN_SELCHANGE(IDC_COMBOX, OnSelchangeCombo)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyStatusBar message handlers
- //对鼠标的左键击键信息进行响应
- void CMyStatusBar::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CRect rect;
- //得到大小写字母锁定区域的索引值
- int cap=this->CommandToIndex(ID_INDICATOR_CAPS);
- //得到数字锁定区域的索引值
- int num=this->CommandToIndex(ID_INDICATOR_NUM);
- //得到大小写字母锁定区域的索引值
- int scrl=this->CommandToIndex(ID_INDICATOR_SCRL);
- //分别得到三个区域的区域范围
- CRect capRect,numRect,scrlRect;
- this->GetItemRect(cap,&capRect);
- this->GetItemRect(num,&numRect);
- this->GetItemRect(scrl,&scrlRect);
- //查看当前鼠标位置正位于哪个区域
- if(capRect.PtInRect(point))
- {
- //进行一次虚拟"Caps Lock"按下的操作
- SimulateHitKey(VK_CAPITAL);
- AfxMessageBox("已经进行了字母大小写切换!");
- }
- if(numRect.PtInRect(point))
- {
- //进行一次虚拟"NUM Lock"按下的操作
- SimulateHitKey(VK_NUMLOCK);
- AfxMessageBox("已经进行了数字键锁定切换!");
- }
-
- if(scrlRect.PtInRect(point))
- {
- //进行一次虚拟"SCR LOCK"按下的操作
- SimulateHitKey(VK_SCROLL);
- AfxMessageBox("已经进行了屏幕滚动切换!");
- }
-
- //单击左键停止播放
- if (::IsWindow(m_AnimateCtrl))
- m_AnimateCtrl.Play(0,0,0);
- CStatusBar::OnLButtonDown(nFlags, point);
- }
- void CMyStatusBar::OnRButtonDown(UINT nFlags, CPoint point)
- {
- //单击右键开始播放
- CRect rect;
- if (::IsWindow(m_AnimateCtrl))
- m_AnimateCtrl.Play(0,-1,-1);
- CStatusBar::OnRButtonDown(nFlags, point);
- }
- int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
-
- if (CStatusBar::OnCreate(lpCreateStruct) == -1)
- return -1;
- CRect rect,rect2;
- //建立组合列表框控件
- m_ComboBox.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWNLIST,CRect(120,0,240,120),this,IDC_COMBOX);
- CString tmp;
- //在组合列表框控件中添加选项
- for(int i=0;i<10;i++)
- {
- tmp.Format(">列表项%d<",i);
- m_ComboBox.AddString(tmp);
- }
- //设置当前选项
- m_ComboBox.SetCurSel(0);
- //如果m_AnimateCtrl还没有被建立
- if (!::IsWindow(m_AnimateCtrl))
- {
- //建立AVI播放控件
- m_AnimateCtrl.Create(WS_CHILD |WS_VISIBLE,rect,this,469456);
- m_AnimateCtrl.Open(IDR_AVI1);
- m_AnimateCtrl.GetClientRect(rect);
- //得到父窗口的宽度
- this->GetParent()->GetWindowRect(&rect2);
- rect.right=rect2.Width()/2;
- rect.left=rect.right-100;
- //让m_AnimateCtrl居中
- m_AnimateCtrl.MoveWindow(&rect);
- //开始循环播放
- m_AnimateCtrl.Play(0,-1,-1);
- }
- return 0;
- }
- //当工具条的大小发生改变时,让m_AnimateCtrl居中
- void CMyStatusBar::OnSize(UINT nType, int cx, int cy)
- {
- CStatusBar::OnSize(nType, cx, cy);
- CRect rect,rect2;
- m_AnimateCtrl.GetClientRect(&rect);
- if (::IsWindow(m_AnimateCtrl))
- {
- this->GetParent()->GetClientRect(&rect2);
- rect.right=rect2.Width()/2;
- rect.left=rect.right-100;
- m_AnimateCtrl.MoveWindow(&rect);
- }
- }
- //组合列表框内容发生变化时调用:
- void CMyStatusBar::OnSelchangeCombo()
- {
- CString m_text;
- int sel=m_ComboBox.GetCurSel();
- this->m_ComboBox.GetLBText(sel,m_text);
- AfxMessageBox("你选择的内容是----"+m_text);
- }
- //虚拟击键操作:nVirtualKey为键值码
- void CMyStatusBar::SimulateHitKey(int nVirtualKey)
- {
- //按下
- keybd_event(nVirtualKey,0x45,0,0 );
- Sleep(100);
- //释放
- keybd_event(nVirtualKey,0x45,KEYEVENTF_KEYUP,0);
- }