Make Your Own Control - Part 1
The first will make your program stay 'on top'. Make a new ActiveX control and add a .bas module (Project, Add Module). This first piece of code sets some constants and uses an API call on the 'user32' library. Add this code to the module:
Public Const HWND_TOPMOST = -1 Public Const HWND_NOTOPMOST = -2 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Const SWP_NOACTIVATE = &H10 Public Const SWP_SHOWWINDOW = &H40 Public Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, _ ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Now that the raw material is in place, you can set some properties for the control.
By default, the control name is 'UserControl1'. Change its name to something relevant like 'OnTop'. Change the CanGetFocus property to False and the InvisibleAtRunTime property to True. Give it a nice picture and leave the ToolboxBitmap property to None, unless you feel the desire to give it a meaningless picture!
Open up the code window for the Control, and go to the General Declarations procedure. This code adds a method statement, which makes the program 'normal':
Public Sub MakeNormal(Handle As Long) SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS End Sub
Now add this method statement to put the program on top:
Public Sub MakeTopMost(Handle As Long) SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS End Sub
Right, time to compile the control. Click File, Make OnTop.ocx. Now save the project (File, Save Project).
Page 2 of 3