|
Add a file to the list of recent documents
|
Total Hit (2934) |
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 (3405) |
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 (3255) |
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 (3112) |
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 (2989) |
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 (5113) |
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 (4269) |
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 (5007) |
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 (3470) |
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 (4077) |
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 (3240) |
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 (3230) |
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
|
|
|
Determine whether a program is 16- or 32-bit
|
Total Hit (3371) |
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 (3804) |
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 (3348) |
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 (2966) |
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 (3282) |
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 (2672) |
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 (3743) |
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 (4211) |
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 (2903) |
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
|
|
|
Get the exit code of a process
|
Total Hit (4195) |
In a few cases, in particular when running MsDos batch files from within a VB application, you may want to determine the ERRORLEVEL set by an external application. You can't do it with a plain Shell statement, but the job becomes easy with the support of the GetProcessExitCode API function:
«Code
....Read More |
Rating
|
|
|
Get the Windows main directories (without any API call)
|
Total Hit (3245) |
The usual way to determine the Windows' main directory is based on the GetWindowsDirectory API function, which requires that you set up a buffer for the result, and then extract the null-terminated result. However, there is a much simpler approach, that works equally well under Windows 95, 98 and NT
....Read More |
Rating
|
|
|
Get the Windows temporary directory (without any API call)
|
Total Hit (3160) |
The usual way to determine the Windows' main directory is based on the GetTempPath API function, which requires that you set up a buffer for the result, and then extract the null-terminated result. However, there is a much simpler approach, that works equally well under Windows 95, 98 and NT. It is
....Read More |
Rating
|
|
|
Hide or disable the desktop icons
|
Total Hit (3619) |
The Desktop is a window like any other window in the system, so you can hide/show and enable/disable it. The only details you need to know is how to retrieve the handle to the Desktop window. It turns out that this window is the first child window of the "Program Manager" window, so all you need is
....Read More |
Rating
|
|
|
Hide or disable the Windows' application bar
|
Total Hit (3236) |
The Windows' application bar (or Startbar) is a window like any other window in the system, so you can hide/show and enable/disable it. The only thing you need to know is that that the class name of the Start bar window is "Shell_TrayWnd" and that its window name is a null string. Here is the code t
....Read More |
Rating
|
|
|
Hide the application in the Task List dialog
|
Total Hit (3370) |
As you know, when you press CTRL+ALT+CANC the Task List window appears. This dialog allows you to see all the running processes and also to terminate them. If you don't want that your application be closed, you can prevent the application from being displayed in the Task List dialog, by using the Re
....Read More |
Rating
|
|
|
How did Windows start?
|
Total Hit (3068) |
If you need to know how Windows was started you have just to call an API function: GetSystemMetrics. Passing the SM_CLEANBOOT constant as parameter, the function returns a Long value with this meaning:
«Code LangId=1»
0 = Normal boot
1 = Fail-safe boot
2 = Fail-safe with network boot
«/Code»
....Read More |
Rating
|
|
|
Implement password-protected TextBox that are really secure
|
Total Hit (2993) |
As explained in another tip in this TipBank, users can peek at the contents of password-protected TextBox controls with a simple Spy-like program, or even with a VB program plus some API functions. The problem is that such TextBox controls react to the WM_GETTEXT message and the GetWindowText API fu
....Read More |
Rating
|
|
|
Open a Control Panel dialog or wizard
|
Total Hit (2757) |
Have you ever needed to open a Windows dialog such as Internet Properties, New Hardware, Modem Properties or any other dialog you can find in the Control Panel? Well, it's very simple, onve you know the trick.
All these dialogs are implemented in files with the CPL extension. (They're actually D
....Read More |
Rating
|
|