我自己写了个类用来显示图片的, 
并且样式已经设为WS_EX_CLIENTEDGE了, 为什么还是没有立体效果?
在对话框里的初始函数OnInitDialog()加入了引用代码
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();
下面是testView类的代码
.h文件
#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
#endifprotected:
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.cpp文件
// 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 //_DEBUGvoid 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);
}继承对话框

解决方案 »

  1.   

    对话框不建议用CView类,CView是应用于文档视图结构的,如果只是显示继承自CWnd更好.
    至于没有外框是不是因为你自己画的原因呀?还不清楚
      

  2.   

    但即使是继承CWnd,也没有外框啊!为什么?
    难道外框要自己画吗?
      

  3.   

    这么在意框的话就自己画一个,View毕竟不是控件
      

  4.   

    因为MFC很不熟,所以一直都怀疑是我自己的代码为题下面是代码,帮忙看看吧!
    是不是Create的时候参数错了?
    下面是写在对话框的OnInitDialog()函数里的。就一个简单的创建。
    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);
    TestVIew的代码
    .h文件
    #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);
    };.cpp文件
    // TestVIew.cpp : implementation file
    //#include "stdafx.h"
    #include "test.h"
    #include "TestVIew.h"
    // TestVIewIMPLEMENT_DYNAMIC(TestVIew, CWnd)TestVIew::TestVIew()
    {
    }TestVIew::~TestVIew()
    {
    }BEGIN_MESSAGE_MAP(TestVIew, CWnd)
    END_MESSAGE_MAP()// TestVIew message handlersvoid 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);
    }
    TestVIew类只是简单的画了背景,没有特别的操作啊!
    运行后还是没有外框,求解!!或者你给我个例子啦!!
      

  5.   

    view->Create(NULL,NULL, WS_EX_CLIENTEDGE, rect, this, NULL, NULL);
    第3个是 DWORD dwStyle,不是 Extended style
    用 CreateEx
    或者加:
    ModifyStyleEx
      

  6.   


    哈哈!!加了
    view->ModifyStyleEx(WS_EX_STATICEDGE|WS_EX_WINDOWEDGE||WS_EX_DLGMODALFRAME,  WS_EX_CLIENTEDGE,SWP_DRAWFRAME);  
    总算搞定了!!
    原来这么简单,居然困扰了我好几天!!thank you!