OverwriteStatus.cpp
上传用户:hngjqc
上传日期:2007-01-02
资源大小:25k
文件大小:6k
- // OverwriteStatus.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Overwrite.h"
- #include "ChildFrm.h"
- #include "OverwriteStatus.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // COverwriteStatus
- COverwriteStatus::COverwriteStatus()
- {
- VERIFY(m_ctlImage.Create(IDB_INFO,16,0,RGB(255,0,255)));
- m_nImageFlag = 0;
- }
- COverwriteStatus::~COverwriteStatus()
- {
- }
- BEGIN_MESSAGE_MAP(COverwriteStatus, CStatusBar)
- //{{AFX_MSG_MAP(COverwriteStatus)
- ON_WM_LBUTTONDBLCLK()
- ON_WM_DRAWITEM()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // COverwriteStatus message handlers
- //////////////////////////////////////////////////////////////////
- //
- // Method: PreCreateWindow
- //
- // Function: Activate tool tips, no grip in the corner
- //
- // Parameter: CREATESTRUCT&
- //
- // Return: BOOL
- //
- BOOL COverwriteStatus::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style &= ~SBARS_SIZEGRIP;
- EnableToolTips(TRUE);
- return CStatusBar::PreCreateWindow(cs);
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: GetPaneAtPosition
- //
- // Function: Send the message to the frame, who decide, what to do
- //
- // Parameter: CPoint Point, where the double click occures
- //
- // Return: void
- //
- int COverwriteStatus::GetPaneAtPosition(CPoint& point)
- {
- CRect rect;
- for (int i = 0, n = GetCount(); i < n; i++)
- {
- GetItemRect(i, rect);
- if (rect.PtInRect(point)) return i;
- }
- return -1;
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: OnLButtonDblClk
- //
- // Function: Send the message to the frame, who decide, what to do
- //
- // Parameter: UINT nFlgs
- // CPoint Point, where the doubpe click occures
- //
- // Return: void
- //
- void COverwriteStatus::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- int nPane = GetPaneAtPosition(point);
- switch (nPane)
- {
- case 2:
- ChangeInsert();
- break;
- case 3:
- ChangeCapsLock();
- break;
- case 4:
- ChangeNumLock();
- break;
- case 5:
- {
- SetStatusBarFlag(1);
- ((COverWriteApp * )AfxGetApp())->OnAppAbout();
- SetStatusBarFlag(0);
- }
- break;
- }
- CStatusBar::OnLButtonDblClk(nFlags, point);
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: SetStatusBarFlag()
- //
- // Function: Set a new bitmap in the status bar
- //
- // Parameter: int Index of the imagelist for the events
- //
- // Return: void
- //
- void COverwriteStatus::SetStatusBarFlag(int nFlag)
- {
- CStatusBarCtrl& sbc = GetStatusBarCtrl();
- sbc.SetIcon(5, m_ctlImage.ExtractIcon(nFlag));
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: ChangeNumLock()
- //
- // Function: Change the state of the numLock key
- //
- // Parameter:
- //
- // Return: void
- //
- void COverwriteStatus::ChangeNumLock()
- {
- // Simulate a key press
- keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY , 0 );
- // Simulate a key release
- keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: ChangeCapsLock()
- //
- // Function: Change the state of the CapsLock key
- //
- // Parameter:
- //
- // Return: void
- //
- void COverwriteStatus::ChangeCapsLock()
- {
- // Simulate a key press
- keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
- // Simulate a key release
- keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: ChangeInsert()
- //
- // Function: Change the state of the insert key
- //
- // Parameter:
- //
- // Return: void
- //
- void COverwriteStatus::ChangeInsert()
- {
- keybd_event( VK_INSERT, 0x0, KEYEVENTF_EXTENDEDKEY , 0 );
- keybd_event( VK_INSERT, 0x0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- }
- //////////////////////////////////////////////////////////////////
- //
- // Method: DrawItem
- //
- // Function: Draw the specific pane of the status bar
- //
- // Parameter: LPDRAWITEMSTRUCT
- //
- // Return: void
- //
- void COverwriteStatus::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CDC dc;
- dc.Attach(lpDrawItemStruct->hDC);
- CRect cRect(&lpDrawItemStruct->rcItem);
- int nOldBkMode = dc.SetBkMode(TRANSPARENT);
- // Show only the animation, if the selected measure is identical with the running Id
- COLORREF cOldFgColor = dc.GetTextColor();
- COLORREF cTxColor = RGB(0,0,0);
- switch(lpDrawItemStruct->itemID)
- {
- case 2: // Insert/Overwrite
- {
- if (((CChildFrame *)GetParent())-> IsOverwrite ()) cTxColor = RGB(0,0,0);
- // This method can only be used, if there is only one Edit-Window
- // if ( ::GetKeyState(VK_INSERT) & 0x0001) cTxColor = RGB(0,0,0);
- else cTxColor = RGB(128,128,128);
- break;
- }
- case 3: // Caps-Lock
- {
- if ( ::GetKeyState(VK_CAPITAL) & 0x0001) cTxColor = RGB(0,0,0);
- else cTxColor = RGB(128,128,128);
- break;
- }
- case 4: // Num-Lock
- {
- if ( ::GetKeyState(VK_NUMLOCK) & 0x0001) cTxColor = RGB(0,0,0);
- else cTxColor = RGB(128,128,128);
- break;
- }
- }
- dc.SetTextColor(cTxColor);
- CString cText = GetPaneText(lpDrawItemStruct->itemID);
- dc.DrawText(cText,cRect, DT_LEFT);
- dc.SetTextColor(cOldFgColor);
- dc.SetBkMode(nOldBkMode);
- dc.Detach();
- }