📄 splashwnd.c
字号:
// is it the first opaque pixel ? if( bOpaque && xFirst<0 ) { xFirst = x ; } // is it the first transparent pixel ? // or is it the end ? if( xFirst>=0 && ( !bOpaque || x==w-1 ) ) { // get offset to RECT array if RGNDATA buffer RECT * pRect = (RECT*)pRgnData->Buffer + pRgnData->rdh.nCount++ ; // save current RECT pRect->left = xFirst ; pRect->top = h - y - 1 ; pRect->right = x - bOpaque ; // +1 if end of line pRect->bottom = h - y ; // buffer full ? if( pRgnData->rdh.nCount*sizeof(RECT) >= pRgnData->rdh.nRgnSize ) { // resize buffer pRgnData->rdh.nRgnSize += nBlockSize ; pRgnData = (RGNDATA*) realloc (pRgnData, sizeof(RGNDATAHEADER)+pRgnData->rdh.nRgnSize) ; if( ! pRgnData ) return NULL ; } // reset first index xFirst = -1 ; } } } HRGN hRgn = ExtCreateRegion (NULL, sizeof(RGNDATAHEADER)+pRgnData->rdh.nCount*sizeof(RECT), pRgnData) ; free (pRgnData) ; return hRgn;}VOID _SplashWnd_BltImage (HWND hwnd, HDC hdc, FIBITMAP * pfibImage){ HDC hdcImage ; UINT w, h ; BOOL bRes ; HBITMAP hbmImage ; TCHAR szBuffer[1024] ; if( FreeImage_GetColorType(pfibImage)!=FIC_RGBALPHA ) MessageBox (hwnd, TEXT("No alpha channel"), NULL, 0) ; hdcImage = CreateCompatibleDC (hdc) ; hbmImage = CreateDIBitmap (hdc, FreeImage_GetInfoHeader(pfibImage), CBM_INIT, FreeImage_GetBits(pfibImage), FreeImage_GetInfo(pfibImage), DIB_RGB_COLORS) ; if( FreeImage_GetInfo(pfibImage)->bmiHeader.biBitCount!=32 ) MessageBox (hwnd, TEXT("No alpha channel"), NULL, 0) ; if( ! hbmImage ) { MessageBox (hwnd, TEXT("Failed to create bitmap"), NULL, 0) ; return ; } w = FreeImage_GetWidth(pfibImage) ; h = FreeImage_GetHeight(pfibImage) ; SelectObject (hdcImage, hbmImage) ; SetLastError (0) ; bRes = BitBlt (hdc, 0, 0, w, h, hdcImage, 0, 0, SRCCOPY) ; if( ! bRes ) { wsprintf (szBuffer, TEXT("BitBlt failed (error=%d)"), GetLastError()) ; MessageBox (hwnd, szBuffer, NULL, 0) ; }}LRESULT CALLBACK _SplashWnd_LayeredWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ static int g_nOpacity ; static HINSTANCE g_hInstance ; static int g_nDelta ; static BOOL g_bWantClose ; static int g_nShowTime ; LONG nStyle ; BLENDFUNCTION bf ; FIBITMAP *pfibImage ; switch (message) { case WM_CREATE: g_hInstance = ((CREATESTRUCT*)lParam)->hInstance ; g_nDelta = SHOW_SPEED ; g_bWantClose = FALSE ; g_nShowTime = 0 ; g_nOpacity = 0 ; nStyle = GetWindowLong (hwnd, GWL_EXSTYLE) ; SetWindowLong (hwnd, GWL_EXSTYLE, WS_EX_LAYERED|nStyle) ; pfibImage = _SplashWnd_LoadFromResource (g_hInstance, MAKEINTRESOURCE(IDB_SPLASH)) ; if( ! pfibImage ) { DestroyWindow (hwnd) ; return 0 ; } _SplashWnd_SetImage (g_hInstance, hwnd, pfibImage, g_nOpacity) ; FreeImage_Unload (pfibImage) ; SetTimer (hwnd, 0, 70, NULL) ; return 0 ; case WM_TIMER: { if( g_nDelta ) { g_nOpacity += g_nDelta ; if( g_nOpacity>255 ) { g_nOpacity = 255 ; g_nDelta = 0 ; } if( g_nOpacity<0 ) { g_nOpacity = 0 ; g_nDelta = 0 ; DestroyWindow (hwnd) ; } bf.BlendOp = AC_SRC_OVER ; bf.BlendFlags = 0 ; bf.SourceConstantAlpha = g_nOpacity ; bf.AlphaFormat = AC_SRC_ALPHA ; UpdateLayeredWindow (hwnd, NULL, NULL, NULL, NULL, NULL, 0, &bf, ULW_ALPHA); } else { g_nShowTime++ ; if( g_bWantClose && g_nShowTime>MIN_SHOW_TIME ) g_nDelta = -HIDE_SPEED ; } } return 0 ; case WM_CLOSE: g_bWantClose = TRUE ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ;}LRESULT CALLBACK _SplashWnd_RegionnedWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ static int g_nOpacity ; static HINSTANCE g_hInstance ; static int g_nDelta ; static BOOL g_bWantClose ; static int g_nShowTime ; static FIBITMAP *g_pfibImage ; int x, y, w, h ; HDC hdc ; PAINTSTRUCT ps ; switch (message) { case WM_CREATE: g_hInstance = ((CREATESTRUCT*)lParam)->hInstance ; g_nDelta = SHOW_SPEED ; g_bWantClose = FALSE ; g_nShowTime = 0 ; g_nOpacity = 0 ; g_pfibImage = _SplashWnd_LoadFromResource (g_hInstance, MAKEINTRESOURCE(IDB_SPLASH)) ; if( ! g_pfibImage ) { DestroyWindow (hwnd) ; return 0 ; } w = FreeImage_GetWidth (g_pfibImage) ; h = FreeImage_GetHeight (g_pfibImage) ; x = (GetSystemMetrics(SM_CXFULLSCREEN) - w) / 2 ; y = (GetSystemMetrics(SM_CYFULLSCREEN) - h) / 2 ; MoveWindow (hwnd, x, y, w, h, TRUE) ; SetTimer (hwnd, 0, 70, NULL) ; SetWindowRgn (hwnd, _SplashWnd_CreateRgnFromImage (g_pfibImage, 128), TRUE) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; _SplashWnd_BltImage (hwnd, hdc, g_pfibImage) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_TIMER: { if( g_nDelta ) { g_nOpacity += g_nDelta ; if( g_nOpacity>255 ) { g_nOpacity = 255 ; g_nDelta = 0 ; } if( g_nOpacity<0 ) { g_nOpacity = 0 ; g_nDelta = 0 ; DestroyWindow (hwnd) ; } } else { g_nShowTime++ ; if( g_bWantClose && g_nShowTime>MIN_SHOW_TIME ) g_nDelta = -HIDE_SPEED ; } } return 0 ; case WM_CLOSE: g_bWantClose = TRUE ; return 0 ; case WM_DESTROY: FreeImage_Unload (g_pfibImage) ; PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ;}DWORD WINAPI _SplashWnd_Thread (void * pParam){ MSG msg ; HINSTANCE hInstance = GetModuleHandle(NULL) ; HWND hwnd = _SplashWnd_CreateWindow (hInstance) ; while( GetMessage (&msg,NULL,0,0) ) { if( !msg.hwnd ) msg.hwnd = hwnd ; TranslateMessage (&msg) ; DispatchMessage (&msg) ; } DestroyWindow (hwnd) ; return 0 ;}static DWORD g_dwThreadId ;static HANDLE g_hThread ;VOID SplashWnd_Show () { if( Config_GetInteger(CFGINT_SPLASH_SCREEN) ) g_hThread = CreateThread (NULL, 0, _SplashWnd_Thread, NULL, 0, &g_dwThreadId) ;}VOID SplashWnd_Hide (BOOL bWait) { if( g_hThread ) { PostThreadMessage (g_dwThreadId, WM_CLOSE, 0, 0) ; if( bWait ) WaitForSingleObject (g_hThread, INFINITE) ; CloseHandle (g_hThread) ; g_dwThreadId = 0 ; g_hThread = NULL ; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -