Common Control: The
VB WAY
! "Save me! Why do I make a small program be packaged so big after packaging the VB installation wizard?" We can almost see such a post on all VB forums. This bad result is from VB convenient development: Some VB programmers use ActiveX controls in almost no control, and the installation wizard is just a progral with no perceptual, which adds the ActiveX controls to the release package - so you will Run to the online post to save.
How to do? The simple method is to compress EXE, DLL with UPX, but the standard is not true. This article will tell you that you can "cure" method - if your program needs to use some Common Control, you have to bring mscomctl.ocx, mscomct2.ocx, we can help you get rid of this 1.22MB package!
This is Common Control: the
VB WAY
!
First, prepare knowledge
We need to have a little preparation knowledge before specifically explaining how you want something you want.
1. Basic principle of Windows message loop. This is not the theme of this article, but it is the most important basics. If you don't understand, it is best to find basic C for windows book to see first.
Second, Visual Basic variable pointer and function pointer. This is very boring, because we can only get the address in VB, it seems impossible to use the pointer like C. The three functions and one operator are introduced in detail, they are all built in VB6, without claim: Varptr (PTR AS ANY) function This function returns an address of a variable (or array element). With this address, we will be able to access the content inside. Parameter PTR is any variable or array element. For string variables, it returns the ANSI BUFFER address of this variable. StrPtr (PTR AS String) function This function returns a Unicode Buffer address of a string variable, please note the difference between Varptr (). Parameter PTR is any string variable. Objptr (PTR AS Unknown) function This function is specifically used to get the address of the VB object variable. The AddRessof operator returns the address of the SUB or FUNCTION in a standard module. With this operator has a tip: This operator cannot directly assign a value to the variable (it can only be used in the function parameter), so in order to put a Function address in the variable, we need such a Dummy function: public function Procaddr (Byval LPPROC As Long) As long proddr = lpprocend function, we can save the address of the Test () function in the lptest variable: lptest = procaddr (addressof test)
Third, the API function, the constant statement is limited by the limited space, all the API functions, the constant we do not list the declaration code. You can download a function, constant, usage, Win32API, and Common Control 5.80 from http://www.greatmidnight.com/downloads/bint {/downloads/bint {//www.greatmidnight.com/downloads/bintool/tl_comctl.zip statement. This is two type library files, you can add references to these two files from the VB's "Project" - Reference menu so you don't need to manually declare a common Win32 API, Common Control 5.80 Function, constant. Second, get the version of the current system Common Control
Before using Common Control, you must figure out which version of the current system is installed - there are many new features to join after Common Control 5.x, what is the consequence of these features for the old version? Guess yourself. In this section, we will tell the version number of comctl32.dll.
Many Windows Shell's dynamic connection libraries have such a function: dllgetversion (). I have written the following function to get the version number of the specified shell dynamic connection library:
Public Function GetDllVersion (ByVal DllName As String, _ ByRef MajorVersion As Long, _ ByRef MinorVersion As Long, _ ByRef BuildNumber As Long, _ ByRef PlatformID As Long, _ Optional ByVal bDefaultIE3 As Boolean = True) As Boolean 'This function is used to obtain Windows SHELL32.DLL and other DLL version information. On Local Error GoTo Shell32VerErr Dim SecurityAttr As SECURITY_ATTRIBUTES Dim hThread As Long, ThreadID As Long Dim hModule As Long, lpThreadAddr As Long Dim VerInfo As DLLVERSIONINFO Dim ExitCode As Long Dim ErrorOccurred As Integer ErrorOccurred = 0 'must first load DLL. HModule = loadingLibraryEx (Dllname, Vbnull, 0) if hmodule> 0 then 'then locates the address of the function dllgetversion (). lpThreadAddr = GetProcAddress (hModule, "DllGetVersion") If lpThreadAddr> 0 Then With SecurityAttr .lpSecurityDescriptor = 0 .bInheritHandle = 0 .nLength = Len (SecurityAttr) End With VerInfo.cbSize = Len (VerInfo) 'pity! VB cannot call functions directly through the address, so it has to replace it by establishing a thread. Hthread = CreateThread (SecurityAttr, 0, Byval LPthreadaddr, _ Verinfo, 0, Threadid if hthread> 0 "then waits for dllgetversion () to return. Do GetExitCodetteread Hthread, EXITCODE LOOP UnTil EXITCODE <> Still_Active CloseHandle Hthread 'off thread. Else Erroroccurred = 3 'Establishing a thread error.
Endiff = 2 'Can't find the DllgetVersion () entry address. End if freelibrary hmodule 'Release the DLL. Else Erroroccurred = 1 'Unable to load the DLL. End If If Not ErrorOccurred Then With VerInfo MajorVersion = .dwMajorVersion MinorVersion = .dwMinorVersion BuildNumber = .dwBuildNumber PlatformID = .dwPlatformID End With ElseIf ErrorOccurred = 2 And bDefaultIE3 Then 'can not find the entry address, are described in IE Version 4.0 Shell32 3.0. MajorVersion = 4: MinorVersion = 0: BuildNumber = 0: PlatformID = -1 Else GoTo Shell32VerErr 'unexpected error ...... End If GetDllVersion = True Exit FunctionShell32VerErr: GetDllVersion = FalseEnd Function use "comctl32.dll" as the first argument to call This function, we can get its version number. In my system, Majorversion, MinorVersion, BuildNumber will be: 5, 81, 4522, That is, CommON Control version: 5.81.4522.
After confirming that Common Control in the system is 5.x version, we can start the following things!
(to be continued……)