Win95 system API function secrets

Source: Internet
Author: User

Win95 system API function secrets

With its brand-new and exquisite appearance, Win95 is a simple and convenient operation method, allowing you to enjoy the pleasure of operating the platform. Same Microsoft public
Visual Basic is not only a computer language, but also a function integrating application development, testing, and error detection functions.
Millions of programmers benefit from a powerful integrated development environment.
A powerful feature of Visual Basic is that it has the function to call functions that reside in the dynamic connection library (DLL) file.
Including all functions provided and used by windows. Access to hundreds of functions and other functions contained in the DLL
The functions of Visual Basic are greatly expanded, and their functions far exceed those of other languages.
Is Microsoft's "regional troops ". You can use hundreds of Apis provided by Windows APIs in your application.
The function is expanded to accelerate the establishment of applications and reduce the repetition of program development. (It is none of my business to contact Bill Gates for a copyright lawsuit!
-- Sorry !)
The so-called API is the application programing interface, which is written by the operating system in C language.
Function called by the user. Windows API functions consist of many "dynamic connection libraries" or DLL. In 32-bit windows, the core windows
API dll has the following:
Gdi32.dll -------- graphic display interface API
Kernel32.dll ----- API for processing low-level tasks (such as memory and task management)
User32.dll ------- APIs for processing Windows and messages (some of which can be accessed as events by Visual Basic programmers)
New APIs are constantly emerging to process new operating system extensions, such as e-mail, networking, and new peripherals.
Since Windows API functions are not Visual Basic internal functions, they must be explicitly declared before they are used. Yes
For the function Declaration correctly formatted, you can access the WIN32API. txt file in the winapi directory.
This article only describes Win95 system API functions and calls the built-in Win95 functions. For example, we can directly call the standardized "weight"
New boot, disk formatting, calling and changing the standard "About Window", viewing "properties", setting "wallpaper", setting shortcuts,
Determine the memory, read and write the "Registry", and create a status bar icon.
? Restart
Some applications must be restarted once after installation to make the settings take effect. You can use the exitwindowsex function.
Private declare function exitwindowsex lib "USER32" (byval uflags as long, byval dwreserved
As long) as long

Private sub commandementclick ()
Exitwindowsex & h43, 0
End sub
? Disk formatting
When you right-click "3.5 floppy disk A" and select "format", the standard "disk format" window is displayed. We
You can also use functions in your application to easily call the Windows 95 standard disk formatting window
.
Add the following code to the form:
Private sub form_click ()
Formatfloppy
End sub
Add the following code to the module:
Public const wm_close = & H10
Declare function findwindow lib "USER32" alias "find0000wa" (byval lpclassname as any, byval
Lpwindowname as any) as long
Declare function getwindowsdirectory lib "Kernel32" alias "getwindowsdirectorya" (byval
Lpbuffer as string, byval nsize as long) as long
Declare function setwindowpos lib "USER32" (byval hwnd as long, byval hwndinsertafter as long,
Byval X as long, byval y as long, byval CX as long, byval Cy as long, byval wflags as long)
As long
Declare function getasktopwindow lib "USER32" () as long
Declare function lockwindowupdate lib "USER32" (byval hwndlock as long) as long
Declare function getwindowrect lib "USER32" (byval hwnd as long, lprect as rect) as long
Declare sub sleep lib "Kernel32" (byval dwmilliseconds as long)
Type rect
Left as long
Top as long
Right as long
Bottom as long
End type
Type pointapi
X as long
Y as long
End type

Const swp_nosize = & H1
Const swp_nozorder = & h4

Public sub formatfloppy ()
Dim sbuffer as string, WINDIR as string, procs as string, X
Dim lresult as long
Sbuffer = string $ (255, 0)
Lresult = getwindowsdirectory (sbuffer, Len (sbuffer ))
WINDIR = trim (sbuffer)
Procs = left (WINDIR, lresult) & "/rundll32.exe shell32.dll, shformatdrive"
Call centerdialog ("format-3? Floppy (:)")
X = shell (procs, 1)
Call centerdialog ("format-3? Floppy (:)")
K = lockwindowupdate (0)
End sub

Public sub centerdialog (wintext as string)
Doevents
On Error resume next
Dim D3 as long
D3 = lockwindowupdate (getmediatopwindow ())
Dim wdth %
Dim hght %
Dim scrwdth %
Dim scrhght %
Dim lpdlgrect as rect
Dim lpdskrect as rect
Dim htaskbar as long
Htaskbar = findwindow (0 &, wintext)
Call getwindowrect (htaskbar, lpdlgrect)
Wdth % = lpdlgrect. Right-lpdlgrect. Left
Hght % = lpdlgrect. Bottom-lpdlgrect. Top
Call getwindowrect (getjavastopwindow (), lpdskrect)
Scrwdth % = lpdskrect. Right-lpdskrect. Left
Scrhght % = lpdskrect. Bottom-lpdskrect. Top
X % = (scrwdth %-wdth %)/2
Y % = (scrhght %-hght %)/2
Call setwindowpos (htaskbar, 0, x %, Y %, 0, 0, swp_nozorder or swp_nosize)
Doevents
End sub
? Call the "about" Window
Selecting "about XXX" in the "help" menu will bring up the standard "about" window. Using the shellabout function, you can not only call
You can change the content of the standard "about" window at will!
The shellabout statement is as follows:
Hwnd: Set the window handle. szapp sets the "caption" in the window. szotherstuff is "Copyright" and "use right"
In the left-side navigation pane.
Private declare function shellabout lib "shell32.dll" alias "shellabouta" (byval hwnd as long,
Byval szapp as string, byval szotherstuff as string, byval hicon as long) as long
Private sub form_load ()
Call shellabout (hwnd, "He fa Wu Angel studio! "," Calling standard Windows "& vbcrlf &" God is with you!
Amitabha! ", 0)
End sub
You can also change the system's "copyright information" by "operating on the registry information" To Run regedit, following the path below:
HKEY_LOCAL_MACHINE → software → Microsoft → windows → CurrentVersion → version.
In your computer, you can change the version content to your desired settings, such
Studio "," He fa Wu wolf Studio ", etc.
? View "attributes"
IN Win95, a new concept-"attribute" is added. Each object has its own "attribute". In the "attribute" window
Is a detailed description of the object, and the descriptions of different object "attribute" windows are different. We can use the shellexecuteex letter.
Directly call the "attribute" standard window. The following program function is equivalent to when you right-click "autoexec. Bat" under the root directory and select
When "attribute" is selected, the standard "attribute" window is displayed.
Add the following code to the form:
Private sub form_click ()
Dim R as long
Dim filename as string
Filename = "C:/autoexec. Bat"
R = showproperties (filename, me. hwnd)
If r <= 32 then msgbox "error"
End sub
Add the following code to the module:
Option explicit
Type shellexecuteinfo
Cbsize as long
Fmask as long
Hwnd as long
Lpverb as string
Lpfile as string
Lpparameters as string
Lpdirectory as string
Nshow as long
Hinstapp as long
Lpidlist as long
Lpclass as string
Hkeyclass as long
Dwhotkey as long
Hicon as long
Hprocess as long
End type
Public const see_mask_invokeidlist = & HC
Public const see_mask_nocloseprocess = & h40
Public const see_mask_flag_no_ui = & H400

Declare function shellexecuteex lib "shell32.dll" alias "shellexecuteex "_
(SEI as shellexecuteinfo) as long
Public Function showproperties (filename as string, ownerhwnd as long) as long
Dim SEI as shellexecuteinfo
Dim R as long
With sei
. Cbsize = Len (SEI)
. Fmask = see_mask_nocloseprocess or see_mask_invokeidlist or see_mask_flag_no_ui
. Hwnd = ownerhwnd
. Lpverb = "properties"
. Lpfile = filename
. Lpparameters = vbnullchar
. Lpdirectory = vbnullchar
. Nshow = 0
. Hinstapp = 0
. Lpidlist = 0
End
R = shellexecuteex (SEI)
Showproperties = sei. hinstapp
End Function
? Set Wallpaper
Wallpaper is an image or image displayed on the desktop and an important window in Win95. You can select multiple
This is a colorful wallpaper. The wallpaper has a beautiful veil on Win95. We can use the systemparametersinfo function to unveil it.
It is a secret and creates a different style for her.
Add the list1 control to the form, and add the following code to the form:
Option explicit
Private declare function systemparametersinfo lib "USER32" alias "systemparametersinfoa"
(Byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long)
As long
Const spi_set1_wallpaper = 20
Const spif_updateinifile = & H1 'Update win. ini constant
Const spif_sendwininichange = & H2 'Update win. ini and tell everyone
Private sub form_load ()
Dim temp as string
Temp = inputbox ("Please input a directory", "changer", "C:/Windows /")
If temp = "" Then end' cancel clicked
If right $ (temp, 1) <> "/" then temp = temp + "/"
List1.tag = temp
Temp = temp + "*. BMP" 'set the file filter (path + *. BMP)
Temp = dir $ (temp)
Do While TEMP $ <> ""
Temp = dir $
If temp = "" Then exit do
List1.additem temp
Loop
List1.additem "(none )"
Show
List1.setfocus
List1.listindex = 0
End sub
Private sub listdomaindblclick ()
Dim temp as string
Dim BMP file as string
Temp = tag
If list1.text = "(none)" then
BMP file = "(none )"
Else
BMP file = temp + (list1)
End if
Systemparametersinfo spi_set1_wallpaper, 0, byval BMP file, spif_updateinifile
End sub

Private sub listdomainkeypress (keyascii as integer)
If keyascii = 13 then listmongodblclick
End sub
Try it now and change your wallpaper on the spot (no money will be collected )! Great!
? Create shortcuts
The shortcut in Win95 provides shortcuts for accessing common programs and documents.
Or add shortcuts to the printer. Using the fcreateshelllink function in vb5, you can quickly create shortcuts for common programs and documents.
The fcreateshelllink statement is:
Private declare function fcreateshelllink lib "stkit432.dll" (byval lpstrfoldername as string,
Byval lpstrlinkname as string, byval lpstrlinkpath as string, byval lpstrlinkargs as string)
As long
Lpstrfoldername: Set the folder Name of the shortcut, lpstrlinkname, and lpstrlinkpath.
Set the Directory and file name of the application to which the shortcut points. In short, the format is as follows:
Fcreateshelllink (destinationpath, shortcutname, sourcepathappname ,"")
The following code creates a shortcut named "shortcut title" for the "D:/path/appname.exe" application on the "desktop"
.
Private declare function fcreateshelllink lib "stkit432.dll" (byval lpstrfoldername as string,
Byval lpstrlinkname as string, byval lpstrlinkpath as string, byval lpstrlinkargs as string)
As long
Private sub form_click ()
Lresult = fcreateshelllink (".../Windows/desktop", "shortcut title", "d:/path/appname.exe ",
"")
End sub
TIPS:
If you want to create a shortcut on the "desktop", set the target directory to ".../Windows/desktop ".
To create a shortcut in the "Start" menu, set the target directory to ".../Windows/Start Menu ".
Create a shortcut in the "Preface" menu, and set the target directory to the corresponding "... C:/Windows/Start Menu/programs,
And so on.
? Determine memory
We often need to access Windows Memory. The biggest factor affecting application performance is the available memory capacity, Access System
It is very useful to process large files, such as bitmap files, because the program can exchange files (SWAp ).
Obtain a larger memory than the actual available memory. After knowing how the memory is allocated, you can read the memory value and operate on large digital files. Yes
Use a wide range of Win32 API functions to determine windows global memory and operate data files.
It is often used.
The length of the dwlength Data Structure
Dwmemoryload memory usage percentage
Dwtotalphys total memory bytes
Actual memory bytes available for dwavailphys
Total number of bytes of dwtotalpagefile paging files
Number of available bytes of dwavailpagefile paging files
Total number of bytes of dwtotalvirtual memory
Dwavailvirtual available virtual memory bytes
Add the following code to the module:
Type memorystatus
Dwlength as long
Dwmemoryload as long
Dwtotalphys as long
Dwavailphys as long
Dwtotalpagefile as long
Dwavailpagefile as long
Dwtotalvirtual as long
Dwavailvirtual as long
End type
Declare sub globalmemorystatus lib "Kernel32" (lpbuffer as memorystatus)
Add the following code to the form:
Private sub form_click ()
Dim M as memorystatus
M. dwlength = Len (m)
Globalmemorystatus m
Print "Data Structure length", M. dwlength
Print "memory usage percentage", M. dwmemoryload
Print "total memory bytes", M. dwtotalphys
Print "actual available memory bytes", M. dwavailphys
Print "Total number of bytes of the paging file", M. dwtotalpagefile
Print "available bytes of paging files", M. dwavailpagefile
Print "Total number of virtual memory bytes", M. dwtotalvirtual
Print "available virtual memory bytes", M. dwavailvirtual
End sub
? Read and Write the Registry
The registry of Win95 and NT is an important part of the system. It sets the parameters of Win95 and NT,
Including user information, system hardware configuration, and applications. The registry system replaces multiple INI files in earlier Windows versions. (Alert
Warning: if you are not familiar with the Registry, do not modify it at will. If an error occurs in the registry project, the machine may crash or even damage the operating system.
System itself .)
In Win32 API, the reg function processes the read and write operations on the registry database as follows:
1. Use regopenkey or regcreatekey to open or create a key;
2. If the previous step is successful, use regqueryvalue (or regqueryvalueex) to read the value of the subkey, and use regsetvalue (or
Regvsetvalueex) sets the sub-key value, uses regenumkey to obtain all the sub-keys, and deletes a key using regdeletekey;
3. Use regclosekey to close the key after completing the operation.
The following applications demonstrate how to generate keys, store values, and obtain registry data. Generate three values under the HKEY_LOCAL_MACHINE key
The sub-keys test/mastering vb5, Windows width, and Windows height are used to store the form size of the last execution.
Private declare function regcreatekey lib "advapi32.dll" alias "regcreatekeya" (byval hkey
Long, byval lpsubkey as string, phkresult as long) as long
Private declare function regdeletekey lib "advapi32.dll" alias "regdeletekeya" (byval hkey
Long, byval lpsubkey as string) as long
Private declare function regdeletevalue lib "advapi32.dll" alias "regdeletevaluea" (byval hkey
As long, byval lpvaluename as string) as long
Private declare function regqueryvalueex lib "advapi32.dll" alias "regqueryvalueexa" (byval
Hkey as long, byval lpvaluename as string, byval lpreserved as long, lptype as long, lpdata
As any, lpcbdata as long) As long 'note that if you declare the lpdata parameter
String, you must pass it by value.
Private declare function regsetvalueex lib "advapi32.dll" alias "regsetvalueexa" (byval hkey
As long, byval lpvaluename as string, byval reserved as long, byval dwtype as long, lpdata
Any, byval cbdata as long) As long 'note that if you declare the lpdata parameter
String, you must pass it by value.
Const error_success = 0 &
Const error_baddb = 1009 &
Const error_badkey = 1010 &
Const error_cantopen = 1011 &
Const error_cantread = 1012 &
Const error_cantwrite = 1013 &
Const error_registry_recovered = 1014 &
Const error_registry_corrupt = 1015 &
Const error_registry_io_failed = 1016 &
Const hkey_classes_root = & h80000000
Const HKEY_CURRENT_USER = & h80000001
Const HKEY_LOCAL_MACHINE = & h80000002
Const regkey = "test/mastering vb5"

Private sub form_load ()
Dim retvalue as long
Dim result as long
Dim keyValue as string
Dim keyid as long
Dim subkey as string
Dim bufsize as long
Label6.caption = regkey
Retvalue = regcreatekey (HKEY_LOCAL_MACHINE, regkey, keyid)
If retvalue = 0 then
Subkey = "Windows width"
Retvalue = regqueryvalueex (keyid, subkey, 0 &, REG_SZ, 0 &, bufsize)
If bufsize <2 then
KeyValue = me. Width
Retvalue = regsetvalueex (keyid, subkey, 0 &, REG_SZ, byval keyValue, Len (keyValue) + 1)
Else
KeyValue = string (bufsize + 1 ,"")
Retvalue = regqueryvalueex (keyid, subkey, 0 &, REG_SZ, bykeyvalue, bufsize)
KeyValue = left $ (keyValue, bufsize-1)
Me. width = keyValue
End if
Label4.caption = subkey
Label5.caption = me. Width
Subkey = "widows height"
Retvalue = regqueryvalueex (keyid, subkey, 0 &, REG_SZ, 0 &, bufsize)
If bufsize <2 then
KeyValue = me. Height
Retvalue = regsetvalueex (keyid, subkey, 0 &, REG_SZ, byval keyValue, Len (keyValue) + 1)
Else
KeyValue = string (bufsize + 1 ,"")
Retvalue = regqueryvalueex (keyid, subkey, 0 &, REG_SZ, byval keyValue, bufsize-1)
Me. Height = keyValue
End if
Label8.caption = subkey
Label7.caption = me. Height
End if
End sub

Private sub form_queryunload (cancel as integer, unloadmode as integer)
Dim keyValue as string
Dim retvalue as long
Dim keyid as long
Retvalue = regcreatekey (HKEY_LOCAL_MACHINE, regkey, keyid)
KeyValue = me. Width
Retvalue = regsetvalueex (keyid, "Windows width", 0 &, REG_SZ, byval keyValue, Len (keyValue) +
1)
KeyValue = me. Height
Retvalue = regsetvalueex (keyid, "Windows height", 0 &, REG_SZ, byval keyValue, Len (keyValue)
+ 1)
End sub
? Create an icon in the "status Zone"
IN Win95, for example, "volume", "date", and "screen", you can create a shortcut icon on the Win95 Status Bar (tray. If the mouse
When you click or double-click a tooltip icon
You can right-click the component to implement its simple functions.
Tray is also called audit Ray, trayicon, notifyicon, status area, etc. It is a special area of the Win95/NT task.
Domain, many software runtime add their own icons in tray, another special feature of this region is that you can
Drag the file and place it in this area. Due to these features, Tray programming has a special position in Win95/NT.
Tray programming is special, mainly including three main aspects: icons, tool prompts and messages. It is part of shell programming,
The shell_policyicon function in the Shell API is mainly used. The shell_policyicon function is declared as follows:
Type policyicondata
The number of bytes in the cbsize as long Structure
Hwnd as long window handle for receiving tray icon messages
UID as long is the icon identifier defined by the application
Uflags as long flag
Ucallbackmessage as long is a message defined by the application.
Hicon as long tray icon handle
Sztip as string * 64 tooltip string
End type
Declare function shell_policyicon lib "shell32.dll" alias "shell_policyicona" (byval dwmessage as long,
Lpdata as policyicondata) as long
The uflags in this structure is very important. It has three values: nif_icon, nif_message, and nif_tip, which indicate
The hicon, ucallbackmessage, and sztip parameters are valid and used to modify icons, messages, and tooltip. These three values can be used at the same time
It can be used separately (three parameters are the same or. In order to respond to user mouse operations, it must be processed in the program
The message defined by ucallbackmessage. The long parameter lparam of the message contains the mouse message defined by Win32.
The short parameter wparam indicates the icon identifier.
The/tools/unsupprt/initray directory of the VB disc contains the initray project, which is generated after compilation.
Systray. ocx control.
Now we use the javasray. ocx control for tray programming.
First, create a "project", and choose "project"> "component" (or right-click the toolbox and choose "department"
And then check system tray control csystray. The csystray control appears in the toolbox.
The javasray. ocx control has four events: mousedblclick, mousedown, mousemove, and mouseup.
The options are mousemove, mousedown, mouseup, and mousedblclick. The following programming clearly shows their response times
.
Private sub csystray1_mousedblclick (button as integer, ID as long)
Msgbox "Hei! You have dblclick the mouse! "
End sub
Private sub csystray1_mousedown (button as integer, ID as long)
If Button = 2 then
Msgbox "Hei! You have clicked me in right button! "
End if
End sub
Private sub csystray1_mousemove (ID as long)
Msgbox "Hello! I am here! "
End sub
Private sub c0000ray0000mouseup (button as integer, ID as long)
Msgbox "Hei! You clicked me just now! "
End sub
Private sub form_load ()
Csystray1.traytip = "Hello! I am the king of the world! "
Csystray1.intray = true
Csystray1.trayicon = "C:/fitbench/face. ICO"
End sub
The pivoray control also has intray, name, trayicon, traytip, parent, index, object, and tag attributes. Intray
Set whether to create a shortcut icon on the Win95 status bar tray; Name: Set the name of the ray control; trayicon
Set the appearance of the created shortcut icon on tray. traytip sets the tooltip if you move your cursor over the icon.
The additional data required by the tag storage program.

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.