日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

VC启动窗口画面制作方法研究

發布時間:2025/3/15 c/c++ 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VC启动窗口画面制作方法研究 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
VC啟動窗口畫面制作方法研究

源代碼運行效果圖如下:


1. 概述

前幾天在設計軟件時,選擇VC作為開發工具,想做個啟動畫面,由于以前沒有制作過,所以到網上搜了一通。網上有幾篇相關文章,有兩篇我覺得很有價值:一篇是關于 為方便顯示圖像制作的CPicture類的文章,原文是由Paul DiLascia寫的解答,很有影響力;還有一篇是關于制作真彩啟動畫面的文章,不過其限制對位圖操作,而不支持jpg, gif,而且使用繁瑣,基本上是對Splash Screen組件導入后的代碼進行簡單修改。琢磨了好大一會兒才學會使用。

有感于現有材料使用起來不方便,隨進行了整合和再封裝處理,設計了CSplashWnd類,使用起來非常簡便。下面就把我設計的類介紹給大家。有什么不當或錯誤之處,敬請指正。我的Email: zhengxiliu@sohu.com

2.CSplashWnd功能

能夠顯示真彩啟動畫面,能在畫面上顯示初始化文字信息,支持jpg,gif,bmp圖像文件。

3. CSplashWnd的設計

3.1 用戶關心的接口

用戶使用的公開接口:

public: CSplashWnd(LPCTSTR lpszFileName);// 指定作為啟動畫面的圖像文件,并裝載 BOOL ShowSplash();//顯示畫面 void CloseSplash();//關閉畫面 void ShowText(LPCTSTR pCh);在顯示的圖像上中間位置處顯示初始化信息文字

3.2 其他接口
系統使用的公開接口:(用戶不關心)

~CSplashWnd() void PostNcDestroy();

私有接口:(用戶不關心)

BOOL Create(CWnd* pParentWnd = NULL); int OnCreate(LPCREATESTRUCT lpCreateStruct); void OnPaint();

3.3 數據設計(用戶不關心)

BOOL fileIsValid//指示 CPicture pic;//用于對圖像文件進行操作的類 int width,height;

3.4 限制

√ 不允許繼承。
√ 為簡化接口,只提供從文件裝載圖像

3.5 需要的頭文件

StdAfx.h, VC++6.0自動生成的對MFC的支持,不同的工程選項會產生不同的StdAfx.h。

afxwin.h 支持CRect類

atlbase.h 提供對IPicture (COM類)的支持。

afxpriv2.h提供對CArchiveStream類的支持。

4.類的健壯性和可調試性設計

圖像文件是否有效?

需要檢查文件是否有效,當裝載圖像文件失敗時,fileIsValid為false,否則為true。這樣在調用ShowSplash時將什么都不做,返回false。這時,用戶應檢查圖像文件是否存在,文件名稱拼寫是否正確。

5. 用法

√ 將CSplashWnd類加入項目中

√ 在使用CSplashWnd類的文件中#include “Splash.h”

√ 在合適的位置定義一個CSplashWnd對象

√ 在想顯示啟動畫面的地方調用ShowSplash顯示于屏幕上

√ 如果想在啟動畫面上顯示一些初始化或其他提示信息,調用ShowText。

√ 在你想關閉啟動畫面的地方

在你的App類InitInstance函數中,顯示主窗口之前使用,進行上述步驟,這是最典型的用法,如下面代碼所示。

