Keep a Window Always on Top with SetWindowPos

First, add a Timer control to the program. Enable the timer (named timer1). Set its interval to 100. Then enter the following code (paste it over the existing code, replacing what is already there). Option Strict Off Option Explicit On Public Class Form1 Inherits System.Windows.Forms.Form Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer Dim IntR As Object Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Top = 0 Me.Left = 0 Me.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width Me.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick IntR = SetWindowPos(Me.Handle.ToInt32, -1, 0, 0, 0, 0, 3) End Sub End Class

February 14, 2009 · 1 min

VB Keyboard Simulation

The keyboard is still one of the most important input devices for using a computer. Even in today’s mouse-dominated world, many programs still can’t do without it. But repetitive, tedious keyboard operations can wear people out, so people came up with the idea of using a program to press keys in their place. That saves a lot of effort, and it is exactly what Keyboard Genie (Anjian Jingling) does. So how can we use VB to write a program with similar functionality? Let’s first look at how Windows responds to keyboard events. ...

November 26, 2008 · 24 min