iczelion tut26[1]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 jimgreen 的 blog

tutorial 26: splash screen


now that we know how to use a bitmap, we can progress to a more creative use of it. splash screen. download the example.

theory

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.
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.
the general scheme is as follows:
  1. put the bitmap into the dll as a bitmap resource
  2. the main program calls loadlibrary to load the dll into memory
  3. 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.
  4. when the specified length of time elapsed, the splash screen is removed from the screen and the control is returned to the main program
  5. the main program calls freelibrary to unload the dll from memory and then goes on with whatever task it is supposed to do.
we will examine the mechanisms in detail.

load/unload dll

you can dynamically load a dll with loadlibrary function which has the following syntax:
loadlibrary  proto lpdllname:dword
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.
to unload a dll, call freelibrary:
freelibrary  proto  hlib:dword
it takes one parameter: the module handle of the dll you want to unload. normally, you got that handle from loadlibrary

how to use a timer

first, you must create a timer first with settimer:
settimer  proto  hwnd:dword, timerid:dword, uelapse:dword, lptimerfunc:dword

hwnd 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.
timerid is a user-defined value that is used as the id of the timer.
uelapse is the time-out value in milliseconds.
lptimerfunc 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.

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.

you can create a timer in two ways:
  • 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)
  • 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.
we will use the first approach in this example.
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.
when you don't need the timer anymore, destroy it with killtimer:
killtimer  proto  hwnd:dword, timerid:dword

example:

;-----------------------------------------------------------------------
;                         the main program
;-----------------------------------------------------------------------
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib

本文关键:iczelion asm
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top