Click to See Complete Forum and Search --> : How to show my project on the "top window layer"?


kee149
May 2nd, 2006, 03:20 AM
I wanna do a project which it show on the top layer of window

for example, when the window start, my project will appear on the top and user can't do anything with a desktop. (my project is full screen). And also lock any programs. user can't do anything. they have to log in for unlocking my project first.

my propose is that I wanna do a internet cafe program for my own shop. and I want to do my program myself.

Thks
Kee

HanneSThEGreaT
May 2nd, 2006, 04:05 AM
You're in luck - I've got something similar! :wave:
How this program works:
With an easter egg I activate the Username and Password fields (you must click 3 times left, type O, right click 3 times, press J) - the fields will be activated then, it checks a file named Jolt.txt for username and password.
If it's correct, you can continue with the program.
The form is maximized, no border.
When Ctrl Alt Del, or Ctrl Esc, or Alt Tab is pressed, nothing happens.
Start a new Project, and copy and replace all your existing code with this. Also create a file named Jolt.txt with Username and password. Just type the username on one line, then type the password on the second line, something like:
UserName
Password

'system hook libraries
Imports System.Runtime.InteropServices 'MarshalAs, Marshal
Imports System.Reflection 'assembly

Public Class frmJolt
Inherits System.Windows.Forms.Form

'disable alt+tab and ctrl+esc and alt esc system keys
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer

Public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Integer, _
ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, _
ByVal dwThreadId As Integer) As Integer

Private Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Integer) As Integer

Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Integer, _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As KBDLLHOOKSTRUCT) As Integer

Public Structure KBDLLHOOKSTRUCT

Public vkCode As Integer
Public scanCode As Integer
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer

End Structure

' Low-Level Keyboard Constants
Private Const HC_ACTION As Integer = 0
Private Const LLKHF_EXTENDED As Integer = &H1
Private Const LLKHF_INJECTED As Integer = &H10
Private Const LLKHF_ALTDOWN As Integer = &H20
Private Const LLKHF_UP As Integer = &H80

' Virtual Keys
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const VK_DELETE = &H2E
Public Const VK_MENU = &H12

Private Const WH_KEYBOARD_LL As Integer = 13&
Public KeyboardHandle As Integer

' Implement this function to block as many
' key combinations as you'd like
Public Function IsHooked( _
ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean

If (Hookstruct.vkCode = VK_ESCAPE) And _
CBool(GetAsyncKeyState(VK_CONTROL) _
And &H8000) Then

Call HookedState("Ctrl + Esc blocked")
Return True
End If

If (Hookstruct.vkCode = VK_TAB) And _
CBool(Hookstruct.flags And _
LLKHF_ALTDOWN) Then

Call HookedState("Alt + Tab blockd")
Return True
End If

If (Hookstruct.vkCode = VK_ESCAPE) And _
CBool(Hookstruct.flags And _
LLKHF_ALTDOWN) Then

Call HookedState("Alt + Escape blocked")
Return True
End If

Return False

End Function

Private Sub HookedState(ByVal Text As String)

Debug.WriteLine(Text)

End Sub

Public Function KeyboardCallback(ByVal Code As Integer, _
ByVal wParam As Integer, _
ByRef lParam As KBDLLHOOKSTRUCT) As Integer

If (Code = HC_ACTION) Then
Debug.WriteLine("Calling IsHooked")

If (IsHooked(lParam)) Then
Return 1
End If

End If

Return CallNextHookEx(KeyboardHandle, _
Code, wParam, lParam)

End Function

Public Delegate Function KeyboardHookDelegate( _
ByVal Code As Integer, _
ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) _
As Integer

<MarshalAs(UnmanagedType.FunctionPtr)> _
Private callback As KeyboardHookDelegate

Public Sub HookKeyboard()

callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)

KeyboardHandle = SetWindowsHookEx( _
WH_KEYBOARD_LL, callback, _
Marshal.GetHINSTANCE( _
[Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)

Call CheckHooked()

End Sub

Public Sub CheckHooked()

If (Hooked()) Then
Debug.WriteLine("Keyboard hooked")
Else
Debug.WriteLine("Keyboard hook failed: " & Err.LastDllError)
End If

End Sub

Private Function Hooked()

Hooked = KeyboardHandle <> 0

End Function

Public Sub UnhookKeyboard()

If (Hooked()) Then
Call UnhookWindowsHookEx(KeyboardHandle)
End If

End Sub
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents butJLogin As System.Windows.Forms.Button
Friend WithEvents tJolt As System.Windows.Forms.Timer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtJUName As System.Windows.Forms.TextBox
Friend WithEvents txtJPass As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.butJLogin = New System.Windows.Forms.Button
Me.tJolt = New System.Windows.Forms.Timer(Me.components)
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.txtJUName = New System.Windows.Forms.TextBox
Me.txtJPass = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'butJLogin
'
Me.butJLogin.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.butJLogin.Location = New System.Drawing.Point(208, 232)
Me.butJLogin.Name = "butJLogin"
Me.butJLogin.TabIndex = 2
Me.butJLogin.Text = "Login"
Me.butJLogin.Visible = False
'
'tJolt
'
Me.tJolt.Enabled = True
Me.tJolt.Interval = 10
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(16, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(75, 18)
Me.Label1.TabIndex = 1
Me.Label1.Text = "User Name"
Me.Label1.Visible = False
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(23, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(68, 18)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Password"
Me.Label2.Visible = False
'
'txtJUName
'
Me.txtJUName.BackColor = System.Drawing.Color.Black
Me.txtJUName.ForeColor = System.Drawing.Color.OrangeRed
Me.txtJUName.Location = New System.Drawing.Point(104, 16)
Me.txtJUName.Name = "txtJUName"
Me.txtJUName.Size = New System.Drawing.Size(168, 22)
Me.txtJUName.TabIndex = 0
Me.txtJUName.Text = ""
Me.txtJUName.Visible = False
'
'txtJPass
'
Me.txtJPass.BackColor = System.Drawing.Color.Black
Me.txtJPass.ForeColor = System.Drawing.Color.OrangeRed
Me.txtJPass.Location = New System.Drawing.Point(104, 56)
Me.txtJPass.Name = "txtJPass"
Me.txtJPass.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtJPass.Size = New System.Drawing.Size(168, 22)
Me.txtJPass.TabIndex = 1
Me.txtJPass.Text = ""
Me.txtJPass.Visible = False
'
'frmJolt
'
Me.AutoScaleBaseSize = New System.Drawing.Size(7, 15)
Me.BackColor = System.Drawing.Color.Black
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.txtJPass)
Me.Controls.Add(Me.txtJUName)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.butJLogin)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ForeColor = System.Drawing.Color.OrangeRed
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.KeyPreview = True
Me.Name = "frmJolt"
Me.ShowInTaskbar = False
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)

End Sub

#End Region

'easter egg
Private JCount As Integer 'attemted to login
Private leftClicks As Integer = 0 'number of l clicks
Private rightClicks As Integer = 0 'number of r clicks
Private oPressed As Boolean = False 'first button pressed

'shutdown pc
Private Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Int32, ByVal dwReserved As Int32) As Int32

Private Const EWX_SHUTDOWN = 1

Private Sub butJLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butJLogin.Click

'read file for username and password
Dim ReadString As String
Dim iFr As Short
Dim sTmp As String
Dim JUName As String
Dim JPass As String

ReadString = Application.StartupPath & "\Jolt.txt" 'path
iFr = FreeFile() 'free file for reading
FileOpen(iFr, ReadString, OpenMode.Binary) 'file handle, path, mode
sTmp = Space(FileLen(ReadString)) 'varibale into which data is read
FileGet(iFr, sTmp) 'filename, data read variable
FileClose(iFr) 'close

Dim strRecords() As String : strRecords = Split(sTmp, vbCrLf) 'chain multiple statements with :

JUName = strRecords(0) 'first line
JPass = strRecords(1) 'second line

If (txtJUName.Text = JUName And txtJPass.Text = JPass) Then
MsgBox("Welcome Back HanneSThEGreaT!", MsgBoxStyle.Information, "Login")
Me.Close()
Else
'wrong user name or pass
MsgBox("Wrong Password!" & Environment.NewLine & "Try Again!", MsgBoxStyle.Exclamation, "Login")

'shutdown
Call ExitWindowsEx(EWX_SHUTDOWN, 1) 'shut down pc
End If
End If

End Sub

Private Sub frmJolt_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

HookKeyboard() 'hook system keys
Me.TopMost = True 'always on top

End Sub

Private Sub frmJolt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus

' Me.Focus() ' when form object loses focus (another form, control, or program - form always has focus)

End Sub

Private Sub tJolt_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tJolt.Tick

Me.BringToFront() 'top in zorder, other apps move to the back

End Sub

'easter egg
'sequence
'Left Click 3 times
'Press O
'Right Click 3 times
'press J
Private Sub frmJolt_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

If e.Button = MouseButtons.Left AndAlso Me.leftClicks < 3 Then 'if l button clicked 3 times
Me.leftClicks += 1

ElseIf e.Button = MouseButtons.Right AndAlso Me.oPressed AndAlso Me.rightClicks < 3 Then 'if right cliked 3 times and o was pressed
Me.rightClicks += 1

Else
Me.ResetEasterEgg() 'reset
End If

End Sub

Private Sub frmJolt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If (e.KeyChar = "o"c OrElse e.KeyChar = "O"c) AndAlso Me.leftClicks = 3 Then 'if o is pressed when l clicks = 3
Me.oPressed = True

ElseIf (e.KeyChar = "j"c OrElse e.KeyChar = "J"c) AndAlso Me.rightClicks = 3 Then 'if j is pressed when rclicks = 3 c = convert literal to char

'Activate easter egg.
butJLogin.Visible = True
Label1.Visible = True
Label2.Visible = True
txtJUName.Visible = True
txtJPass.Visible = True
txtJUName.Focus()
Me.KeyPreview = False 'in order to type in textboxes

Me.ResetEasterEgg() 'reset

Else
Me.ResetEasterEgg() 'reset
End If

End Sub

Private Sub ResetEasterEgg()

Me.leftClicks = 0
Me.rightClicks = 0
Me.oPressed = False

End Sub
End Class

kebo
May 2nd, 2006, 08:41 PM
you may want to look into using XP embedded. With it you can build your own XP OS by adding whatever Windows components you need.
kevin