1、主界面对话框;
2、登录界面对话框;(图片控件、BITMAP)
3、CSplashDlg类;(OnInitDialog())
BOOL CSplashDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: Add extra initialization here //创建字体 CFont font; HRGN wndRgn; CDC dc, *pDC = GetDC(); font.CreateFont( 60, // nHeight 30, // nWidth 0, // nEscapement 0, // nOrientation FW_BOLD, // nWeight /*FW_BOLD*/FW_NORMAL FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut GB2312_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("楷体")); // lpszFacename黑体 if (pDC && dc.CreateCompatibleDC(pDC)) { CRect rect; ::GetClientRect(GetSafeHwnd(), &rect); dc.SelectObject(&font); CSize size; CString strText = _T("欢迎登陆Taily段软件系统"); //计算要输出的字符串的高度和宽度 ::GetTextExtentPoint32(dc.GetSafeHdc(), strText, strText.GetLength(), &size); //居中输出,计算文字要输出的位置 int x = (rect.Width()-size.cx)/2; int y = (rect.Height()-size.cy)/2; dc.SetBkMode(TRANSPARENT); //开始记录窗体轮廓路径 dc.BeginPath(); dc.TextOut(x, y, strText, strText.GetLength()); dc.EndPath(); //把所记录的路径转化为窗体轮廓句柄 wndRgn = PathToRegion(dc.GetSafeHdc()); //赋予窗体指定的轮廓形状 SetWindowRgn(wndRgn, TRUE); DeleteObject(wndRgn); dc.DeleteDC(); ReleaseDC(pDC); } ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW); //VC++程序不在任务栏显示 return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
#pragma once #include "SplashDlg.h" // CSplashThread class CSplashThread : public CWinThread { DECLARE_DYNCREATE(CSplashThread) protected: CSplashThread(); // protected constructor used by dynamic creation virtual ~CSplashThread(); public: virtual BOOL InitInstance(); virtual int ExitInstance(); void HideSplash(); CSplashDlg* m_pSplashDlg; //声明一个对话框指针 protected: DECLARE_MESSAGE_MAP() };
// SplashThread.cpp : implementation file // #include "stdafx.h" #include "LoginUI.h" #include "SplashThread.h" #include "SplashDlg.h" // CSplashThread IMPLEMENT_DYNCREATE(CSplashThread, CWinThread) CSplashThread::CSplashThread() { } CSplashThread::~CSplashThread() { } BOOL CSplashThread::InitInstance() { ::AttachThreadInput(m_nThreadID, AfxGetApp()->m_nThreadID, TRUE ); //通常系统内的每个线程都有自己的输入队列。本函数允许线程和进程共享输入队列。连接了线程后,输入焦点、窗口激活、鼠标捕获、键盘状态以及输入队列状态都会进入共享状态 . (这个函数可以不用) m_pSplashDlg = new CSplashDlg; m_pSplashDlg->Create(IDD_SPLASH); m_pSplashDlg->ShowWindow(SW_SHOW); return TRUE; } int CSplashThread::ExitInstance() { m_pSplashDlg->DestroyWindow(); delete m_pSplashDlg; return CWinThread::ExitInstance(); } // CSplashThread message handlers void CSplashThread::HideSplash() { m_pSplashDlg->SendMessage(WM_CLOSE); } BEGIN_MESSAGE_MAP(CSplashThread, CWinThread) END_MESSAGE_MAP()
5、CLoginUIApp中添加;
CSplashThread* pSplashThread; CSplashDlg* m_pSplashDlg;
BOOL CLoginUIApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. pSplashThread = (CSplashThread*) AfxBeginThread( RUNTIME_CLASS(CSplashThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); ASSERT(pSplashThread->IsKindOf(RUNTIME_CLASS(CSplashThread))); pSplashThread->ResumeThread(); Sleep(2000); pSplashThread->HideSplash();//添加这段代码 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); // Create the shell manager, in case the dialog contains // any shell tree view or shell list view controls. CShellManager *pShellManager = new CShellManager; // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("Local AppWizard-Generated Applications")); CLoginUIDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Delete the shell manager created above. if (pShellManager != NULL) { delete pShellManager; } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }