June 24, 2000

Display the Connect To Printer dialog

Under Windows NT you can programmatically display the Connect To Printer dialog using one simple API function: ‘ This works only under Windows NT and 2000Private Declare Function ConnectToPrinterDlg Lib “winspool.drv” (ByVal hWnd As _ Long, ByVal flags As Long) As Long’ the 1st argument is the handle of the

ClipMouseToWindow – Confine the cursor to a window’s client area

Private Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePrivate Declare Function GetClientRect Lib “user32” (ByVal hWnd As Long, _ lpRect As RECT) As LongPrivate Declare Function ClientToScreen Lib “user32” (ByVal hWnd As Long, _ lpPoint As Any) As LongPrivate Declare Function ClipCursor Lib

SnapMouseToWindow – Move the mouse cursor to the center of a form or control

Private Declare Function SetCursorPos Lib “user32” (ByVal X As Long, _ ByVal Y As Long) As LongPrivate Declare Function GetWindowRect Lib “user32” (ByVal hWnd As Long, _ lpRect As RECT) As Long’ Move the mouse cursor to the center’ of a given window or controlSub SnapMouseToWindow(ByVal hWnd As Long) Dim

MoveMouseCursor – Move the mouse to given coordinates

Private Type POINTAPI X As Long Y As LongEnd TypePrivate Declare Function SetCursorPos Lib “user32” (ByVal X As Long, _ ByVal Y As Long) As LongPrivate Declare Function ClientToScreen Lib “user32″ (ByVal hWnd As Long, _ lpPoint As POINTAPI) As Long’ Mouse the mouse cursor.” If a window handle is

Terminate the process with an ErrorLevel code

If your VB application is meant to be called from within a Ms-Dos batch file, you must be able to return Dos an error code. This can be accomplished using the ExitProcess API function: Private Declare Sub ExitProcess Lib “kernel32” (ByVal uExitCode As Long)’ terminate the program and return ErrorLevel

WindowFromMouse – The handle of the window under the mouse cursor

Private Type POINTAPI X As Long Y As LongEnd TypePrivate Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As LongPrivate Declare Function WindowFromPoint Lib “user32” (ByVal xPoint As Long, _ ByVal yPoint As Long) As Long’ Return the handle of the window under the mouse cursor.Function WindowFromMouse() As Long Dim

MouseX, MouseY – Get mouse coordinates, relative to the screen or a window

Private Type POINTAPI X As Long Y As LongEnd TypePrivate Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As LongPrivate Declare Function ScreenToClient Lib “user32″ (ByVal hWnd As Long, _ lpPoint As POINTAPI) As Long’ Get mouse X coordinates in pixels” If a window handle is passed, the result is

DiscardMouseMessages – Prevent queud mouse actions from being processed

Private Type POINTAPI X As Long Y As LongEnd TypePrivate Type MSG hwnd As Long message As Long wParam As Long lParam As Long time As Long pt As POINTAPIEnd TypePrivate Declare Function PeekMessage Lib “user32” Alias “PeekMessageA” (lpMsg _ As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long,

Disable the Ctrl-Alt-Del key combination (Windows 9x only)

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 believe