⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lion-tutorial26.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<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,&nbsp; 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&nbsp; 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&nbsp; 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&nbsp; proto&nbsp; 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&nbsp; proto&nbsp; 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&nbsp; proto&nbsp; hWnd:DWORD, TimerID:DWORD</blockquote>
<h3> <b>Example:</b></h3>
 ;-----------------------------------------------------------------------  
<br>
 ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
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&nbsp; 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> &nbsp;invoke LoadLibrary,addr Libname </b> <br>
  <b> &nbsp;.if eax!=NULL </b> <br>
  <b> &nbsp;&nbsp;&nbsp; invoke FreeLibrary,eax </b> <br>
  <b> &nbsp;.endif </b> <br>
   &nbsp;invoke GetModuleHandle, NULL  <br>
   &nbsp;mov&nbsp;&nbsp;&nbsp; hInstance,eax  <br>
   &nbsp;invoke GetCommandLine  <br>
   &nbsp;mov&nbsp;&nbsp;&nbsp; CommandLine,eax  <br>
   &nbsp;invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT  <br>
   &nbsp;invoke ExitProcess,eax  
<p> WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD  
  <br>
   &nbsp;LOCAL wc:WNDCLASSEX  <br>
   &nbsp;LOCAL msg:MSG  <br>
   &nbsp;LOCAL hwnd:HWND  <br>
   &nbsp;mov&nbsp;&nbsp; wc.cbSize,SIZEOF WNDCLASSEX  <br>
   &nbsp;mov&nbsp;&nbsp; wc.style, CS_HREDRAW or CS_VREDRAW  <br>
   &nbsp;mov&nbsp;&nbsp; wc.lpfnWndProc, OFFSET WndProc  <br>
   &nbsp;mov&nbsp;&nbsp; wc.cbClsExtra,NULL  <br>
   &nbsp;mov&nbsp;&nbsp; wc.cbWndExtra,NULL  <br>
   &nbsp;push&nbsp; hInstance  <br>
   &nbsp;pop&nbsp;&nbsp; wc.hInstance  <br>
   &nbsp;mov&nbsp;&nbsp; wc.hbrBackground,COLOR_WINDOW+1  <br>
   &nbsp;mov&nbsp;&nbsp; wc.lpszMenuName,NULL  <br>
   &nbsp;mov&nbsp;&nbsp; wc.lpszClassName,OFFSET ClassName  <br>
   &nbsp;invoke LoadIcon,NULL,IDI_APPLICATION  <br>
   &nbsp;mov&nbsp;&nbsp; wc.hIcon,eax  <br>
   &nbsp;mov&nbsp;&nbsp; wc.hIconSm,eax  <br>
   &nbsp;invoke LoadCursor,NULL,IDC_ARROW  <br>
   &nbsp;mov&nbsp;&nbsp; wc.hCursor,eax  <br>
   &nbsp;invoke RegisterClassEx, addr wc  <br>
   &nbsp;INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hInst,NULL  
  <br>
   &nbsp;mov&nbsp;&nbsp; hwnd,eax  <br>
   &nbsp;invoke ShowWindow, hwnd,SW_SHOWNORMAL  <br>
   &nbsp;invoke UpdateWindow, hwnd  <br>
   &nbsp;.while TRUE  <br>
   &nbsp; invoke GetMessage, ADDR msg,NULL,0,0  <br>
   &nbsp; .break .if (!eax)  <br>
   &nbsp; invoke TranslateMessage, ADDR msg  <br>
   &nbsp; invoke DispatchMessage, ADDR msg  <br>
   &nbsp;.endw  <br>
   &nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp; eax,msg.wParam  <br>
   &nbsp;ret  <br>
   WinMain endp  
<p> WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM  <br>
   &nbsp;.IF uMsg==WM_DESTROY  <br>
   &nbsp; invoke PostQuitMessage,NULL  <br>
   &nbsp;.ELSE  <br>
   &nbsp; invoke DefWindowProc,hWnd,uMsg,wParam,lParam  <br>
   &nbsp; ret  <br>
   &nbsp;.ENDIF  <br>
   &nbsp;xor eax,eax  <br>
   &nbsp;ret  <br>
   WndProc endp  <br>
   end start  
<p> ;--------------------------------------------------------------------  
  <br>
   ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  The Bitmap DLL  <br>
   ;--------------------------------------------------------------------  
  <br>
   .386  <br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -