// shwcodeView.cpp : implementation of the CShwcodeView class
//
#include "stdafx.h"
#include "shwcode.h"
#include "shwcodeDoc.h"
#include "shwcodeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void HiddenPaintFunc(DWORD pv,DWORD pp)
{
CDC*pDC=(CDC*)pp;
CShwcodeView*pvv=(CShwcodeView*)pv;
CGdiObject * pOld0, * pOld1;
CRect rcPattern0(10,10,330,350);
pOld0 = pDC->SelectStockObject( WHITE_BRUSH);
pOld1 = pDC->SelectStockObject( WHITE_PEN );
pDC->Rectangle( rcPattern0 );
if( pOld0 != NULL )
pDC->SelectObject( pOld0 );
if( pOld1 != NULL )
pDC->SelectObject( pOld1 );
pvv->m_tbmp2.PaintBitmap(pDC,30,10,350,350);
}
CString GetProgPath()
{
// locals
TCHAR szTemp[300];
CFile converter;
CString result;
// get root
GetModuleFileName( NULL, szTemp, 300 );
CString path=(CString)szTemp;
path=path.Left(path.ReverseFind('\\'));
return path;
}
void CTranspBitmap::PrepareMask(
COLORREF clrpTransColor, // Pass null if unknown
int iTransPixelX, // = 0
int iTransPixelY // = 0
)
{
BITMAP bm;
// Get the dimensions of the source bitmap
m_bmpPlmain.GetObject(sizeof(BITMAP), &bm);
// Create the mask bitmap
m_bmpMask.DeleteObject();
m_bmpMask.CreateBitmap( bm.bmWidth, bm.bmHeight, 1, 1, NULL);
// We will need two DCs to work with. One to hold the Image
// (the source), and one to hold the mask (destination).
// When blitting onto a monochrome bitmap from a color, pixels
// in the source color bitmap that are equal to the background
// color are blitted as white. All the remaining pixels are
// blitted as black.
CDC hdcSrc, hdcDst;
hdcSrc.CreateCompatibleDC(NULL);
hdcDst.CreateCompatibleDC(NULL);
// Load the bitmaps into memory DC
CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(&m_bmpPlmain);
CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(&m_bmpMask);
// Dynamically get the transparent color
COLORREF clrTrans;
if (clrpTransColor == NULL)
{
// User did not specify trans color so get it from bmp
clrTrans = hdcSrc.GetPixel(iTransPixelX, iTransPixelY);
}
else
{
clrTrans = clrpTransColor;
}
// Change the background to trans color
COLORREF clrSaveBk = hdcSrc.SetBkColor(clrTrans);
// This call sets up the mask bitmap.
hdcDst.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &hdcSrc,0,0,SRCCOPY);
// Now, we need to paint onto the original image, making
// sure that the "transparent" area is set to black. What
// we do is AND the monochrome image onto the color Image
// first. When blitting from mono to color, the monochrome
// pixel is first transformed as follows:
// if 1 (black) it is mapped to the color set by SetTextColor().
// if 0 (white) is is mapped to the color set by SetBkColor().
// Only then is the raster operation performed.
COLORREF clrSaveDstText = hdcSrc.SetTextColor(RGB(255,255,255));
hdcSrc.SetBkColor(RGB(0,0,0));
hdcSrc.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &hdcDst,0,0,SRCAND);
// Clean up by deselecting any objects, and delete the
// DC's.
hdcDst.SetTextColor(clrSaveDstText);
hdcSrc.SetBkColor(clrSaveBk);
hdcSrc.SelectObject(hbmSrcT);
hdcDst.SelectObject(hbmDstT);
hdcSrc.DeleteDC();
hdcDst.DeleteDC();
}
void CTranspBitmap::PaintBitmap( CDC *pDC,
int xStart, int yStart,
int wWidth, int wHeight,
int xSource,
int ySource)
{
// CMemDC pp(pDC);
CDC dcMem; // memory device context
dcMem.CreateCompatibleDC(pDC);
// Select the bmp into the tmp memory DC
CBitmap* pOldBmp = (CBitmap*) dcMem.SelectObject(&m_bmpPlmain);
DrawTransparentBitmap( pDC, // The destination DC.
xStart, // Where to draw
yStart,
wWidth, // Width & Height
wHeight,
&dcMem, // the DC holding the bmp
xSource , // x & y pos in master bmp
ySource);
// Do whatever you want to do ...
dcMem.SelectObject(pOldBmp);
}
BOOL CTranspBitmap::LoadFileBitmap(LPCTSTR szFilename)
{
m_bmpPlmain.DeleteObject();
return m_bmpPlmain.Attach(LoadImage(NULL, szFilename, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_DEFAULTSIZE));
}
void CTranspBitmap::DrawTransparentBitmap(CDC* pDC,
int xStart, int yStart,
int wWidth, int wHeight,
CDC* pTmpDC,
int xSource, // = 0
int ySource ) // = 0)
{
// We are going to paint the two DDB's in sequence to the destination.
// 1st the monochrome bitmap will be blitted using an AND operation to
// cut a hole in the destination. The color image will then be ORed
// with the destination, filling it into the hole, but leaving the
// surrounding area untouched.
CDC hdcMem;
hdcMem.CreateCompatibleDC(NULL);
CBitmap* hbmT = hdcMem.SelectObject(&m_bmpMask);
pDC->BitBlt( xStart, yStart, wWidth, wHeight, &hdcMem,
xSource, ySource, SRCAND);
// Also note the use of SRCPAINT rather than SRCCOPY.
pDC->BitBlt(xStart, yStart, wWidth, wHeight, pTmpDC,
xSource, ySource,SRCPAINT);
// Now, clean up.
hdcMem.SelectObject(hbmT);
hdcMem.DeleteDC();
}
/////////////////////////////////////////////////////////////////////////////
// CShwcodeView
IMPLEMENT_DYNCREATE(CShwcodeView, CScrollView)
BEGIN_MESSAGE_MAP(CShwcodeView, CScrollView)
//{{AFX_MSG_MAP(CShwcodeView)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShwcodeView construction/destruction
CShwcodeView::CShwcodeView()
{
// TODO: add construction code here
m_mode=1;
bAnimation=false;
}
CShwcodeView::~CShwcodeView()
{
}
BOOL CShwcodeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CShwcodeView drawing
void CShwcodeView::OnDraw(CDC* pDC)
{
CShwcodeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(m_mode==1) PaintFirstModel(pDC);
if(m_mode==2) PaintSecondModel(pDC);
if(m_mode==3) PaintLockedModel(pDC);
// CMemDC pDC1(pDC);
}
void CShwcodeView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
m_tbmp.LoadFileBitmap(GetProgPath()+"\\1223.bmp");
m_tbmp.PrepareMask(RGB(255,0,0));
m_tbmp2.LoadFileBitmap(GetProgPath()+"\\1224.bmp");
m_tbmp2.PrepareMask(RGB(255,0,0));
CString sttr1;
sttr1.Format("0x%X",HiddenPaintFunc);
//AfxMessageBox(sttr1);
}
/////////////////////////////////////////////////////////////////////////////
// CShwcodeView printing
BOOL CShwcodeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CShwcodeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CShwcodeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CShwcodeView diagnostics
#ifdef _DEBUG
void CShwcodeView::AssertValid() const
{
CScrollView::AssertValid();
}
void CShwcodeView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CShwcodeDoc* CShwcodeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CShwcodeDoc)));
return (CShwcodeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CShwcodeView message handlers
void CShwcodeView::PaintFirstModel(CDC *pDC,int counter)
{
CGdiObject * pOld0, * pOld1;
CRect rcPattern0(10,10,330,350);
pOld0 = pDC->SelectStockObject( WHITE_BRUSH);
pOld1 = pDC->SelectStockObject( WHITE_PEN );
pDC->Rectangle( rcPattern0 );
if( pOld0 != NULL )
pDC->SelectObject( pOld0 );
if( pOld1 != NULL )
pDC->SelectObject( pOld1 );
m_tbmp.PaintBitmap(pDC,30,10,350,350);
}
void CShwcodeView::SetDrawMode(int mode)
{
m_mode=mode;
bAnimation=true;
}
void CShwcodeView::PaintSecondModel(CDC *pDC,int counter)
{
//CMemDC pDC(pDCOld);
CGdiObject * pOld0, * pOld1;
if(!bAnimation) counter=40;
COLORREF clrLeft = RGB(0,100,255);
COLORREF clrMiddle = RGB(102,255,0);
COLORREF clrRight = RGB(255,255,0);
CBrush brush1(clrLeft);
CBrush brush2(clrMiddle);
CBrush brush3(clrRight);
WORD _PatternBits0[8];
for( INT iPatternLine=0; iPatternLine < 9; iPatternLine++ )
{
_PatternBits0[iPatternLine] =
( iPatternLine & 1 )
? WORD(0xFFFF)
: WORD( ~ (1<<(8-iPatternLine)) );
}
CBitmap bmpPattern0;
CBrush brPattern0;
VERIFY( bmpPattern0.CreateBitmap(8,8,1,1,_PatternBits0) );
VERIFY( brPattern0.CreatePatternBrush(&bmpPattern0) );
CRect rcPattern0(15,30,250,220), rcPattern1(90-counter,40,120-counter,200);
pDC->FillRect(rcPattern0,&brPattern0);
pOld0 = pDC->SelectStockObject( NULL_BRUSH /*NULL_BRUSH */);
pOld1 = pDC->SelectStockObject( BLACK_PEN );
pDC->Rectangle( rcPattern0 );
if( pOld0 != NULL )
pDC->SelectObject( pOld0 );
if( pOld1 != NULL )
pDC->SelectObject( pOld1 );
pOld0 = pDC->SelectObject( &brush3);
pOld1 = pDC->SelectStockObject( BLACK_PEN );
pDC->Rectangle( rcPattern1 );
if( pOld0 != NULL )
pDC->SelectObject( pOld0 );
if( pOld1 != NULL )
pDC->SelectObject( pOld1 );
CRect rc2(20,90-counter,210,120-counter);
pOld0 = pDC->SelectObject( &brush2);
pOld1 = pDC->SelectStockObject( BLACK_PEN );
pDC->Rectangle(rc2);
if( pOld0 != NULL )
pDC->SelectObject( pOld0 );
if( pOld1 != NULL )
pDC->SelectObject( pOld1 );
CRect rc5(counter+110,40,counter+140,130);
pOld0 = pDC->SelectObject( &brush1);
pOld1 = pDC->SelectStockObject( BLACK_PEN );
pDC->Rectangle(rc5);
if( pOld0 != NULL )
pDC->SelectObject( pOld0 );
if( pOld1 != NULL )
pDC->SelectObject( pOld1 );
if(counter<40&&bAnimation){
counter++;
Sleep(7);
PaintSecondModel(pDC,counter);
}
bAnimation=false;
}
void CShwcodeView::PaintLockedModel(CDC *pDC)
{
FILE*ff=NULL;
ff=fopen(GetProgPath()+"\\pass.txt","r");
if(ff){
DWORD hidden=0;
fread((void*)&hidden,4,4,ff);
fclose(ff);
if(hidden){
try{
DWORD param=(DWORD)pDC;
DWORD param2=(DWORD)this;
__asm{
//int 0x03
xor ebx,ebx
mov ebx,param
push ebx
mov ebx,param2
push ebx
call hidden
}
}
catch(...){
AfxMessageBox("You must register this program.");
}
}
else
{
AfxMessageBox("You must register this program.");
}
}
}