syswow64 net.dll:制作启动界面

来源:百度文库 编辑:中财网 时间:2024/03/29 23:16:51
如果自己写的程序有一个漂亮的启动界面,那样效果是很不错的!
要做到这一点也很简单。
首先要创建一个启动窗口类,名为Csplash。
对应有一个头文件和一个源文件splash.h和splash.cpp。
splash.h
******************************************************************************************************
#if !defined SPLASH_H
#define SPLASH_H

// WzdSplsh.h : header file
//
#include "btmap.h"
/////////////////////////////////////////////////////////////////////////////
// CWzdSplash window
class Csplash : public CWnd
{
// Construction
public:
    Csplash();
// Attributes
public:
// Operations
public:
    void Create( UINT nBitmapID );
// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CWzdSplash)
    //}}AFX_VIRTUAL
// Implementation
public:
    virtual ~Csplash();
    // Generated message map functions
protected:
    //{{AFX_MSG(CWzdSplash)
    afx_msg void OnPaint();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    Cbtmap m_bitmap;
};
/////////////////////////////////////////////////////////////////////////////
#endif

splash.cpp
************************************************************************************************
#include "stdafx.h"
#include "splash.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWzdSplash

Csplash::Csplash()
{
}
Csplash::~Csplash()
{
}
BEGIN_MESSAGE_MAP(Csplash, CWnd)
    //{{AFX_MSG_MAP(CWzdSplash)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWzdSplash message handlers

void Csplash::OnPaint() 
{
    CPaintDC dc(this); // device context for painting

    // get bitmap colors
    CPalette *pOldPal = dc.SelectPalette(m_bitmap.GetPalette(),FALSE);
    dc.RealizePalette();

    // get device context to select bitmap into
    CDC dcComp;
    dcComp.CreateCompatibleDC(&dc);
    dcComp.SelectObject(&m_bitmap);

    // draw bitmap
    dc.BitBlt(0,0,m_bitmap.m_Width,m_bitmap.m_Height, &dcComp, 0,0,SRCCOPY);

    // reselect old palette
    dc.SelectPalette(pOldPal,FALSE);
}

void Csplash::Create( UINT nID )
{
    m_bitmap.LoadBitmapEx(nID,FALSE);

    int x = (::GetSystemMetrics (SM_CXSCREEN)-m_bitmap.m_Width)/2;
    int y = (::GetSystemMetrics (SM_CYSCREEN)-m_bitmap.m_Height)/2;
    CRect rect(x,y,x+m_bitmap.m_Width,y+m_bitmap.m_Height);
    CreateEx(0,AfxRegisterWndClass(0),"",WS_POPUP|WS_VISIBLE|WS_BORDER,rect,NULL,0);
}

因为启动图片是一位图形式展现的,还要有一个封装位图的类Cbtmap.
btmap.h
***************************************************************************************
#ifndef BTMAP_H
#define BTMAP_H

class Cbtmap : public CBitmap
{
public:
    DECLARE_DYNAMIC(Cbtmap)

// Constructors
    Cbtmap();

    void LoadBitmapEx(UINT nID, BOOL bIconBkgrd );
    CPalette *GetPalette(){return m_pPalette;};

// Implementation
public:
    virtual ~Cbtmap();

// Attributes
    int    m_Width;
    int m_Height;
// Operations

private:
    CPalette *m_pPalette;
};
#endif


btmap.cpp
*******************************************************************************
#include "stdafx.h"
#include "btmap.h"

/////////////////////////////////////////////////////////////////////////////
// CWzdBitmap

IMPLEMENT_DYNAMIC(Cbtmap, CBitmap)


Cbtmap::Cbtmap()
{
    m_pPalette=NULL;
}

Cbtmap::~Cbtmap()
{
    if (m_pPalette)
    {
        delete m_pPalette;
    }
}

