00001 /* 00002 Module : SPLASHER.H 00003 Purpose: A splash screen component for MFC which uses a DIB bitmap 00004 instead of a resource. Palette management code is also included 00005 so that the bitmap will display using its own optimized palette 00006 Created: PJN / 15-11-1996 00007 00008 Copyright (c) 1996 - 2002 by PJ Naughter. 00009 00010 All rights reserved. 00011 00012 Copyright / Usage Details: 00013 00014 You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise) 00015 when your product is released in binary form. You are allowed to modify the source code in any way you want 00016 except you cannot modify the copyright details at the top of each module. If you want to distribute source 00017 code with your application, then you are only allowed to distribute versions released by the author. This is 00018 to maintain a single distribution point for the source code. 00019 00020 */ 00021 00022 #ifndef __SPLASHER_H__ 00023 #define __SPLASHER_H__ 00024 00025 00027 00028 #ifndef __AFXMT_H__ 00029 #pragma message("To avoid this message, please put afxmt.h in your Precompiled Header") 00030 #include <afxmt.h> 00031 #endif 00032 00033 00034 00036 00037 class CSplashWnd : public CWnd 00038 { 00039 public: 00040 //Constructors / Destructors 00041 CSplashWnd(); 00042 virtual ~CSplashWnd(); 00043 00044 protected: 00045 typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND, COLORREF, BYTE, DWORD); 00046 00047 DECLARE_DYNCREATE(CSplashWnd); 00048 00049 //Virtual methods 00050 virtual BOOL Create(); 00051 virtual BOOL LoadBitmap(); 00052 00053 //Misc methods 00054 void SetBitmapToUse(const CString& sFilename); 00055 BOOL SetTransparent(COLORREF clrTransparent = RGB(255, 0, 255)); 00056 void SetDropShadow(BOOL bDropShadow = TRUE); 00057 void SetBitmapToUse(UINT nResourceID); 00058 void SetBitmapToUse(LPCTSTR pszResourceName); 00059 void SetOKToClose() { m_bOKToClose = TRUE; }; 00060 void SetIcon(HICON hIcon); 00061 BOOL SelRelPal(BOOL bForceBkgnd); 00062 void CreatePaletteFromBitmap(); 00063 void SetDraggable(BOOL bDragable); 00064 BOOL TransparencyAvailable() const { return m_lpfnSetLayeredWindowAttributes != NULL; }; 00065 00066 //{{AFX_VIRTUAL(CSplashWnd) 00067 //}}AFX_VIRTUAL 00068 00069 //{{AFX_MSG(CSplashWnd) 00070 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 00071 afx_msg void OnPaint(); 00072 afx_msg void OnPaletteChanged(CWnd* pFocusWnd); 00073 afx_msg BOOL OnQueryNewPalette(); 00074 afx_msg void OnClose(); 00075 //}}AFX_MSG 00076 00077 DECLARE_MESSAGE_MAP() 00078 00079 //Member variables 00080 BOOL m_bOKToClose; //Ok to respond to WM_CLOSE messages 00081 CBitmap m_Bitmap; //The Bitmap we are displaying 00082 CPalette m_Palette; //The palette associated with the bitmap 00083 int m_nHeight; //The height in pixels of the bitmap 00084 int m_nWidth; //The width in pixels of the bitmap 00085 CWnd m_wndOwner; //Our hidden window parent (causes this window not to have a entry in the task bar) 00086 BOOL m_bUseFile; //Should we use m_sFilename when it comes time to call LoadBitmap 00087 LPCTSTR m_pszResourceName; //The resource ID if m_bUseFile is FALSE 00088 CString m_sFilename; //The name of the file to load the bitmap from (used if m_bUseFile is TRUE) 00089 HICON m_hIcon; //The icon to use for this window 00090 BOOL m_bTransparent; //Should the image be drawn transparent 00091 COLORREF m_clrTransparent; //The transparent color to use 00092 BOOL m_bDraggable; //Should the splash window be draggable 00093 lpfnSetLayeredWindowAttributes m_lpfnSetLayeredWindowAttributes; //Pointer to the function "SetLayeredWindowAttributes" 00094 BOOL m_bDropShadow; //Should the window have a drop shadow effect 00095 00096 00097 friend class CSplashThread; //To allow the splash thread class to access to this classes members 00098 friend class CSplashFactory; //To allow the class factory to access to this classes members 00099 }; 00100 00101 //GUI thread in which the splash window is run 00102 class CSplashThread : public CWinThread 00103 { 00104 protected: 00105 //Constructors / Destructors 00106 CSplashThread(); 00107 virtual ~CSplashThread(); 00108 00109 DECLARE_DYNCREATE(CSplashThread) 00110 00111 //{{AFX_VIRTUAL(CSplashThread) 00112 virtual BOOL InitInstance(); 00113 //}}AFX_VIRTUAL 00114 00115 //{{AFX_MSG(CSplashThread) 00116 //}}AFX_MSG 00117 00118 DECLARE_MESSAGE_MAP() 00119 00120 //Member variables 00121 CRuntimeClass* m_pRuntimeClassSplashWnd; //The runtime class version of "m_pSplashScreen" 00122 CSplashWnd* m_pSplashScreen; //Pointer the CWnd splash screen 00123 CEvent m_SplashCreated; //Event using to synchronise our startup 00124 BOOL m_bInitOK; //Was InitInstance successful 00125 00126 friend class CSplashFactory; //To allow the class factory to access to this classes members 00127 00128 public: 00129 static BOOL PreTranslateAppMessage(MSG* pMsg); 00130 00131 }; 00132 00133 00134 //Class which looks after creating the splash window in the separate thread 00135 class CSplashFactory 00136 { 00137 public: 00138 //Constructors / Destructors 00139 CSplashFactory(); 00140 ~CSplashFactory(); 00141 00142 //Methods 00143 BOOL Create(CRuntimeClass* pRuntimeClassSplashWnd); 00144 BOOL Close(CWnd* pWndToGainFocus = NULL); 00145 00146 protected: 00147 CSplashThread* m_pSplashThread; //The GUI thread we are managing 00148 }; 00149 00150 00151 #endif //__SPLASHER_H__ 00152 00153