| 1 |
/* |
|---|
| 2 |
Module : SPLASHER.H |
|---|
| 3 |
Purpose: A splash screen component for MFC which uses a DIB bitmap |
|---|
| 4 |
instead of a resource. Palette management code is also included |
|---|
| 5 |
so that the bitmap will display using its own optimized palette |
|---|
| 6 |
Created: PJN / 15-11-1996 |
|---|
| 7 |
|
|---|
| 8 |
Copyright (c) 1996 - 2004 by PJ Naughter. |
|---|
| 9 |
|
|---|
| 10 |
All rights reserved. |
|---|
| 11 |
|
|---|
| 12 |
Copyright / Usage Details: |
|---|
| 13 |
|
|---|
| 14 |
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise) |
|---|
| 15 |
when your product is released in binary form. You are allowed to modify the source code in any way you want |
|---|
| 16 |
except you cannot modify the copyright details at the top of each module. If you want to distribute source |
|---|
| 17 |
code with your application, then you are only allowed to distribute versions released by the author. This is |
|---|
| 18 |
to maintain a single distribution point for the source code. |
|---|
| 19 |
|
|---|
| 20 |
*/ |
|---|
| 21 |
|
|---|
| 22 |
#ifndef __SPLASHER_H__ |
|---|
| 23 |
#define __SPLASHER_H__ |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
///////////////// Includes ///////////////////////// |
|---|
| 27 |
|
|---|
| 28 |
#ifndef __AFXMT_H__ |
|---|
| 29 |
#pragma message("To avoid this message, please put afxmt.h in your Precompiled Header (normally stdafx.h)") |
|---|
| 30 |
#include <afxmt.h> |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
///////////////// Classes ////////////////////////// |
|---|
| 36 |
|
|---|
| 37 |
class CSplashWnd : public CWnd |
|---|
| 38 |
{ |
|---|
| 39 |
public: |
|---|
| 40 |
//Constructors / Destructors |
|---|
| 41 |
CSplashWnd(); |
|---|
| 42 |
virtual ~CSplashWnd(); |
|---|
| 43 |
|
|---|
| 44 |
protected: |
|---|
| 45 |
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND, COLORREF, BYTE, DWORD); |
|---|
| 46 |
|
|---|
| 47 |
DECLARE_DYNCREATE(CSplashWnd); |
|---|
| 48 |
|
|---|
| 49 |
//Virtual methods |
|---|
| 50 |
virtual BOOL Create(); |
|---|
| 51 |
virtual BOOL LoadBitmap(); |
|---|
| 52 |
|
|---|
| 53 |
//Misc methods |
|---|
| 54 |
void SetBitmapToUse(const CString& sFilename); |
|---|
| 55 |
BOOL SetTransparent(COLORREF clrTransparent = RGB(255, 0, 255)); |
|---|
| 56 |
void SetDropShadow(BOOL bDropShadow = TRUE); |
|---|
| 57 |
void SetBitmapToUse(UINT nResourceID); |
|---|
| 58 |
void SetBitmapToUse(LPCTSTR pszResourceName); |
|---|
| 59 |
void SetOKToClose() { m_bOKToClose = TRUE; }; |
|---|
| 60 |
void SetIcon(HICON hIcon); |
|---|
| 61 |
BOOL SelRelPal(BOOL bForceBkgnd); |
|---|
| 62 |
void CreatePaletteFromBitmap(); |
|---|
| 63 |
void SetDraggable(BOOL bDragable); |
|---|
| 64 |
BOOL TransparencyAvailable() const { return m_lpfnSetLayeredWindowAttributes != NULL; }; |
|---|
| 65 |
|
|---|
| 66 |
//{{AFX_VIRTUAL(CSplashWnd) |
|---|
| 67 |
//}}AFX_VIRTUAL |
|---|
| 68 |
|
|---|
| 69 |
//{{AFX_MSG(CSplashWnd) |
|---|
| 70 |
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); |
|---|
| 71 |
afx_msg void OnPaint(); |
|---|
| 72 |
afx_msg void OnLButtonDown(UINT nFlags, CPoint point); |
|---|
| 73 |
afx_msg void OnPaletteChanged(CWnd* pFocusWnd); |
|---|
| 74 |
afx_msg BOOL OnQueryNewPalette(); |
|---|
| 75 |
afx_msg void OnClose(); |
|---|
| 76 |
//}}AFX_MSG |
|---|
| 77 |
|
|---|
| 78 |
DECLARE_MESSAGE_MAP() |
|---|
| 79 |
|
|---|
| 80 |
//Member variables |
|---|
| 81 |
BOOL m_bOKToClose; //Ok to respond to WM_CLOSE messages |
|---|
| 82 |
CBitmap m_Bitmap; //The Bitmap we are displaying |
|---|
| 83 |
CPalette m_Palette; //The palette associated with the bitmap |
|---|
| 84 |
int m_nHeight; //The height in pixels of the bitmap |
|---|
| 85 |
int m_nWidth; //The width in pixels of the bitmap |
|---|
| 86 |
CWnd m_wndOwner; //Our hidden window parent (causes this window not to have a entry in the task bar) |
|---|
| 87 |
BOOL m_bUseFile; //Should we use m_sFilename when it comes time to call LoadBitmap |
|---|
| 88 |
LPCTSTR m_pszResourceName; //The resource ID if m_bUseFile is FALSE |
|---|
| 89 |
CString m_sFilename; //The name of the file to load the bitmap from (used if m_bUseFile is TRUE) |
|---|
| 90 |
HICON m_hIcon; //The icon to use for this window |
|---|
| 91 |
BOOL m_bTransparent; //Should the image be drawn transparent |
|---|
| 92 |
COLORREF m_clrTransparent; //The transparent color to use |
|---|
| 93 |
BOOL m_bDraggable; //Should the splash window be draggable |
|---|
| 94 |
lpfnSetLayeredWindowAttributes m_lpfnSetLayeredWindowAttributes; //Pointer to the function "SetLayeredWindowAttributes" |
|---|
| 95 |
BOOL m_bDropShadow; //Should the window have a drop shadow effect |
|---|
| 96 |
|
|---|
| 97 |
friend class CSplashThread; //To allow the splash thread class to access to this classes members |
|---|
| 98 |
friend class CSplashFactory; //To allow the class factory to access to this classes members |
|---|
| 99 |
}; |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
//GUI thread in which the splash window is run |
|---|
| 103 |
class CSplashThread : public CWinThread |
|---|
| 104 |
{ |
|---|
| 105 |
protected: |
|---|
| 106 |
//Constructors / Destructors |
|---|
| 107 |
CSplashThread(); |
|---|
| 108 |
virtual ~CSplashThread(); |
|---|
| 109 |
|
|---|
| 110 |
DECLARE_DYNCREATE(CSplashThread) |
|---|
| 111 |
|
|---|
| 112 |
//{{AFX_VIRTUAL(CSplashThread) |
|---|
| 113 |
virtual BOOL InitInstance(); |
|---|
| 114 |
//}}AFX_VIRTUAL |
|---|
| 115 |
|
|---|
| 116 |
//{{AFX_MSG(CSplashThread) |
|---|
| 117 |
//}}AFX_MSG |
|---|
| 118 |
|
|---|
| 119 |
DECLARE_MESSAGE_MAP() |
|---|
| 120 |
|
|---|
| 121 |
//Member variables |
|---|
| 122 |
CRuntimeClass* m_pRuntimeClassSplashWnd; //The runtime class version of "m_pSplashScreen" |
|---|
| 123 |
CSplashWnd* m_pSplashScreen; //Pointer the CWnd splash screen |
|---|
| 124 |
CEvent m_SplashCreated; //Event using to synchronise our startup |
|---|
| 125 |
BOOL m_bInitOK; //Was InitInstance successful |
|---|
| 126 |
|
|---|
| 127 |
friend class CSplashFactory; //To allow the class factory to access to this classes members |
|---|
| 128 |
}; |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
//Class which looks after creating the splash window in the separate thread |
|---|
| 132 |
class CSplashFactory |
|---|
| 133 |
{ |
|---|
| 134 |
public: |
|---|
| 135 |
//Constructors / Destructors |
|---|
| 136 |
CSplashFactory(); |
|---|
| 137 |
~CSplashFactory(); |
|---|
| 138 |
|
|---|
| 139 |
//Methods |
|---|
| 140 |
BOOL Create(CRuntimeClass* pRuntimeClassSplashWnd); |
|---|
| 141 |
BOOL Close(CWnd* pWndToGainFocus = NULL); |
|---|
| 142 |
|
|---|
| 143 |
protected: |
|---|
| 144 |
CSplashThread* m_pSplashThread; //The GUI thread we are managing |
|---|
| 145 |
}; |
|---|
| 146 |
|
|---|
| 147 |
#endif //__SPLASHER_H__ |
|---|