void Cbtmap::LoadBitmapEx(UINT nID, BOOL bTransparent )
{
// can only load once
    ASSERT(!m_pPalette);

    CDC dcScreen;
    dcScreen.Attach(::GetDC(NULL));

// find and lock bitmap resource
    HRSRC hRsrc = FindResource(AfxGetResourceHandle(),MAKEINTRESOURCE(nID),RT_BITMAP);
    HGLOBAL hglb = LoadResource(AfxGetResourceHandle(), hRsrc);
    LPBITMAPINFOHEADER lpBitmap = (LPBITMAPINFOHEADER)LockResource(hglb);

// get pointers into bitmap structures (header, color table and picture bits)
    LPBITMAPINFO pBitmapInfo = (LPBITMAPINFO)lpBitmap;
    LPBITMAPINFOHEADER pBitmapInfoHeader = (LPBITMAPINFOHEADER)lpBitmap;
     // if the picture data uses more then 8 bits per pixel, there's
    // no color table to turn into a palette
    int nNumberOfColors=0;
    if (lpBitmap->biClrUsed)
        nNumberOfColors = lpBitmap->biClrUsed;
    else if (pBitmapInfoHeader->biBitCount <= 8)
           nNumberOfColors = (1<biBitCount);
    LPBYTE pBitmapPictureData = (LPBYTE)lpBitmap+lpBitmap->biSize+
                    (nNumberOfColors*sizeof(RGBQUAD));

    // get width and height
    m_Width = lpBitmap->biWidth;
    m_Height = lpBitmap->biHeight;

// create a logical palette from the color table in this bitmap 
    if (nNumberOfColors)
    {
        LOGPALETTE *pLogPal = (LOGPALETTE *)new BYTE[
            sizeof(LOGPALETTE) + (nNumberOfColors * sizeof(PALETTEENTRY))];
        pLogPal->palVersion    = 0x300;
        pLogPal->palNumEntries = nNumberOfColors;

        for (int i = 0; i < nNumberOfColors; i++)
        {
// if flag set, replace grey color with window's background color
            if (bTransparent && 
                    pBitmapInfo->bmiColors[i].rgbRed==192 &&
                    pBitmapInfo->bmiColors[i].rgbGreen==192 &&
                    pBitmapInfo->bmiColors[i].rgbBlue==192)
            {
                pBitmapInfo->bmiColors[i].rgbRed= GetRValue(::GetSysColor(COLOR_BTNFACE));
                pBitmapInfo->bmiColors[i].rgbGreen=GetGValue(::GetSysColor(COLOR_BTNFACE));
                pBitmapInfo->bmiColors[i].rgbBlue= GetBValue(::GetSysColor(COLOR_BTNFACE));
            }
            pLogPal->palPalEntry[i].peRed   = pBitmapInfo->bmiColors[i].rgbRed;
            pLogPal->palPalEntry[i].peGreen = pBitmapInfo->bmiColors[i].rgbGreen;
            pLogPal->palPalEntry[i].peBlue = pBitmapInfo->bmiColors[i].rgbBlue;
            pLogPal->palPalEntry[i].peFlags = 0;
        }
        m_pPalette=new CPalette;
        m_pPalette->CreatePalette(pLogPal);
        delete []pLogPal;
        dcScreen.SelectPalette(m_pPalette,TRUE);
        dcScreen.RealizePalette();
    }
    
// create device dependant bitmap
    HBITMAP bitmap = ::CreateDIBitmap(dcScreen.m_hDC, pBitmapInfoHeader, CBM_INIT, pBitmapPictureData, 
                                    pBitmapInfo, DIB_RGB_COLORS);

// attach this new bitmap object to our CBitmap class
    Attach(bitmap);

// release dc
    ::ReleaseDC(NULL, dcScreen.Detach());
}


最后,在程序主函数里,InitInstance()的开始处加如下代码: 
Csplash wndSplash;
wndSplash.Create(IDB_WZDSPLASH);//插入位图,位图id号为:IDB_WZDSPLASH
wndSplash.UpdateWindow(); //send WM_PAINT
Sleep(2000);//可选
别忘了,主函数里要添加相关头文件。可见,这种小技巧的可扩展性是很好的。