厌倦了普通的打开窗体,对3D操作系统窗体界面跳出特效比较心动,但是自己还在用vc++6开发程序,从网上翻了翻,找到一个界面特效库,实现了翻转界面,这样程序在打开窗体或关闭窗体时,来这么个翻转,应该感觉不错
下面是实现步骤:
1 -------------引用头文件
在StdAfx.h里增加
#include <imm.h>
#pragma warning(disable : 4786)
#include <vector>
#include <map>
#include <string>
#include <mmsystem.h>
using std::map;
using std::vector;
using std::string;
typedef struct {
BITMAPINFOHEADER bmiHeader;
DWORD bmiColors[256];
} _BMPINFO, *BMPINFO;
#define DLL_EXPORT
#define C_DLL_EXPORT extern "C" DLL_EXPORT
#include "../clayui/UI_BASIC/CLAYUI_Config.h"
在自己主窗体的cpp(本例是switch3dDlg.cpp)里增加
#include "../CLAYUI/UI_BASIC/CLAYUI_BFRAME.h"
#include "../clayui/UI_ANIMATION/CLAYUI_ALPHA_ANIM.h"
#include "../clayui/UI_ANIMATION/CLAYUI_SCALE_ANIM.h"
#include "../clayui/UI_ANIMATION/CLAYUI_ROTATE_ANIM.h"
#include "../clayui/UI_ANIMATION/CLAYUI_MOVE_ANIM.h"
在switch3dDlg.cpp的头文件switch3dDlg.h增加头文件引用
#include "MFC_GRAPHICS.h"
#include "LAYUI_RootFrame_Wrapper.h"
同时将MFC_GRAPHICS.h LAYUI_RootFrame_Wrapper.h LAYUI_RootFrame_Wrapper.cpp MFC_GRAPHICS.cpp
加入工程
2 ---------------------switch3dDlg.h里增加变量和函数声明
void EnableControl(BOOL enable);
void Redraw(CDC *pDC);
CLAYUI_RootFrame_Wrapper m_rootframe_wrapper;
CMFC_GRAPHICS m_graphics;
CLAYUI_BFRAME* m_bframe;
CLAYUI_FRAME* m_aniframe;
BYTE* m_bgpvb;
HBITMAP m_bghbitmap;
_BMPINFO m_bgbmpinfo;
CDC m_memdc;
HBITMAP m_oldbmp;
BYTE* m_bgpvb1;
HBITMAP m_bghbitmap1;
_BMPINFO m_bgbmpinfo1;
CDC m_memdc1;
HBITMAP m_oldbmp1;
BOOL m_isInit;
BOOL m_isfocus;
BOOL m_isquit;
static LRESULT CALLBACK CtrlWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
INT64 m_timecount;
// INT64 m_timeturn;
int orix;
int oriy;
void startmovie(int xanglefrom, int xangleto,int yanglefrom, int yangleto);//启动动画
BOOL m_isanimation;
同时还有类的虚函数实现virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
afx_msg void OnTimer(UINT nIDEvent);//定时器
virtual void OnCancel();//退出按钮
afx_msg void OnClose();//窗体关闭事件
afx_msg void OnCtest();//垂直按钮
afx_msg void OnBtrun();//水平翻转
3 -----------------------cpp文件加代码
#define WS_EX_LAYERED 0x00080000
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
#define wm_init3d WM_USER+200 //
#define turn_timelen 800 //
#define move_z -1600 //
BOOL g_init=FALSE;//
BOOL g_time=FALSE;//
typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);
static PSLWA pSetLayeredWindowAttributes = NULL;//
static BOOL initialized = FALSE;//
WNDPROC g_pWndProc;
BOOL MakeWindowTransparent(HWND hWnd, unsigned char factor){
....//窗体透明
}
LRESULT CALLBACK CSwitch3dDlg::CtrlWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam){
...//控件接收消息传递
}
OnInitDialog()窗体初始化里增加代码初始化clayui对象
然后发消息可以启动动画翻转了PostMessage(wm_init3d,0,0);
然后初始化动画对象
LRESULT CSwitch3dDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(wm_init3d==message){
if(!g_init){
g_init=TRUE;
}
return CDialog::WindowProc(message, wParam, lParam);
}
另外:void CSwitch3dDlg::Redraw(CDC *pDC)这个就是具体画出效果的函数,定时器画出不同形状,就看起来像动画翻转了
csdn发博文不能带附件不太好,具体详细代码见只能放到
http://download.csdn.net/source/3391869
更多clayui库参见http://blog.csdn.net/clayui/archive/2011/06/20/6556417.aspx