BOOL CTsApp::InitInstance() {AfxEnableControlContainer();#ifdef _AFXDLLEnable3dControls(); // Call this when using MFC in a shared DLL #elseEnable3dControlsStatic(); // Call this when linking to MFC statically #endifSetRegistryKey(_T("Local AppWizard-Generated Applications"));LoadStdProfileSettings(); // Load standard INI file options (including MRU)CSingleDocTemplate* pDocTemplate;pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,RUNTIME_CLASS(CTsDoc),RUNTIME_CLASS(CMainFrame), // main SDI frame windowRUNTIME_CLASS(CTsView));AddDocTemplate(pDocTemplate);CCommandLineInfo cmdInfo;ParseCommandLine(cmdInfo);if (!ProcessShellCommand(cmdInfo))return FALSE;/CSplashWnd* pCsw = new CSplashWnd("fx.jpg");//located in the local directory,or else full-path file name is neededpCsw->ShowSplash();Sleep(750);//delay some time to observe the image displayed.pCsw->CloseSplash();delete pCsw;pCsw = NULL; /// The one and only window has been initialized, so show and update it.m_pMainWnd->ShowWindow(SW_SHOW);m_pMainWnd->UpdateWindow();return TRUE; }

6. 類代碼

6.1 Splash.h

/ //Written by Liu Zhengxi //May 5,2003 //Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 // too. /#ifndef _SPLASH #define _SPLASH #include #include // Splash.h : header file /// // Splash Screen class#pragma once/// // Picture object—encapsulates IPicture //Written by Paul DiLascia. //used to display picture //// declare CPicture class //class CPicture { public:BOOL Render(CDC* pDC,CRect rc,LPCRECT prcMFBounds=NULL) const;CPicture();~CPicture();// Load from various resourcesBOOL Load(UINT nIDRes);BOOL Load(LPCTSTR pszPathName);BOOL Load(CFile& file);BOOL Load(CArchive& ar);BOOL Load(IStream* pstm);// render to device contextCSize GetImageSize(CDC* pDC=NULL) const;operator IPicture*() {return m_spIPicture;}void GetHIMETRICSize(OLE_XSIZE_HIMETRIC& cx, OLE_YSIZE_HIMETRIC& cy) const {cx = cy = 0;const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Width(&cx);ASSERT(SUCCEEDED(m_hr));const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Height(&cy);ASSERT(SUCCEEDED(m_hr));}void Free() {if (m_spIPicture) {m_spIPicture.Release();}}protected:CComQIPtr<IPicture>m_spIPicture; // ATL smart pointer to IPictureHRESULT m_hr; // last error code };/// // //declare CSplashWnd //class CSplashWnd : public CWnd { // Construction public:CSplashWnd(LPCTSTR lpszFileName); // Operations public:BOOL ShowSplash();BOOL PreTranslateAppMessage(MSG* pMsg); void ShowText(LPCTSTR lpStr);void CloseSplash(); // Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CSplashWnd)//}}AFX_VIRTUAL // Implementation public:~CSplashWnd();virtual void PostNcDestroy(); private:BOOL Create(CWnd* pParentWnd = NULL); // Generated message map functions private://{{AFX_MSG(CSplashWnd)afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnPaint();//}}AFX_MSGDECLARE_MESSAGE_MAP() private:int height;//the height of the displayed pictureint width;//the width of the displayed pictureCPicture pic;//used to operate the pictureBOOL fileIsValid; };#endif

6.2 Splash.cpp

/// //Written by Liu Zhengxi //May 5,2003 //Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 // too. /// // Splash.cpp : implementation file //#include <atlbase.h> #include <afxwin.h> #include <afxpriv2.h> #include "stdafx.h" // e. g. stdafx.h #include "Splash.h" // e.g. splash.h#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif/ // CSplashWnd class//constructor //Load image from the given file //CSplashWnd::CSplashWnd(LPCTSTR lpszFileName) {fileIsValid = pic.Load(lpszFileName);if(fileIsValid){CSize cz = pic.GetImageSize(NULL);width = cz.cx;height = cz.cy;} }//nothing to do //deconstructor // CSplashWnd::~CSplashWnd() { }//message map //BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)//{{AFX_MSG_MAP(CSplashWnd)ON_WM_CREATE()ON_WM_PAINT()ON_WM_TIMER()//}}AFX_MSG_MAP END_MESSAGE_MAP()//ShowSplash //to display the given image on screen // BOOL CSplashWnd::ShowSplash() {if(fileIsValid){if (!Create(AfxGetMainWnd()))return false;else{UpdateWindow();return true;}}else{return false;} }//PreTranslateAppMessage //BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg) {// If we get a keyboard or mouse message, hide the splash screen.if (pMsg->message == WM_KEYDOWN ||pMsg->message == WM_SYSKEYDOWN ||pMsg->message == WM_LBUTTONDOWN ||pMsg->message == WM_RBUTTONDOWN ||pMsg->message == WM_MBUTTONDOWN ||pMsg->message == WM_NCLBUTTONDOWN ||pMsg->message == WM_NCRBUTTONDOWN ||pMsg->message == WM_NCMBUTTONDOWN){CloseSplash();return TRUE; // message handled here}return FALSE; // message not handled }//Create //make a popup splash window //BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/) {return CreateEx(0,AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),NULL, WS_POPUP | WS_VISIBLE, 0, 0, width, height, pParentWnd->GetSafeHwnd(), NULL); }//CloseSplash //Quit the splash window //void CSplashWnd::CloseSplash() {// Destroy the window, and update the mainframe.DestroyWindow(); }//do nothing //void CSplashWnd::PostNcDestroy() { }//OnCreate //put the splash window on center //int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) {if (CWnd::OnCreate(lpCreateStruct) == -1)return -1;// Center the window.CenterWindow();return 0; }//OnPaint //Display the given image//void CSplashWnd::OnPaint() {CPaintDC dc(this);CRect rc(0,0,0,0);;pic.Render(&dc, rc); }//ShowText //sometimes if we show what we are doing (I display the information on the center of //the picture ), the customer will be more //patient // //void CSplashWnd::ShowText(LPCTSTR lpStr) {Invalidate();CPaintDC dc(this);dc.SetBkMode(TRANSPARENT);SIZE sz;sz = (SIZE)dc.GetTextExtent(lpStr,strlen(lpStr));dc.TextOut((width-sz.cx)/2,height/2,lpStr); }// MSDN Magazine — October 2001 // If this code works, it was written by Paul DiLascia. // If not, I don''t know who wrote it. // Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 // too. // Set tabsize = 3 in your editor. //// CPicture implementation //CPicture::CPicture() { }CPicture::~CPicture() { }// // Load from resource. Looks for "IMAGE" type. //BOOL CPicture::Load(UINT nIDRes) {// find resource in resource fileHINSTANCE hInst = AfxGetResourceHandle();HRSRC hRsrc = ::FindResource(hInst,MAKEINTRESOURCE(nIDRes),"IMAGE"); // typeif (!hRsrc)return FALSE;// load resource into memoryDWORD len = SizeofResource(hInst, hRsrc);BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);if (!lpRsrc)return FALSE;// create memory file and load itCMemFile file(lpRsrc, len);BOOL bRet = Load(file);FreeResource(hRsrc);return bRet; }// // Load from path name. //BOOL CPicture::Load(LPCTSTR pszPathName) {CFile file;if (!file.Open(pszPathName, CFile::modeRead|CFile::shareDenyWrite))return FALSE;BOOL bRet = Load(file);file.Close();return bRet; }// // Load from CFile //BOOL CPicture::Load(CFile& file) {CArchive ar(&file, CArchive::load | CArchive::bNoFlushOnDelete);return Load(ar); }// // Load from archive—create stream and load from stream. //BOOL CPicture::Load(CArchive& ar) {CArchiveStream arcstream(&ar);return Load((IStream*)&arcstream); }// // Load from stream (IStream). This is the one that really does it: call // OleLoadPicture to do the work. //BOOL CPicture::Load(IStream* pstm) {Free();HRESULT hr = OleLoadPicture(pstm, 0, FALSE,IID_IPicture, (void**)&m_spIPicture);ASSERT(SUCCEEDED(hr) && m_spIPicture); return TRUE; }// // Get image size in pixels. Converts from HIMETRIC to device coords. //CSize CPicture::GetImageSize(CDC* pDC) const {if (!m_spIPicture)return CSize(0,0);LONG hmWidth, hmHeight; // HIMETRIC unitsm_spIPicture->get_Width(&hmWidth);m_spIPicture->get_Height(&hmHeight);CSize sz(hmWidth,hmHeight);if (pDC==NULL) {CWindowDC dc(NULL);dc.HIMETRICtoDP(&sz); // convert to pixels} else {pDC->HIMETRICtoDP(&sz);}return sz; }// // Render to device context. Covert to HIMETRIC for IPicture. //BOOL CPicture::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const {ASSERT(pDC);if (rc.IsRectNull()) {CSize sz = GetImageSize(pDC);rc.right = sz.cx;rc.bottom = sz.cy;}long hmWidth,hmHeight; // HIMETRIC unitsGetHIMETRICSize(hmWidth, hmHeight);m_spIPicture->Render(*pDC, rc.left, rc.top, rc.Width(), rc.Height(),0, hmHeight, hmWidth, -hmHeight, prcMFBounds);return TRUE; }

參考連接:

總結

以上是生活随笔為你收集整理的VC启动窗口画面制作方法研究的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久免费久久 | 久久久精品免费视频 | 夜噜噜| 女人夜夜春 | 久久在线电影 | 天堂√ | 一级黄色录象 | 日本少妇一区二区三区 | 欧美黄色网 | 少妇做爰免费理伦电影 | 婷婷国产精品 | 中文字幕电影av | 色蜜桃av | av男人天堂av| 免费av网站在线 | 午夜成人影片 | 亚洲欧美变态另类丝袜第一区 | 久久国产免费观看 | 日本中文字幕有码 | 欧美一区二区三区免费看 | 久久精品日韩无码 | 国产第一草草影院 | 在线看黄色片 | 强乱中文字幕av一区乱码 | 国产乱国产乱老熟300部视频 | 国产妇女乱一性一交 | 天堂色av | 日韩欧美亚洲一区 | 天天干天天舔 | 黄片毛片在线 | 温柔少妇的高潮呻吟 | 求av网站| 欧美一区影院 | 夜夜骑av| 久久99精品国产麻豆婷婷洗澡 | 一级毛毛片 | 亚洲一级网 | 91日日| 欧美色图亚洲激情 | 少妇裸体性生交 | 免费在线观看网址入口 | 国产精品高潮呻吟久久av野狼 | 少妇人妻真实偷人精品视频 | 亚洲网站av | 在线观看国产欧美 | 激情久久婷婷 | 麻豆免费看片 | 开心激情深爱 | 黄色在线观看视频网站 | 在线v | 欧美激情片一区二区 | feel性丰满白嫩嫩hd | 91你懂的 | av日韩精品 | 午夜羞羞影院 | 日韩av中文字幕在线播放 | 在线免费观看一区二区三区 | 男女激情在线观看 | 成人啪啪网站 | 337p日本欧洲亚洲大胆精筑 | 色九月婷婷 | 日韩不卡在线视频 | 最好看的mv中文字幕国语电影 | 91蝌蚪少妇偷拍 | 国产成人久久久 | 国产香蕉久久 | 日韩一级完整毛片 | 91高清在线视频 | 嫩模啪啪 | 人乳喂奶hd无中字 | 精品一区二区久久久久蜜桃 | www.色欧美| wwwxxx日本 | 国产 福利 在线 | 国产亚洲精品久久久久动 | 亚洲小说专区 | 理论片一级 | 17c在线观看| 狠狠操狠狠摸 | 欧美日韩一区二区三区不卡视频 | 丁香啪啪综合成人亚洲 | 国产91绿帽单男绿奴 | jzz国产 | 国产一区二区三区视频网站 | 亚洲成人黄色小说 | 久久久久久黄 | 午夜少妇av | gav在线 | 国产欧美一区二区三区免费看 | 泰剧19禁啪啪无遮挡 | 亚洲香蕉在线观看 | 国产一区二区av | 亚洲成av人片 | 日韩欧美黄色片 | 亚洲色图偷拍视频 | 免费一级片网址 | 久久人人人| 日韩精品一区二区三区在线播放 | 亚洲国产欧美一区二区三区深喉 |