
项目-添加类-c++类,类名CSplashWnd
其他默认。把SplashWnd.h的代码如下:
#pragma once
// CSplashWnd
class CSplashWnd : public CWnd
{
DECLARE_DYNAMIC(CSplashWnd)
private:
CDC mMemDC
BITMAP bmBitmap
CBitmap m_Bitmap
CBitmap *Old_Bitmap
public:
void CreateSplash()
public:
CSplashWnd()
virtual ~CSplashWnd()
protected:
afx_msg void OnPaint()
DECLARE_MESSAGE_MAP()
}
类的cpp代码:
// SplasWnd.cpp : 实现文件
//
#include "stdafx.h"
#include "resource.h"
#include "SplashWnd.h"
// CSplashWnd
IMPLEMENT_DYNAMIC(CSplashWnd, CWnd)
CSplashWnd::CSplashWnd()
{
m_Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP1))//Load Bitmap
m_Bitmap.GetBitmap(&bmBitmap) //Get Bitmap Info
}
CSplashWnd::~CSplashWnd()
{
}
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
// CSplashWnd 消息处理程序
void CSplashWnd::CreateSplash()
{
//Create Splash Window
CWnd::CreateEx(0,
AfxRegisterWndClass(
0,
AfxGetApp()->LoadStandardCursor(IDC_UPARROW)),
NULL,
//"SplashWindow Sample",
WS_POPUP,
0,
0,
bmBitmap.bmWidth, //Bitmap Width = Splash Window Width
bmBitmap.bmHeight, //Bitmap Height = Splash Window Height
NULL,
NULL,
NULL)
}
void CSplashWnd::OnPaint()
{
CPaintDC dc(this)
CBrush brush
brush.CreateSolidBrush(RGB(64,64,255))
dc.SelectObject(&brush)
dc.Rectangle(0,0,bmBitmap.bmWidth,bmBitmap.bmHeight)
mMemDC.CreateCompatibleDC(NULL)//Create Memory DC
Old_Bitmap = mMemDC.SelectObject(&m_Bitmap)//Select DC
int num = bmBitmap.bmWidth/40
dc.StretchBlt(0,0,bmBitmap.bmWidth,bmBitmap.bmHeight,&mMemDC,0,0,bmBitmap.bmWidth,bmBitmap.bmHeight,SRCCOPY)
mMemDC.SelectObject(Old_Bitmap)//Select Bitmap
}
//IDB_BITMAP1是添加的位图资源。
然后在MainFrm.cpp中OnCreate函数开始处
m_pSplashWindow = new CSplashWnd()
// CRect rect(10,10,500,500)
// m_pSplashWindow->Create(NULL,NULL,0,rect,NULL,0)
m_pSplashWindow->CreateSplash()
m_pSplashWindow->CenterWindow()
m_pSplashWindow->ShowWindow(SW_SHOW)
m_pSplashWindow->UpdateWindow()
// Sleep(2000)
m_pSplashWindow->DestroyWindow()
//m_pSplashWindow 要在头文件中声明,并要在析构函数中delete。不过这破程序没必要,不知道自己当时为什么要这样写,动态内存使用麻烦容易出错,直接在这个函数中构造对象就可以了,不用什么动态申请,也就不用在头文件中声明什么指针了。自己懒得改,你觉得有必要就改下吧
(__thiscall A::* ) 表示指向A的成员函数的函数指针(__thiscall CWnd::* ) 表示指向CWnd的成员函数的函数指针。
VC6,VC2005的消息处理函数参数有些变化,他错误提示怎么改你就怎么改成对应的就是了。
你自定义消息处理函数声明写错了吧,你看提示:
LPCTSTR ,应该是LRESULT
void OnLButtonDblClk(UINT nFlags, CPoint point)你确定要为CEdit控件添加鼠标响应事件?
右击改控件->"属性",找到
那个闪电状图标,点击
在对应的后面下拉,“添加OnXXXX()”
但是没有鼠标事件NM_DBLCLK。
如真要添加,须在.h和.cpp文件分别添加:
DECLARE_MESSAGE_MAP()
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point)
和
BEGIN_MESSAGE_MAP(CPlot, CStatic)
ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()
并实现void OnLButtonDblClk(UINT nFlags, CPoint point)这个函数
希望能有帮助
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)