16,471
社区成员
发帖
与我相关
我的任务
分享
testView* m_view = new testView;
((CView*)m_view)->Create(NULL, NULL, WS_EX_CLIENTEDGE, CRect(250,120,800,520), this, NULL, NULL);
m_view->ShowWindow(SW_SHOW);
m_view->OnInitialUpdate();
#pragma once
#pragma comment(lib, "../debug/valib.lib")
#include "valib.h"
// testView 视图
VA_NS_BEGIN
class testView : public CView
{
DECLARE_DYNCREATE(testView)
VASprite* m_rootSP;
public:
testView(); // 动态创建所使用的受保护的构造函数
virtual ~testView();
public:
virtual void OnFinalRelease();
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
DECLARE_MESSAGE_MAP()
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
public:
virtual void OnInitialUpdate();
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnPaint();
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};
VA_NS_END
// testView.cpp : 实现文件
//
#include "stdafx.h"
#include "ImgTools.h"
#include "testView.h"
// testView
US_VA_NS
IMPLEMENT_DYNCREATE(testView, CView)
testView::testView()
:m_rootSP(NULL)
{
EnableAutomation();
}
testView::~testView()
{
}
void testView::OnFinalRelease()
{
// 释放了对自动化对象的最后一个引用后,将调用
// OnFinalRelease。基类将自动
// 删除该对象。在调用该基类之前,请添加您的
// 对象所需的附加清理代码。
CView::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(testView, CView)
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(testView, CView)
END_DISPATCH_MAP()
// 注意: 我们添加 IID_ItestView 支持
// 以支持来自 VBA 的类型安全绑定。此 IID 必须同附加到 .IDL 文件中的
// 调度接口的 GUID 匹配。
// {ED946E81-95CB-491A-90E1-3EA850D4E5B7}
static const IID IID_ItestView =
{ 0xED946E81, 0x95CB, 0x491A, { 0x90, 0xE1, 0x3E, 0xA8, 0x50, 0xD4, 0xE5, 0xB7 } };
BEGIN_INTERFACE_MAP(testView, CView)
INTERFACE_PART(testView, IID_ItestView, Dispatch)
END_INTERFACE_MAP()
// testView 绘图
void testView::OnDraw(CDC* pDC)
{
//CDocument* pDoc = GetDocument();
// TODO: 在此添加绘制代码
CView::OnInitialUpdate();
}
// testView 诊断
#ifdef _DEBUG
void testView::AssertValid() const
{
CView::AssertValid();
}
#ifndef _WIN32_WCE
void testView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif
#endif //_DEBUG
void testView::OnInitialUpdate()
{
if(!m_hWnd)return;
VADirector::sharedDirector()->init(m_hWnd);
m_rootSP = new VASprite("root");
VASprite* m_cake;
m_cake = new VASprite("cake");
m_rootSP->addChild(m_cake);
TCHAR szCurrDir[_MAX_PATH];
::GetCurrentDirectory(_MAX_PATH, szCurrDir);;
TCHAR m_bgName[_MAX_PATH];
wsprintf(m_bgName,L"%s\\res\\img.jpg",szCurrDir);
TCHAR m_cakeName[_MAX_PATH];
wsprintf(m_cakeName,L"%s\\res\\cake.png", szCurrDir);
Bitmap* m_imgBG = Bitmap::FromFile(m_bgName);
Bitmap* m_imgCake = Bitmap::FromFile(m_cakeName);
m_rootSP->setBitmap(m_imgBG);
m_cake->setBitmap(m_imgCake);
CView::OnInitialUpdate();
}
// testView 消息处理程序
void testView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnTimer(nIDEvent);
}
void testView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CView::OnPaint()
//增加精灵
m_rootSP->draw();
CView::OnPaint();
}
void testView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnLButtonDblClk(nFlags, point);
}
void testView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnLButtonDown(nFlags, point);
}
void testView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnLButtonUp(nFlags, point);
}
CRect clientRect;
this->GetClientRect(clientRect);
CRect rect(10, 10, clientRect.Width()-10, clientRect.Height()-10);
TestVIew* view = new TestVIew;
view->Create(NULL,NULL, WS_EX_CLIENTEDGE, rect, this, NULL, NULL);
view->ShowWindow(SW_SHOW);
#pragma once
// TestVIew
class TestVIew : public CWnd
{
DECLARE_DYNAMIC(TestVIew)
public:
TestVIew();
virtual ~TestVIew();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPaint();
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
void drawBackground(CDC* dc);
};
// TestVIew.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "TestVIew.h"
// TestVIew
IMPLEMENT_DYNAMIC(TestVIew, CWnd)
TestVIew::TestVIew()
{
}
TestVIew::~TestVIew()
{
}
BEGIN_MESSAGE_MAP(TestVIew, CWnd)
END_MESSAGE_MAP()
// TestVIew message handlers
void TestVIew::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
/*CRect rect;
this->GetWindowRect(rect);
dc.Draw3dRect(0, 0, rect.right, rect.bottom, RGB(192,192,192),RGB(0,0,0) );*/
drawBackground(&dc);
// Do not call CWnd::OnPaint() for painting messages
CWnd::OnPaint();
}
LRESULT TestVIew::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message){
case WM_CREATE:
Invalidate(true);
break;
case WM_PAINT:
OnPaint();
break;
}
return CWnd::WindowProc(message, wParam, lParam);
}
void TestVIew::drawBackground(CDC* dc)
{
CRect clientRect;
this->GetClientRect(clientRect);
CBrush newBrush;
CBrush bgGrush;
CPen newPen;
newPen.CreatePen(PS_NULL,5, RGB(0, 255, 255));
dc->SelectObject(&newPen);
bgGrush.CreateSolidBrush(RGB(210,210, 210));
dc->SelectObject(bgGrush);
dc->Rectangle(clientRect);
newBrush.CreateSolidBrush(RGB(255, 255, 255));
dc->SelectObject(&newBrush);
int m_space = 22;
for(int i = 0; i<=clientRect.Height()/m_space; i++){
CRect lineRcet(0,i*m_space, clientRect.Width(), i*m_space+m_space/2);
dc->Rectangle(lineRcet);
}
for(int i = 0; i<=clientRect.Width()/m_space; i++){
CRect lineRcet(i*m_space, 0, i*m_space+m_space/2, clientRect.Width());
dc->Rectangle(lineRcet);
}
//dc.SelectObject(oldBrush);
//dc.SelectObject(oldPen);
}