|
Determine whether a program is 16- or 32-bit
|
Total Hit (3367) |
Even if we're living in a 32-bit world, and closer and closer to the 64-bit day, 16-bit programs are still running out there. Knowing whether a given EXE is 32-bit or not can be useful when you have to arrange version checking routine, for example to detect which version of a product is installed.
....Read More |
Rating
|
|
|
Disable the Ctrl-Alt-Del key combination (Windows 9x only)
|
Total Hit (3801) |
In Windows 95 and 98, when the screen saver is currently active (and the screen is blanked) the Ctrl-Alt-Del key combination doesn't work, in order to force the user to enter her password. You can take advantage of this feature and programmatically disable this key combination, by making Windows bel
....Read More |
Rating
|
|
|
Display the "Shut down Windows" dialog
|
Total Hit (3343) |
To programmatically display the "Shut down Windows" standard dialog box you can use the SHShutDownDialog undocumented API function, whose declaration is:
«Code LangId=1»
Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal lType As _
Long) As Long
Its only argument can be
....Read More |
Rating
|
|
|
Display the dialog to configure a port
|
Total Hit (2962) |
The ConfigurePort API function lets you programmatically bring up the system dialog box for configuring a COM or LPT port. The function returns a non-zero value if successful (that is, the dialog appears). Here is the Declare of this function, and an example of its usage:
«Code LangId=1»
Privat
....Read More |
Rating
|
|
|
Display the Find system dialog
|
Total Hit (3279) |
If you ever needed to programmatically enable your users to search for files, you certainly found useful the possibility of reusing the system Find dialog integrated in the Start menu and also available through the F3 key within the Explorer. The key to obtain such a dialog is the ShellExecute funct
....Read More |
Rating
|
|
|
Display the Windows Shortcut Wizard
|
Total Hit (2666) |
You can programmatically start the Shortcut Wizard from your code, to give the end user the capability to create a new shortcut:
«Code LangId=1»
Shell "rundll32.exe AppWiz.Cpl, NewLinkHere " & App.Path, 1
«/Code»
|
Rating
|
|
|
Find out the Windows version a program require
|
Total Hit (3739) |
Not all programs may run on all the Windows platforms. Often programs require at least a certain version of Windows. In most cases, this is due to the lack of specific functions in the SDK.
Anyway, to detect yourself whether a given EXE file can run under the current version of Windows (without r
....Read More |
Rating
|
|
|
Format a drive using an undocumented function
|
Total Hit (4208) |
SHFormatDrive is an undocumented but simple API function that allows you to format a drive. This function simply opens "Format Drive" diaolog window. Being undocument you won't find its Declare with the API Viewer utility:
«Code LangId=1»
Private Declare Function SHFormatDrive Lib "Shell32.dll"
....Read More |
Rating
|
|
|
Get login information the easy way (without any API call)
|
Total Hit (2896) |
While you can use many different API function to get user and domain information, if you're running under Windows NT or 2000 Server there is a shortest path, based on the fact that the operating system loads many piece of data into environment variables:
«Code LangId=1»
' this code works only un
....Read More |
Rating
|
|
|
Getting a pixel color
|
Total Hit (3946) |
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 (4176) |
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 (3592) |
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
|
|
|
Create a gradient background
|
Total Hit (4709) |
a gradient brush is a brush that contains all the color nuances that vary from a starting color to an ending color, like the typical background screen of many installation procedures or Microsoft PowerPoint slides. The simplest way to create a linear gradient brush is passing its size (by means of a
....Read More |
Rating
|
|
|
Dashed lines with custom caps
|
Total Hit (4477) |
You can set properties of the Pen object to create custom lines. For example, you can use the DashStyle enumerated property to draw dashed lines using a predefined pattern, and you can even create custom dash patterns by assigning an array of Single values to the DashPattern property. The StartCap a
....Read More |
Rating
|
|
|
Drawing Bézier splines
|
Total Hit (3563) |
GDI+ supports two different forms of a complex curve that can't be represented as an arc of a circle or an ellipse: a cardinal spline and a Bézier spline. A Bézier spline is a curve specified by four points: the initial point, the ending point, and two control points. The curve doesn't pass through
....Read More |
Rating
|
|
|
Drawing Cardinal splines
|
Total Hit (4498) |
GDI+ supports two different forms of a complex curve that can't be represented as an arc of a circle or an ellipse: a cardinal spline and a Bézier spline. A cardinal spline is the curve that you would create by taking a piece of flexible material-such as a thin stripe of iron or wood-and making it p
....Read More |
Rating
|
|
|
Measuring a string drawn with a specific font
|
Total Hit (2719) |
When you're dynamically drawing text (either on a Windows Form or Web Form application), you may need to calculate the width and height of a string printed with a particular font. This is easy with the Graphics class's Measure string method, that takes in input the string being measured, and the fon
....Read More |
Rating
|
|
|
Process individual pixels of a bitmap
|
Total Hit (3991) |
While you can access individual pixels of a bitmap by means of the GetPixel and SetPixel methods of the Bitmap object, in practice you seldom want to use these methods, as they are simply too slow for most cpu-intensive operations. Fortunately there is a faster way, which consists of moving all the
....Read More |
Rating
|
|
|
Add a file to the list of recent documents
|
Total Hit (2929) |
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 (3400) |
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 (3251) |
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 (3105) |
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 (2984) |
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 (5106) |
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 (4263) |
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 (5003) |
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 (3464) |
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 (4071) |
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
|
|
|
Determine the Windows version (without any API call)
|
Total Hit (3235) |
You can use the GetVersion or GetVersionEx API functions to determine which Windows version the application is running on. However, there is a much simpler solution, based on the fact that Windows NT creates an environment variable named "OS" while Windows 95/98 don't. So you can quickly discern bet
....Read More |
Rating
|
|
|
Determine whether a folder is shared
|
Total Hit (3225) |
The Windows shell provides a simple way to detect whether a given folder is shared or not. You must call the SHGetFileInfo() API function and analyze the way it fills out a given structure.
«Code LangId=1»
Type SHFILEINFO
hIcon As Long
iIcon As Long
dwAttributes As Long
szD
....Read More |
Rating
|
|