// BasePage.h : header file
//
//用于显示图片
#include
#include
/////////////////////////////////////////////////////////////////////////////
// CBasePage window
class CBasePage : public CDialog
{
public:
void SetpicPath(CString picpath);
CBasePage(UINT nIDTemplate, CWnd* pParentWnd = NULL);
virtual ~CBasePage();
protected:
//为了加速显示不放在ONPAINT中
BITMAP m_mapinfo;
CDC m_memdc;
CComBSTR m_picturePath;
//{{AFX_MSG(CBasePage)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// BasePage.cpp : implementation file
//
#include "stdafx.h"
#include "kyvodclient.h"
#include "BasePage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBasePage
CBasePage::CBasePage(UINT nIDTemplate, CWnd *pParentWnd)
:CDialog(nIDTemplate,pParentWnd)//没有对话框资源,要续传给CDialog
{
//{{AFX_DATA_INIT(CBasePage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CBasePage::~CBasePage()
{
}
BEGIN_MESSAGE_MAP(CBasePage, CDialog)
//{{AFX_MSG_MAP(CBasePage)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBasePage message handlers
BOOL CBasePage::OnInitDialog()
{
CDialog::OnInitDialog();
//------------------------------------------------------------------
// Full-Screen Setup
//------------------------------------------------------------------
int cx, cy;
HDC dc = ::GetDC(NULL);
cx = GetDeviceCaps(dc,HORZRES) + GetSystemMetrics(SM_CXBORDER);
cy = GetDeviceCaps(dc,VERTRES) + GetSystemMetrics(SM_CYBORDER);
::ReleaseDC(0,dc);
::SetWindowPos(m_hWnd, HWND_TOPMOST,
-(GetSystemMetrics(SM_CXBORDER)+1),
-(GetSystemMetrics(SM_CYBORDER)+1),
cx+1,cy+1, SWP_NOZORDER);
//------------------------------------------------------------------
// Load Picture
//------------------------------------------------------------------
CPictureHolder picholder;
CBitmap bitmap;
long WD, HT;
if(SUCCEEDED(::OleLoadPicturePath(m_picturePath,0,0,0,IID_IPicture,(void**)&picholder)))
{
picholder.m_pPict->get_Width (&WD);
picholder.m_pPict->get_Height(&HT);
}
m_memdc.CreateCompatibleDC(GetDC());
bitmap.CreateCompatibleBitmap(GetDC(),cx,cy);
m_memdc.SelectObject(bitmap);
picholder.Render(&m_memdc,CRect(0,0,cx,cy),CRect(0,0,cx,cy));
bitmap.GetBitmap(&m_mapinfo);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBasePage::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.BitBlt(0,0,m_mapinfo.bmWidth,m_mapinfo.bmHeight,&m_memdc,0,0,SRCCOPY);
// Do not call CDialog::OnPaint() for painting messages
}
void CBasePage::SetpicPath(CString path)
{
m_picturePath = path;
}
//////////////////////////////////子类调用/////////////////////////////////////////////////////
BOOL CSingerList::OnInitDialog()
{
char CurPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,CurPath);
SetpicPath(CurPath + CString("\\image\\singerlist.jpg"));
CBasePage::OnInitDialog();//要在最后调用
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSingerList::OnPaint()
{
CBasePage::OnPaint();
// Do not call CDialog::OnPaint() for painting messages
}
本文地址:http://com.8s8s.com/it/it462.htm