📄 modalarea.cpp
字号:
// ModalArea.cpp : implementation file
//
#include "stdafx.h"
#include "ModalWin.h"
#include "ModalArea.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ModalArea
IMPLEMENT_DYNCREATE(ModalArea, CWnd)
ModalArea::ModalArea()
{
}
ModalArea::~ModalArea()
{
}
BEGIN_MESSAGE_MAP(ModalArea, CWnd)
//{{AFX_MSG_MAP(ModalArea)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_CLOSE()
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ModalArea message handlers
int ModalArea::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void ModalArea::OnClose()
{
// TODO: Add your message handler code here and/or call default
// Since it will not be destroyed here
// hide the modal frame window
ShowWindow( SW_HIDE );
// End the modal loop, started in OnViewGoModal()
// Return true or any other value you desire
EndModalLoop( TRUE );
// Re-enable the main application window
::EnableWindow( AfxGetApp()->m_pMainWnd->m_hWnd, TRUE );
}
void ModalArea::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd::OnLButtonDblClk(nFlags, point);
if (
( point.x > pointTarget.x) &&
( point.x < (pointTarget.x + 2*pointRange.x)) &&
( point.y > pointTarget.y) &&
( point.y < (pointTarget.y + 2*pointRange.y)) )
OnClose();
}
void ModalArea::SetpAppWnd(CFrameWnd * pWnd)
{
pAppWnd = pWnd;
}
void ModalArea::OnPaint()
{
// This is the device contex where we will do
// the drawing
CPaintDC dc(this);
// These are various compatible device contexts
// in which we will copy the bitmap in order to
// mask the desired transparent bits
CDC cdcTemp,
cdcBackGround,
cdcBitMask,
cdcMemory,
cdcScreenBits;
// Status bar from our main application window
CStatusBar * pMessageBar;
// Original background color of the source
// device context
COLORREF clrrefBkColor;
// Bitmap objects for copying the masks, original,
// and so forth back and forth
CBitmap cbmNewBitmap,
cbmCopyBitMask,
cbmCopyMemory,
cbmCopyBackGround,
cbmScreenBits;
CBitmap * cbmOldBitmap;
CBitmap * cbmBackGroundOld;
CBitmap * cbmBitMaskOld;
CBitmap * cbmMemoryOld;
CBitmap * cbmScreenBitsOld;
// bitmpap sizes and target points for the mouse
CPoint pointBmpExtent, pointTextOut;
// Used to put the bitmap over the NumLock pane
CRect rectNumPane, rectMessageBar, rectTarget;
BITMAP bm;
// Get the pointer to the message bar
// of the application
pMessageBar = (CStatusBar *) pAppWnd->GetMessageBar();
// Coordinates of the NumLock pane are relative to the
// upper left of the status bar, so get them
// and add them together
pMessageBar->GetItemRect(2, &rectNumPane);
pMessageBar->GetWindowRect(&rectMessageBar);
rectTarget = rectNumPane;
rectTarget.left = rectMessageBar.left
+ rectNumPane.left;
rectTarget.top = rectMessageBar.top
+ rectNumPane.top;
// Load our resource bitmap
cdcTemp.CreateCompatibleDC(&dc);
cbmNewBitmap.LoadBitmap(IDB_BITMAP1);
// Select the bitmap into the dc
cbmOldBitmap = cdcTemp.SelectObject(&cbmNewBitmap);
GetObject(HBITMAP(cbmNewBitmap),
sizeof(BITMAP),
(LPSTR)&bm);
pointBmpExtent.x = bm.bmWidth;
pointBmpExtent.y = bm.bmHeight;
// We need to offset our bitmap so the area of interest
// is in it center when it appears on the screen
pointRange.x = pointBmpExtent.x / 2;
pointRange.y = pointBmpExtent.y / 2;
pointTarget.x = (rectTarget.left - pointRange.x)
+ (rectNumPane.Width() / 2);
pointTarget.y = rectTarget.top - pointRange.y
+ (rectNumPane.Height() / 2);
// Create dc's in which to move our bitmap around
// so we can back out background
cdcBackGround.CreateCompatibleDC(&dc);
cdcMemory.CreateCompatibleDC(&dc);
cdcScreenBits.CreateCompatibleDC(&dc);
cdcBitMask.CreateCompatibleDC(&dc);
// Create the bitmaps for each of our dc's
cbmCopyBackGround.CreateBitmap(pointBmpExtent.x,
pointBmpExtent.y, 1, 1, NULL);
cbmCopyBitMask.CreateBitmap(pointBmpExtent.x,
pointBmpExtent.y, 1, 1, NULL);
cbmCopyMemory.CreateCompatibleBitmap(&dc,
pointBmpExtent.x, pointBmpExtent.y);
cbmScreenBits.CreateCompatibleBitmap(&dc,
pointBmpExtent.x, pointBmpExtent.y);
// Select the bitmaps just created into each of the dc's
cbmBackGroundOld =
cdcBackGround.SelectObject(&cbmCopyBackGround);
cbmBitMaskOld =
cdcBitMask.SelectObject(&cbmCopyBitMask);
cbmMemoryOld =
cdcMemory.SelectObject(&cbmCopyMemory);
cbmScreenBitsOld =
cdcScreenBits.SelectObject(&cbmScreenBits);
// Copy out the are of the screen that is about
// to be overwritten
cdcScreenBits.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &cdcTemp, 0, 0, SRCCOPY);
// Set the background color to white
// This was the color chosen to be transparent
clrrefBkColor = cdcTemp.SetBkColor(RGB( 255, 255, 255));
// Create mask for your bitmap
cdcBitMask.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &cdcTemp, 0, 0,
SRCCOPY);
// Put the original background color back
cdcTemp.SetBkColor(clrrefBkColor);
// Create the reverse of the mask you just made
cdcBackGround.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &cdcBitMask, 0, 0,
NOTSRCCOPY);
// Copy in the background of the paint dc first
cdcMemory.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &dc, pointTarget.x,
pointTarget.y, SRCCOPY);
// Copy in the mask for the bitmap
cdcMemory.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &cdcBitMask, 0, 0, SRCAND);
// Mask out the bits we have determined to be
// transparent (white ones)
cdcTemp.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &cdcBackGround, 0, 0, SRCAND);
// Blend in the background
cdcMemory.BitBlt(0, 0, pointBmpExtent.x,
pointBmpExtent.y, &cdcTemp, 0, 0, SRCPAINT);
// Now put it all on the display
dc.BitBlt(pointTarget.x, pointTarget.y,
pointBmpExtent.x, pointBmpExtent.y, &cdcMemory,
0, 0, SRCCOPY);
// Put the instruction string for student on the screen
LPCTSTR pInstruction =
_T("Identify and double-click the Numlock indicator.");
CSize sizeString = dc.GetTextExtent(pInstruction,
lstrlen(pInstruction));
pointTextOut.x = pointTarget.x - (sizeString.cx/2);
pointTextOut.y = rectMessageBar.bottom + pointRange.y;
dc.TextOut( pointTextOut.x, pointTextOut.y, pInstruction,
lstrlen(pInstruction));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -