|
Play an AVI movie
|
Total Hit (5118) |
If you want to play an AVI movie from VB you can use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lps
....Read More |
Rating
|
|
|
Play an AVI movie in a PictureBox control
|
Total Hit (5248) |
With MCI functions you can play an AVI movie into a PictureBox. All you need to do is open the file with a special procedure:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uR
....Read More |
Rating
|
|
|
Record a WAV file
|
Total Hit (3650) |
You can use MCI functions if you want to record a WAV file. The main MCI function is mciSendString, that sends command strings to the system and execute them.
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturn
....Read More |
Rating
|
|
|
Retrieve the length of a media file (WAV, AVI, MIDI)
|
Total Hit (5608) |
You can retrieve the length of a standard windows media file (WAV, AVI or MIDI) using simple MCI functions. First, you must open the file with:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As Strin
....Read More |
Rating
|
|
|
Retrieve the size of an AVI movie
|
Total Hit (3860) |
To retrieve the original size of an AVI file that you've already opened with the mciSendString API function you can use this command
«Code LangId=1»
Dim RetString As String
RetString = Space$(256)
CommandString = "where AVIFile destination"
RetVal = mciSendString(CommandString, RetString, Len
....Read More |
Rating
|
|
|
Animated form icons
|
Total Hit (3940) |
You can add a professional touch to your apps by showing an animated icon when the main form is minimized. To achieve this effect, prepare an array of Image controls, each one containing the icons that make up the animation, then add a Timer control, with the Enabled property set to True and the Int
....Read More |
Rating
|
|
|
Build a simple browser for icons
|
Total Hit (2956) |
Winodws uses a special browser to show all icons contained in a file and offers the end user the possibility to choose an icon from it. You can add this functionallity to your applications through an undocumented API function, SHChangeIconDialog. Its Declare is:
«Code LangId=1»
Declare Function
....Read More |
Rating
|
|
|
Convert a color value to a gray scale
|
Total Hit (3225) |
When you have a 32-bit color value, you can convert it to a grey-scale - that is, you can determine how it would appear on a monochromatic display (more or less) using the following function:
«Code LangId=1»
Function GetGreyScale(ByVal lColor As Long)
lColor = 0.33 * (lColor Mod 256) + 0.59
....Read More |
Rating
|
|
|
Copy the contents of the screen or the active window
|
Total Hit (5386) |
The standard way to copy the contents of the screen or a window to a picture box requires you to use a lot of API functions, such as BitBlt. A simpler approach is possible, though: you just have to simulate the typing of the Print Screen key (or Alt+Print Screen if you want to copy the contents of t
....Read More |
Rating
|
|
|
Display an animated GIF using the WebBrowser control
|
Total Hit (4197) |
The standard PictureBox control doesn't support the Animated GIF graphic format. However, you can display these images by using a WebBrowser control:
«Code LangId=1»
WebBrowser1.Navigate "c:\Images\Animated.Gif"
«/Code»
The only problem of this technique is that the WebBrowser control also di
....Read More |
Rating
|
|
|
Extract Red,Green,Blue components of a color
|
Total Hit (2906) |
If you have a 32-bit color value in RGB format, you can extract its Red, Green and Blue components using the following routines:
«Code LangId=1»
Function GetRed(ByVal lColor As Long) As Long
GetRed = lColor Mod 256
End Function
Function GetGreen(ByVal lColor As Long) As Long
GetGre
....Read More |
Rating
|
|
|
Extract RGB components from a Long value
|
Total Hit (2994) |
You can extract RGB values out of a 32-bit color value by using the integer division and the MOD operators, but there is a much more effective way, based on the LSet. You can convert from a long to rgb bytes and vice versa with the following code:
«Code LangId=1»
Private Type RGBWrapper
Red
....Read More |
Rating
|
|
|
Getting a pixel color
|
Total Hit (3852) |
The Point method returns the color value of a given pixel, but is rather slow because it has to convert its argument from twips (or whatever ScaleMode is currently active) to pixels, and also because its argument are treated as Single quantities, and must therefore converted. When you have to retrie
....Read More |
Rating
|
|
|
Retrieving Bitmap properties
|
Total Hit (4065) |
The Picture box control does not directly expose any property that returns information on the bitmap currently loaded. You can retrieve this information by calling the GetObject API function, passing it the handle of the bitmap. This value is the Handle property of the IPictureDisp object (which is
....Read More |
Rating
|
|
|
Setting a pixel color
|
Total Hit (3509) |
The PSet method is much slower than it should actually be, and in most cases you will find it convenient to substitute it with direct calls to the SetPixel API functions. This function is about twelve times faster than the VB's method, at least when you can set the form's ScaleMode to Pixels, for mo
....Read More |
Rating
|
|
|
Add a file to the list of recent documents
|
Total Hit (2856) |
The Windows shell provides a function that lets you add a file to the list of the recent documents, that is the list that you can access from the Start menu:
«Code LangId=1»
Private Declare Function SHAddToRecentDocs Lib "shell32.dll" (ByVal dwFlags As _
Long, ByVal dwData As String) As Lon
....Read More |
Rating
|
|
|
Add pizazz to your apps with an animated cursor
|
Total Hit (3302) |
Who said you can't use an animated cursor with Visual Basic? Actually, it's so simple! You just have to load your animated cursor through LoadCursorFromFile API function, then you get the current cursor using GetCursor, and finally you can set your cursor using SetSystemCursor. This is all the code
....Read More |
Rating
|
|
|
Cascade all the child windows of a window
|
Total Hit (3137) |
The Windows API provides an handy function that lets you cascade all the child windows of another window with one single call. The effect of this function is similar to the Cascade Windows command in most MDI apps, except the parent window doesn't have to be an MDI window.
This is the (incorrect)
....Read More |
Rating
|
|
|
Changing the icon of a drive
|
Total Hit (3031) |
By editing the Registry it is possible to change the icon that Windows Explorer uses for a drive. For example, if you want to change Drive E's icon, create the following registry key:
HEKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\Explorer\DriveIcons\E\DefaultIcon\
When you c
....Read More |
Rating
|
|
|
Check whether a serial or parallel port is available
|
Total Hit (2895) |
The Open statement also supports special device names such as COM1 or LPT2. You can build on this feature and use the Open command to test whether a given serial or parallel port is available. Here are two functions that perform this task:
«Code LangId=1»
' Check whether a given COM serial port
....Read More |
Rating
|
|
|
Check whether the current user is an administrator
|
Total Hit (5019) |
This function will determine whether or not a thread is running in the user context of the local Administrator account. You need to examine the access token associated with that thread using the GetTokenInformation() API, since this access token represents the user under which the thread is running.
....Read More |
Rating
|
|
|
Create a simple Windows inspector
|
Total Hit (4188) |
It takes only a handful of lines of code to create Windows inspector program, that is, an utility that lets you display the handle, the class name and the contents (Text or Caption) of the window under the mouse cursor.
To create such a program, create a small form, add a Label1 control and a Tim
....Read More |
Rating
|
|
|
Create a System Tray icon
|
Total Hit (4890) |
Sometimes is useful to add an icon in the Window taskbar's status area (a.k.a. System Tray), to gain a better interaction between the user and your application. The only API you have to use is Shell_NotifyIcon:
Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByV
....Read More |
Rating
|
|
|
Detect when the application gets or loses the input focus
|
Total Hit (3380) |
VB forms exposes the Activate and Deactivate events, which fire when the form gets and loses the focus because the user has clicked on another form of the same application. However, VB doesn't fire any event when the user clicks on a form that belongs to another Windows application. In some cases th
....Read More |
Rating
|
|
|
Determine memory usage
|
Total Hit (3976) |
The GlobalMemoryStatus API function returns detailed information about the current load on the physical and virtual memory. You can use the following code to display the current amount of free memory:
«Code LangId=1»
Dim ms As MEMORYSTATUS
Dim msg As String
' query for memory
....Read More |
Rating
|
|
|
Check whether a sound card exists
|
Total Hit (3316) |
If you are developing a game in VB or an application that plays sounds, you probably want to check that a sound card actually exists. There is an API function that does this, and returns the number of sound cards installed in the system. Therefore, a return value of zero means that no devices are pr
....Read More |
Rating
|
|
|
Determine the total playing time of an Audio CD
|
Total Hit (2615) |
The Microsoft Multimedia Control lets you easily determine the total playing time of an Audio CD: you only need to correctly initialize the control and then decipher the value returned by its Length property. Use the following code as a guideline for your routines:
«Code LangId=1»
Private Sub cm
....Read More |
Rating
|
|
|
Open and close the CD drive's door
|
Total Hit (3120) |
Here's a short code snippet that lets you programmatically open and close the CD door. Note that not all the CD drives support these functions:
«Code LangId=1»
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnStr
....Read More |
Rating
|
|
|
Play a CD Audio track
|
Total Hit (3578) |
If you want to play a track of an audio CD from VB you can use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String,
....Read More |
Rating
|
|
|
Play a MIDI file
|
Total Hit (4389) |
If you want to play a MIDI file from VB you have to use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal
....Read More |
Rating
|
|