I've been playing around with win api stuff and came up with this animated splash screen. Don't know how usefull this is for 'real' games. Unfortunately it crashes when run in full screen mode :(
Anyway, play around with it and com up with improvements, ideas
You have to compile this code before running the testing code below.
Here is the testing code
Anyway, play around with it and com up with improvements, ideas
You have to compile this code before running the testing code below.
;******************************************************************************************* ; animated splash screen by nadia, Jan 2005 ; ; to run this sample code you need to compile this 'animSplash.bb' to 'animSplash.exe ; and save it in the same folder as 'test animSplash.bb' ; ; make sure you add the following declarations to the user libs: ; ; .lib "Gdi32.dll" ; api_CreateRectRgn%(X1%, Y1%, X2%, Y2%): "CreateRectRgn" ; api_CreateRoundRectRgn%(X1%, Y1%, X2%, Y2%, X3%, Y3%): "CreateRoundRectRgn" ; ; .lib "user32.dll" ; api_FindWindow_0% (lpClassName%, lpWindowName$) : "FindWindowA" ; api_SendMessage% (hWnd%, wMsg%, wParam%, lParam%): "SendMessageA" ; api_SetWindowRgn%(hWnd%, hRgn%, bRedraw): "SetWindowRgn" ; api_SetWindowPos%(hWnd% ,hWndInsertAfter%, x%, y%, cx%, cy%, wFlags%): "SetWindowPos" ; ;;******************************************************************************************* ; API Constants Const WM_CLOSE = $10 Const SWP_NOMOVE = 2 Const SWP_NOSIZE = 1 Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 ; width and height of anim splash screen app Const SCR_TITLEBAR_HEIGHT = 27 ; height of window title bar Const SCR_RADIUS = 20 ; corner radius for rounded region Const SCR_WIDTH = 250 Const SCR_HEIGHT = 200 Const APP_TITLE$ = "Animated Splash Screen" AppTitle APP_TITLE$ Graphics SCR_WIDTH,SCR_HEIGHT,16,2 roundedRgn = False ; flag for splash screen with rounded corners ; get the command line input used for displayed message msg$ = CommandLine() ; extract indicator if rounded corners are required If Instr(msg$, "[roundRect]") Then roundedRgn = True msg$ = Replace(msg$, "[roundRect]", "") End If ; if we didn't get a message via command line, set a default message If msg$ = "" Then msg$ = "loading...! End If If Not roundedRgn Then ; create the region to restrict the visible part of the splash screen app hRgn = api_CreateRectRgn(0,SCR_TITLEBAR_HEIGHT,SCR_WIDTH + 5, SCR_HEIGHT + SCR_TITLEBAR_HEIGHT +5) Else ; create a region with rounded corners hRgn = api_CreateRoundRectRgn(5,SCR_TITLEBAR_HEIGHT + 5 ,SCR_WIDTH, SCR_HEIGHT + SCR_TITLEBAR_HEIGHT - 5, SCR_RADIUS, SCR_RADIUS) End If ; get the win handle of this app hWnd = FindWindow(APP_TITLE$) ; applay the win region If hRgn <> 0 And hWnd <> 0 Then api_SetWindowRgn(hWnd, hRgn, True) ; set this app to stay as topmost window while open api_SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) End If ; create and load a font fnt = LoadFont("arial", 20, True) SetFont fnt ; set uo some variables for the text animation txtW = StringWidth(msg$) txtH = StringHeight(msg$) curX = 20 + (txtW/2) curY = 20 + (txtH/2) incX = 2 incY = 2 Repeat Cls Delay 10 ; emergency exit !!!! If KeyHit(1) End ; draw some animated lines For i = 0 To 200 Color Rand(50,255), Rand(80), 0; Rand(255) Line Rand(SCR_WIDTH), 0, Rand(SCR_WIDTH), SCR_HEIGHT Next ; bounce the message around Color 250, 200, 0 If (curX + incX - (txtW / 2) < 0 ) Or (curX + incX + (txtW / 2) > SCR_WIDTH) Then incX = incX * -1 If (curY + incY - (txtH / 2) < 0 ) Or (curY + incY + (txtH / 2) > SCR_HEIGHT) Then incY = incY * -1 curX = CurX + incX curY = CurY + incY Text curX, curY, msg$, True, True Flip Forever ;=============================== ; uses semar's code from code library ; FindWindow without class name ; api_FindWindow_0% (lpClassName%, lpWindowName$) : "FindWindowA" Function FindWindow(name$) hWnd% = api_FindWindow_0% (0,name$) Return hWnd End Function
Here is the testing code
;******************************************************************************************* ; testing animated splash screen by nadia, Jan 2005 ; ; to run this sample code you need to compile 'animSplash.bb' to 'animSplash.exe ; and save it in the same folder as this file. ; DON'T try this in FULL SCREEN MODE, it will crash!!!!! ; ; make sure you add the following declarations to the user libs: ; ; .lib "Gdi32.dll" ; api_CreateRectRgn%(X1%, Y1%, X2%, Y2%): "CreateRectRgn" ; api_CreateRoundRectRgn%(X1%, Y1%, X2%, Y2%, X3%, Y3%): "CreateRoundRectRgn" ; ; .lib "user32.dll" ; api_FindWindow_0% (lpClassName%, lpWindowName$) : "FindWindowA" ; api_SendMessage% (hWnd%, wMsg%, wParam%, lParam%): "SendMessageA" ; api_SetWindowRgn%(hWnd%, hRgn%, bRedraw): "SetWindowRgn" ; api_SetWindowPos%(hWnd% ,hWndInsertAfter%, x%, y%, cx%, cy%, wFlags%): "SetWindowPos" ; ;;******************************************************************************************* ; API Constants Const WM_CLOSE = $10 ; Splash screen data Const SPL_APP_TITLE$ = "Animated Splash Screen" ; must be the same as AppTitle of animSplash.exe Const SPL_EXE_NAME$ = "animSplash.exe" ; file name if animSplash app ; make sure 'animSplash.exe' is in the ; same folder as this app Const USE_ROUND_RECT$ = "[roundRect]" ; draws regions with rounded corners ; also send with command line ; text displayed in the animSplash.exe ; send to splash screen as command line msg$ = "loading stuff..." ; <<--- change this to anything... roundedRgn = True ; <<--- set to true for splash screen with rounded corners!!! ; create command line If roundedRgn Then cmdLine$ = msg$ + USE_ROUND_RECT$ Else cmdLine$ = msg$ End If ; run the splash screen app ExecFile(SPL_EXE_NAME$ + " " + cmdLine$) ; get the win handle of the splash screen app ; without loop the handle gets missed hWnd = 0 Repeat Delay 10 hWnd = FindWindow(SPL_APP_TITLE$) Until hWnd <> 0 ; initialise the game engine Graphics3D 640,480,16,2 ; <<<--- if you use full screen mode this will crash!!! ClsColor 0, 0, 100 ; \./\./ here you would load all the game related stuff \./\./\./\./\./\./\./\./\ ; some loops to waste time secs = 10 start# = MilliSecs() wait# = start# + (1000 * secs) Repeat elapsed# = (MilliSecs() - start#) / 1000 Cls Color 255, 255, 255 Text 10, 10, "Splash Screen Handle = " + hWnd Text 10, 30, "Rgn Handel = " + hRgn Color 255, 0, 0 Text 10, 50, "Closing Splash Screen in " + (secs - Int(elapsed#)) + " secs" Flip Until wait < MilliSecs() Cls ; finished loading the game stuff ;============================================================================== ; unload the the splash screen app If KillWindow(hWnd) Then msg$ = "Animated splash screen closed ok!" Else msg$ = "Failed to close splash screen!" End If Color 255, 255, 255 Text 10, 10, msg$ Text 10, 30, "Hit any key to close me" Flip WaitKey End Function KillWindow(hWND) If hWND = 0 Then Return ret = api_SendMessage(hWND, WM_CLOSE, 0, 0) If ret = 0 Then ; I think this always returns 0, ; regardless if the function succeeds or not Return True Else Return False End If End Function ;=============================== ; uses semar's code from code library ; FindWindow without class name ; api_FindWindow_0% (lpClassName%, lpWindowName$) : "FindWindowA" Function FindWindow(name$) hWnd% = api_FindWindow_0% (0,name$) Return hWnd End Function