News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

splash screen without window dialog

Started by diablo2oo2, July 19, 2005, 09:10:42 PM

Previous topic - Next topic

diablo2oo2

I was searching for some code to create a splashscrenn. what i found, were solutions with window dialogs. where the window must have the same size as the bitmap (or jpg) i want to show.
I would like to know if its possible to make a splashscreen without a dialog. My aim is to code something where i can use pictures with different size as splash screen. Maybe its possible to draw the picture on the desktop window? Some little example code would be nice....

QvasiModo

Sure you can, a dialog is just another kind of window. :)

At any rate you've found examples using dialogs because it's so much easier that way. BTW it's not true that you should make the dialog the same size as the bitmap, in fact this is not possible at all (dialogs may not look the same on different computers). You have to resize the dialog box instead.

Nevertheless, if you want to give "pure" windows a try, start from one of Iczelion's tutorials to show a bitmap, and turn it into a splash screen. Use the same style bits as in the sample code you already have (no border, no caption, probably topmost too).

Hope that helps! :)

diablo2oo2

thx for your reply. i already solved my problems (with a dialogbox). btw, i dont like much code (small is beautiful), so i delete always that code which is not need for the working solution ;)

diablo2oo2

i made an small example template for the splashscreen.

;******************************************************************************
;* ASM STUFF                                                                  *
;******************************************************************************
.586p
.mmx
.model flat, stdcall
option casemap :none

;******************************************************************************
;* INCLUDES (better too much...)                                              *
;******************************************************************************
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\advapi32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\ole32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\masm32.inc
include \masm32\macros\macros.asm

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\masm32.lib

include    \masm32\include\wsock32.inc
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\wininet.lib
include    \masm32\include\wininet.inc

;******************************************************************************
;* PROTOTYPES                                                                 *
;******************************************************************************
DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

;******************************************************************************
;* DATA                                                                       *
;******************************************************************************
.data?
splashscreen_hBmp dd ?

;******************************************************************************
;* CODE                                                                       *
;******************************************************************************
.code
main:
invoke GetModuleHandle,0
        invoke DialogBoxParam,eax,1,0,addr DialogProc,0
        invoke ExitProcess,0
       
DialogProc Proc uses ebx esi edi  hwnd:dword,message:dword,wParam:dword,lParam:dword
LOCAL ps:PAINTSTRUCT
        LOCAL hdc:HDC
        LOCAL hMemoryDC:HDC
        LOCAL bitmap:BITMAP
LOCAL DesktopRect:RECT

mov eax,message
.if eax==WM_INITDIALOG
;---load bitmap (jpg) from resource---
        invoke FindResource,0,chr$("SPLASH"),RT_RCDATA
mov edi,eax
invoke SizeofResource,0,eax
mov esi,eax
invoke LoadResource,0,edi
invoke BitmapFromMemory,eax,esi ;read jpg
mov splashscreen_hBmp,eax
invoke GetObject,splashscreen_hBmp,sizeof BITMAP,addr bitmap

;---Get Desktopsize---
invoke GetDesktopWindow
                mov ecx,eax
                invoke GetWindowRect,ecx,addr DesktopRect
                ;---set window size&position---
                push FALSE ;bRepaint
                push bitmap.bmHeight ;nHeight
                push bitmap.bmWidth ;nWidth
                mov  eax,DesktopRect.bottom ;calculate middle...
                sub  eax,bitmap.bmHeight
                shr  eax,1
                push eax ;y position
                mov  eax,DesktopRect.right ;calculate middle...
                sub  eax,bitmap.bmWidth
                shr  eax,1
                push eax ;x position
                push hwnd ;dialog handle
                call MoveWindow

;---Set time to show the window---
invoke SetTimer,hwnd,1,3000,0 ;3 seconds
.elseif eax==WM_TIMER
jmp @close ;time to close...
.elseif eax==WM_PAINT
;---draw bitmap---
invoke BeginPaint,hwnd,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemoryDC,eax
invoke SelectObject,eax,splashscreen_hBmp
mov esi,eax ;esi=hOldBmp
invoke GetObject,splashscreen_hBmp,sizeof BITMAP,addr bitmap ;get info about bitmap
invoke BitBlt,hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hMemoryDC,0,0,SRCCOPY ;draw bitmap
invoke SelectObject,hMemoryDC,esi ;esi=hOldBmp
invoke DeleteDC,hMemoryDC
invoke EndPaint,hwnd,addr ps
.elseif eax==WM_CLOSE
@close:
invoke EndDialog,hwnd,0 ;bye bye...
.endif
xor eax,eax
ret                          
DialogProc endp

end main


Check the attachment "splashscreen.zip" for the full sourcecode...

[attachment deleted by admin]

PBrennick

Diablo2002,
That is very nicely done.  Do you plan to throw a DLL wrapper around it?  I did that with the splash screen to my editor.  I like that method because the resource is released when it is no longer needed.  The DLL would have no exports and would run when loaded.  In the main program, you load the library (screen splashes and then exits), the main program then unloads the DLL.  To the uninitiated, the code looks like it does nothing.


        invoke  LoadLibrary, addr Libname  ; Splash screen DLL is loaded here
        .if !eax
          jmp     NoLib
        .endif
        invoke  FreeLibrary, eax          ; Splash screen DLL is unloaded here
NoLib:


Paul
The GeneSys Project is available from:
The Repository or My crappy website

diablo2oo2

QuoteDo you plan to throw a DLL wrapper around it?
no, i dont plan much to do with this. maybe it will be usefull one day...

yes, i know the loadlibrary method. i also read the iczelions tutorials. but i prefer to include much as possible into the executable

PBrennick

Yeah and with all the memory and storage that we have these days, along with speed, there is a lot tom be said for that approach.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

QvasiModo

IMHO the DLL approach is still a good thing if the splash screen is too large. Or the app is resident. Or it's meant to run in old computers.

Another good idea is to run this in another thread. That way you can keep loading your app in the background.

hutch--

I don't see the problem with running a splash acreen as a normal CreateWindowEx window, the code is small, it stays the same size on different compters, you can either directly blit the image data to it or shove it in a static control, you can leave it running while you load the rest of the app and turn it off or delete it when you are finished. This can be done in either a DLL or directly in the EXE if the image data is not too big.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php