📄 lion-tutorial26.htm
字号:
<html>
<head>
<link rel="stylesheet" href="../../asm.css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Iczelion's win32 asm tutorial</title>
</head>
<body bgcolor="#FFFFFF" background="../../images/back01.jpg">
<p align="center">Tutorial 26: Splash Screen</p>
<hr size="1">
<strong> </strong> Now that we know how to use a bitmap, we can progress to a
more creative use of it. Splash screen. Download <a href="files/tut26.zip">the
example</a>.
<h3> <b>Theory</b></h3>
A splash screen is a window that has no title bar, no system menu box, no border
that displays a bitmap for a while and then disappears automatically. It's usually
used during program startup, to display the program's logo or to distract the
user's attention while the program does some lengthy initialization. We will implement
a splash screen in this tutorial. <br>
The first step is to include the bitmap in the resource file. However, if you
think of it, it's a waste of precious memory to load a bitmap that will
be used only once and keep it in memory till the program is closed. A better solution
is to create a *resource* DLL which contains the bitmap and has the sole purpose
of displaying the splash screen. This way, you can load the DLL when you want
to display the splash screen and unload it when it's not necessary anymore. So
we will have two modules: the main program and the splash DLL. We will put the
bitmap into the DLL's resource. <br>
The general scheme is as follows:
<ol>
<li> Put the bitmap into the DLL as a bitmap resource</li>
<li> The main program calls LoadLibrary to load the dll into memory</li>
<li> The DLL entrypoint function of the DLL is called. It will create a timer
and set the length of time that the splash screen will be displayed. Next
it will register and create a window without caption and border and
display the bitmap in the client area.</li>
<li> When the specified length of time elapsed, the splash screen is removed
from the screen and the control is returned to the main program</li>
<li> The main program calls FreeLibrary to unload the DLL from memory and then
goes on with whatever task it is supposed to do.</li>
</ol>
We will examine the mechanisms in detail.
<h3> Load/Unload DLL</h3>
You can dynamically load a DLL with LoadLibrary function which has the following
syntax:
<blockquote>LoadLibrary proto lpDLLName:DWORD</blockquote>
It takes only one parameter: the address of the name of the DLL you want to load
into memory. If the call is successful, it returns the module handle of the DLL
else it returns NULL. <br>
To unload a DLL, call FreeLibrary:
<blockquote>FreeLibrary proto hLib:DWORD</blockquote>
It takes one parameter: the module handle of the DLL you want to unload. Normally,
you got that handle from LoadLibrary
<h3> <b>How to use a timer</b></h3>
First, you must create a timer first with SetTimer:
<blockquote>SetTimer proto hWnd:DWORD, TimerID:DWORD, uElapse:DWORD,
lpTimerFunc:DWORD
<p><b>hWnd</b> is the handle of a window that will receive the timer notification
message. This parameter can be NULL to specify that there is no window that's
associated with the timer. <br>
<b>TimerID</b> is a user-defined value that is used as the ID of the timer.
<br>
<b>uElapse </b>is the time-out value in milliseconds. <br>
<b>lpTimerFunc </b>is the address of a function that will process the timer
notification messages. If you pass NULL, the timer messages will be sent to
the window specified by hWnd parameter.
<p>SetTimer returns the ID of the timer if successful. Otherwise it returns
NULL. So it's best not to use the timer ID of 0.
</blockquote>
You can create a timer in two ways:
<ul>
<li> If you have a window and you want the timer notification messages to go
to that window, you must pass all four parameters to SetTimer (the lpTimerFunc
must be NULL)</li>
<li> If you don't have a window or you don't want to process the timer messages
in the window procedure, you must pass NULL to the function in place of a
window handle. You must also specify the address of the timer function that
will process the timer messages.</li>
</ul>
We will use the first approach in this example. <br>
When the time-out period elapses, WM_TIMER message is sent to the window that
is associated with the timer. For example, if you specify uElapse of 1000, your
window will receive WM_TIMER every second. <br>
When you don't need the timer anymore, destroy it with KillTimer:
<blockquote>KillTimer proto hWnd:DWORD, TimerID:DWORD</blockquote>
<h3> <b>Example:</b></h3>
;-----------------------------------------------------------------------
<br>
;
The main program <br>
;-----------------------------------------------------------------------
<br>
.386 <br>
.model flat,stdcall <br>
option casemap:none <br>
include \masm32\include\windows.inc <br>
include \masm32\include\user32.inc <br>
include \masm32\include\kernel32.inc <br>
includelib \masm32\lib\user32.lib <br>
includelib \masm32\lib\kernel32.lib
<p> WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
<p> .data <br>
ClassName db "SplashDemoWinClass",0 <br>
AppName db "Splash Screen Example",0 <br>
<b> Libname db "splash.dll",0 </b>
<p> .data? <br>
hInstance HINSTANCE ? <br>
CommandLine LPSTR ? <br>
.code <br>
start: <br>
<b> invoke LoadLibrary,addr Libname </b> <br>
<b> .if eax!=NULL </b> <br>
<b> invoke FreeLibrary,eax </b> <br>
<b> .endif </b> <br>
invoke GetModuleHandle, NULL <br>
mov hInstance,eax <br>
invoke GetCommandLine <br>
mov CommandLine,eax <br>
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT <br>
invoke ExitProcess,eax
<p> WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
<br>
LOCAL wc:WNDCLASSEX <br>
LOCAL msg:MSG <br>
LOCAL hwnd:HWND <br>
mov wc.cbSize,SIZEOF WNDCLASSEX <br>
mov wc.style, CS_HREDRAW or CS_VREDRAW <br>
mov wc.lpfnWndProc, OFFSET WndProc <br>
mov wc.cbClsExtra,NULL <br>
mov wc.cbWndExtra,NULL <br>
push hInstance <br>
pop wc.hInstance <br>
mov wc.hbrBackground,COLOR_WINDOW+1 <br>
mov wc.lpszMenuName,NULL <br>
mov wc.lpszClassName,OFFSET ClassName <br>
invoke LoadIcon,NULL,IDI_APPLICATION <br>
mov wc.hIcon,eax <br>
mov wc.hIconSm,eax <br>
invoke LoadCursor,NULL,IDC_ARROW <br>
mov wc.hCursor,eax <br>
invoke RegisterClassEx, addr wc <br>
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ <br>
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
<br>
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
<br>
hInst,NULL
<br>
mov hwnd,eax <br>
invoke ShowWindow, hwnd,SW_SHOWNORMAL <br>
invoke UpdateWindow, hwnd <br>
.while TRUE <br>
invoke GetMessage, ADDR msg,NULL,0,0 <br>
.break .if (!eax) <br>
invoke TranslateMessage, ADDR msg <br>
invoke DispatchMessage, ADDR msg <br>
.endw <br>
mov eax,msg.wParam <br>
ret <br>
WinMain endp
<p> WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM <br>
.IF uMsg==WM_DESTROY <br>
invoke PostQuitMessage,NULL <br>
.ELSE <br>
invoke DefWindowProc,hWnd,uMsg,wParam,lParam <br>
ret <br>
.ENDIF <br>
xor eax,eax <br>
ret <br>
WndProc endp <br>
end start
<p> ;--------------------------------------------------------------------
<br>
;
The Bitmap DLL <br>
;--------------------------------------------------------------------
<br>
.386 <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -