📄 winlottoryview.cpp
字号:
// WinLottoryView.cpp : implementation of the CWinLottoryView class
//
#include "stdafx.h"
#include "WinLottory.h"
#include "Picture.h"
#include "Resource.h"
#include "PositionPoint.h"
#include "WinLottory.h"
#include "LottoryUtils.h"
#include "MainFrm.h"
#include <afxwin.h>
#include "WinLottoryDoc.h"
#include "WinLottoryView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWinLottoryView
IMPLEMENT_DYNCREATE(CWinLottoryView, CView)
BEGIN_MESSAGE_MAP(CWinLottoryView, CView)
//{{AFX_MSG_MAP(CWinLottoryView)
ON_WM_DESTROY()
ON_WM_CANCELMODE()
ON_WM_SIZE()
ON_WM_CAPTURECHANGED()
ON_WM_ERASEBKGND()
ON_WM_CHAR()
ON_WM_PAINT()
ON_WM_CONTEXTMENU()
ON_WM_TIMER()
ON_WM_COPYDATA()
ON_WM_LBUTTONDOWN()
ON_WM_CREATE()
ON_WM_MOVE()
ON_WM_DROPFILES()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWinLottoryView construction/destruction
CWinLottoryView::CWinLottoryView()
{
// TODO: add construction code here
}
CWinLottoryView::~CWinLottoryView()
{
}
BOOL CWinLottoryView::PreCreateWindow(CREATESTRUCT& cs)
{
//MessageBox("onprecreatewindow");
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// 预读文件
jpgFile = new CFile("res//1024.jpg",0);
pic.Load(*jpgFile);
//
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWinLottoryView drawing
void CWinLottoryView::OnDraw(CDC* pDC)
{
CWinLottoryDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//CPaintDC dc(this);
//GetClientRect(&rc);
//dc.DrawText(_T("抽奖活动"),-1,&rc,DT_SINGLELINE|DT_CENTER);
//Invalidate(true);
}
/////////////////////////////////////////////////////////////////////////////
// CWinLottoryView printing
BOOL CWinLottoryView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWinLottoryView::OnBeginPrinting(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWinLottoryView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CWinLottoryView diagnostics
#ifdef _DEBUG
void CWinLottoryView::AssertValid() const
{
CView::AssertValid();
}
void CWinLottoryView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWinLottoryDoc* CWinLottoryView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWinLottoryDoc)));
return (CWinLottoryDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWinLottoryView message handlers
void CWinLottoryView::OnDestroy()
{
if (pic!=NULL)
{
pic.Free();
}
if (jpgFile!=NULL)
{
jpgFile->Close();
}
CView::OnDestroy();
}
void CWinLottoryView::OnCancelMode()
{
CView::OnCancelMode();
// TODO: Add your message handler code here
}
void CWinLottoryView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CWinLottoryView::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here
CView::OnCaptureChanged(pWnd);
}
BOOL CWinLottoryView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//return TRUE;
return CView::OnEraseBkgnd(pDC);
}
void CWinLottoryView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CWinLottoryView::OnPaint()
{
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
CWinLottoryDoc *pDoc = (CWinLottoryDoc *) pFrame->GetActiveDocument();
CPaintDC dc(this);
// 读取并显示主界面背景图片
if (jpgFile==NULL||pic==NULL){
jpgFile = new CFile("res//1024.jpg",0);
pic.Load(*jpgFile);
}
// TODO采用双缓冲显示图片
PositionPoint pp;
// 取当前屏幕大小
CRect rc(0,0,pp.getScreamX(),pp.getScreamY());
// 取得当前窗口设备
CDC* pDC = GetDC();
// 建立兼容设备
//CDC MemDC;
// 建立兼容DC
//MemDC.CreateCompatibleDC(pDC);
//MemDC.SelectObject(&pic);
//pic.Render(&MemDC,rc);
//pDC->BitBlt(rc.left,rc.top,rc.Width(),rc.Height(),&MemDC,rc.left,rc.top,SRCCOPY);
//MemDC.DeleteDC();
pic.Render(pDC,rc);
// 暂停状态抽奖数据的显示
/*if (pDoc->m_nIfTimer==1)
{
if (((CMainFrame*)pFrame)->count>0)
{
CRect rcTemp(280,268,853,385);
dc.SetBkMode(TRANSPARENT);
// 设置画刷
CBrush brush(RGB(255,0,0));
CBrush *oldBrush = dc.SelectObject(&brush);
dc.Rectangle(280,248,853,385);
dc.SelectObject(oldBrush);
// 设置字体
CFont mainTitleFont;
mainTitleFont.CreatePointFont(650,_T("楷体_GB2312"));
dc.SelectObject(&mainTitleFont);
// 显示数据 ((CMainFrame*)pFrame)->count-1
dc.DrawText(_T(pDoc->m_sLottoryData.GetAt(((CMainFrame*)pFrame)->count-1)),-1,&rcTemp,DT_SINGLELINE/*|DT_CENTER|DT_VCENTER);
}
}*/
/////////////////////////////////////////////////////
//dc.DrawText(_T("抽奖活动"),-1,&rc,DT_SINGLELINE|DT_CENTER);
//MessageBox("change");
//dc.DrawText(_T("有道理"),-1,&rc,DT_SINGLELINE|DT_CENTER);
// 释放空间
pDC->ReleaseOutputDC();
pDC=NULL;
//Invalidate(true);
// Do not call CView::OnPaint() for painting messages
}
void CWinLottoryView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
}
void CWinLottoryView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CView::OnTimer(nIDEvent);
}
BOOL CWinLottoryView::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
// TODO: Add your message handler code here and/or call default
return CView::OnCopyData(pWnd, pCopyDataStruct);
}
void CWinLottoryView::OnLButtonDown(UINT nFlags, CPoint point)
{
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
CWinLottoryDoc *pDoc = (CWinLottoryDoc *) pFrame->GetActiveDocument();
CString tempString;
int* result = (int*)malloc(sizeof(int)*500);
memset(result,0,500);
if (pDoc->m_nFlag==0)
{
if (pDoc->m_nIfSetTimer==0)
{
if (pDoc->m_nIfTimer==0)
{
pDoc->m_nIfTimer=1;
LottoryUtils lu;
int lottoryNum = (pDoc->m_nLottory)[pDoc->m_nLottoryTimes];
if (pDoc->m_sLottoryData.GetSize()<lottoryNum)
{
MessageBox("抽奖数据少于抽奖数!");
}
else
{
// 如果中奖数为1的话,抽中的数,必须是屏幕滚到的数
if (lottoryNum==1)
{
*result = ((CMainFrame*)pFrame)->count-1;
}
else
{
lu.getRand(result,pDoc->m_sLottoryData.GetSize(),lottoryNum);
}
for(int i=0;i<lottoryNum;i++)
{
pDoc->m_sLottoryBingo.Add(pDoc->m_sLottoryData.GetAt(*(result+i)));
tempString = tempString + pDoc->m_sLottoryData.GetAt(*(result+i)) + "\n";
}
for (int j=0;j<lottoryNum;j++)
{
pDoc->m_sLottoryData.RemoveAt(*(result+j));
for (int n = 0;n < lottoryNum; n++)
{
if (*(result+n)>*(result+j))
{
*(result+n) = *(result+n) - 1;
}
}
}
switch(pDoc->m_nLottoryTimes)
{
case 2:
MessageBox("三等奖获奖名单:\n\n"+tempString);
break;
case 1:
MessageBox("二等奖获奖名单:\n\n"+tempString);
break;
case 0:
MessageBox("一等奖获奖名单:\n\n"+tempString);
break;
default:
MessageBox("名单为空!");
}
pDoc->m_nLottoryTimes--;
if (pDoc->m_nLottoryTimes<0)
{
pDoc->m_nFlag=1;
MessageBox("本次抽奖结束");
}
}
}
else
{
pDoc->m_nIfSetTimer=0;
pDoc->m_nIfTimer=0;
}
}
}
else
{
MessageBox("请载入抽奖数据!");
}
delete(result);
CView::OnLButtonDown(nFlags, point);
}
int CWinLottoryView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void CWinLottoryView::OnMove(int x, int y)
{
CView::OnMove(x, y);
// TODO: Add your message handler code here
}
void CWinLottoryView::OnDropFiles(HDROP hDropInfo)
{
// TODO: Add your message handler code here and/or call default
CView::OnDropFiles(hDropInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -