Compilation Tutorial: Launch screen

Source: Internet
Author: User
Tags resource set time

In the previous chapter we learned about the use of bitmaps. In this chapter we use the creativity that God has given us to digest the knowledge we have learned in the last chapter. That's how to create a splash screen with a bitmap.

Theory

First, we need to figure out what the splash screen is. For a simple example: when we start some of the professional programs (such as Netscape,adobe Acrobat), we first jump out of a splash screen. There are usually some copyright information, version number, etc. at the same time, Program backstage is doing some program loading or initialization work. This splash screen is different from the general window. It has no title bar, no system menu, and no border. Only one bitmap is displayed on the screen for a while and then disappears. In this chapter we try to do one ourselves.

The first step you might think of is to include the bitmap to be displayed in the resource file. But there is a drawback to doing so. Your program only displays this bitmap when it is started, but it still exists in your memory until you turn it off. This is a great waste of memory. A good idea is to create a "resource" DLL (Dynamic Connection library) to contain the bitmap and its unique display code. This way, you can load him when you want to display the splash screen, and then uninstall it when you're done. So, our program requires 2 modules: The main program and the launch screen DLL. We're going to put the bitmap in the resource of this DLL.

The basic steps are as follows:

Place the bitmap as a bitmap resource in the DLL.

The main program calls LoadLibrary to load the DLL into memory.

When a DLL is invoked, it creates a timer to manage when the splash screen is displayed. Then, register and create a window without a caption and a border. The bitmap is displayed in the client area of the window as well.

Wait for the start of the screen to display the length of time to reach your pre-set values, start the screen disappear, control back to the main program hands.

The main program calls FreeLibrary to unload the DLL from memory. Then, do what it's supposed to do.

Now let's look at the details.

Loading/unloading DLLs

You can use LoadLibrary to load a DLL in a flexible format as follows:

LoadLibrary Proto Lpdllname:dword

It has only one argument: the address of the name of the DLL you want to load. The call successfully returns a handle to the DLL module, which returns null instead.

To uninstall the DLL, call FreeLibrary:

FreeLibrary Proto Hlib:dword

It also has only one parameter: The handle of the DLL module you want to uninstall (usually the one above that function returns).

How to use the timer

First, you will use SetTimer to create a timer:

SetTimer Proto Hwnd:dword, Timerid:dword, Uelapse:dword, Lptimerfunc:dword

The HWND accepts the handle of the window of this timer message. If your timer doesn't need a window to accept its message, you can also use NULL as a parameter

The ID value of the Timerid timer. defined by yourself.

Uelapse Timer set time, in MS (1 per thousand seconds) as the unit.

Lptimerfunc the address of the function that handles the timer message. If you use NULL as the parameter, then the timer's message is sent to the window specified by the HWND parameter.

SetTimer returns the ID of the timer or returns NULL if successful. So it's best not to set the timer ID to 0 (pheadnius:null represents 0, remember?).

You can create timers in 2 different ways:

If you have a window and the timer passes the message to the window. Then you need to pass all 4 parameters to the SetTimer function (the Lptimerfunc argument must be null).

If you do not have a window or you do not want the window to handle the timer message, you must send a null in the window handle. You also specify the address of the function used to process the timer message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.