Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Service VB App?

Status
Not open for further replies.

tpercy

Programmer
Oct 3, 2002
19
US
Hello! I would like to create a VB application that runs as a system service. The computer is never shut down unless of a power failure. I need to create the word "DEMO" centered on the top and bottom of a four monitor screen. It needs to always be visible regardless of applications running. Is it possible to do this? It must not interfere with maximizing applications and it must be displayed on all four monitors.
I know how to run an app as a system service but I am unsure of how to code this kind of app.
Thanks in advance for any help!
 
I found this microsoft web page eons ago and kept a copy of it. I have used the code and it works great if you need something that will sit on top of all forms at all times. Use sparingly as the form can get int the way if placed over something important (like a close button).


HOWTO: Create a Form That Always Stays on Top (Q184297)
Step-by-Step Example
[ol]
[li]Start a new Standard EXE project. Form1 is created by default.[/li]
[li]Add two command buttons (Command1 and Command2) to Form1.[/li]
[li]Set the caption property of Command1 to "Always on top."[/li]
[li]Set the caption property of Command2 to "Normal."[/li]
[li]Put the following code in the Form1 Declaration section:
Code:
Option Explicit

Private Sub Command1_Click()
  Dim lR As Long
  lR = SetTopMostWindow(Form1.hwnd, True)
End Sub

Private Sub Command2_Click()
  Dim lR As Long
  lR = SetTopMostWindow(Form1.hwnd, False)
End Sub
[/li]
[li]On the Project menu, click Add Module, to add a new module to the project.[/li]
[li]Add the following code to the new module:
Code:
Option Explicit

Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos"  _
            (ByVal hwnd As Long, _
            ByVal hWndInsertAfter As Long, _
            ByVal x As Long, _
            ByVal y As Long, _
            ByVal cx As Long, _
            ByVal cy As Long, _
            ByVal wFlags As Long  ) As Long

Public Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long

  If Topmost = True Then 'Make the window topmost
    SetTopMostWindow = _
      SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,FLAGS)
  Else
    SetTopMostWindow = _
      SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,FLAGS)
      SetTopMostWindow = False
  End If
End Function

NOTE: In the above sample code, an underscore (_) at the end of a line is used as a line-continuation character.
[/li]

[li]Press F5 to run the project. [/li]
[/ol]
If you click the "Always on top" command button, your form becomes the topmost window and remains on top of every window; you cannot move any other window on top of it. If you click the "Normal" button, the form behaves normally (you can move other windows on top of it).

References
For additional information, please see the following articles in the Microsoft Knowledge Base:
[ul]
[li]Q84251 How to Create a Topmost or Floating Window in Visual Basic[/li]
[li]Q150233 BUG: Topmost Window Does Not Stay on Top in Design Environment[/li]
[/ul]

---------------------------------------
Where would one begin to study Myology?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top