Search notes:

Examples for Visual Basic for Application accessing the Windows API

Here are a few examples how the WinAPI can be accessed from Visual Basic for Applications.
Some of these examples need the declarations of the respective Windwos API functions and memory structures which are found here.
hello World uses CreateWindowEx to create a window and write hello world into it. Apart from that, it does nothing except waiting for the window to be destroyed.
CreateProcess creates a process.
Determining the user associated with the current thread with GetUserName.
Sleeping for a specified duration in milliseconds.
ShellExecute can be used to open a specific file with its default application or to start a specific application.
Determining the dimensions of a window with GetWindowRect.
GetLocaleInfo.
EnumDisplayMonitors iterates over all monitors that are attached to the system and calls a callback function.
Determining the Net Bios Name of the computer with GetComputerName.
GetTempPath returns the name of the temporary directory.
GetTempFileName can be used to create a temporary (and if desired: unique) filename.
Examples related to the clipboard.
Beep sounds a given frequency for a given period of time.
FormatMessage shows how FormatMessage can be used to create the text for a Windows error number.
GetSystemMetrics retrieves system metrics and configuration settings.
SendMessage sends messages (such as WM_SETTEXT) to other windows.
SetWindowPos with HWND_TOPMOST places a window permanently to the top most position so that is always visible.
Downloading a file with URLDownloadToFile.
EnumWindows iterates over all windows and calls a callback function.
EnumChildWindows iterates over all descendents of a window, not only its (immediate) children.
This example uses FindWindowEx to find a notepad's edit control.
VkKeyScanEx can be used to determine what a user would have to type on his keyboard so that it results in a desired character. This can then be used in SendInput.
SendInput simulates a user pressing some keys to start notepad and enter some text into it.
key press
SetWindowsHookEx
This example uses EnumWkindows to find a window by the text it contains in the title and then calls ShowWindow followed by SetForeGroundWindow to bring it to the top.
With Winsock, it's possible to create a webserver.
EnumProcessModules is a PSAPI function with which a handle can be retrieved for each process.
List exported functions in a DLL uses some functions that are offered by DbgHelp.

Index