Link to home
Create AccountLog in
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Avatar of grahampe
grahampe

Focous
Can a form be given sole Focous so that nothing else can. In other words if I have a form load can I make it so nothing else can be clicked on, selected or accessed in windows until that form has been unloaded.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Davy070599Davy070599

impossible on NT based systems!


On win 9.x it's possible but you'll have to be sure that your code handles all keyboard activity

Avatar of PaulHewsPaulHews🇨🇦

That's a 16 bit function call isn't it Davy?  There is no SetSystemModal in Win 32.  Here's some code to disable the Alt-Tab and Alt-Ctrl-Del combos

Private Const SPI_SCREENSAVERRUNNING = 97&
      Private Declare Function SystemParametersInfo Lib "User32" _
          Alias "SystemParametersInfoA" _
         (ByVal uAction As Long, _
          ByVal uParam As Long, _
          lpvParam As Any, _
          ByVal fuWinIni As Long) As Long

      Private Sub Form_Load()
         Command1.Caption = "Disabled"
         Command2.Caption = "Enabled"
      End Sub

      Private Sub Form_Unload(Cancel As Integer)
         'Re-enable CTRL+ALT+DEL and ALT+TAB before the program terminates.
         Command2_Click
      End Sub

      Private Sub Command1_Click()
         Dim lngRet As Long
         Dim blnOld As Boolean
         lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, _
         blnOld, _
            0&)
      End Sub

      Private Sub Command2_Click()
        Dim lngRet As Long
        Dim blnOld As Boolean
        lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, _
        blnOld, _
           0&)
      End Sub
 


ASKER CERTIFIED SOLUTION
Avatar of PaulHewsPaulHews🇨🇦

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of PaulHewsPaulHews🇨🇦

To stop the user unloading your program set the form caption = "" and set controlbox to false.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


<ping>

Or you *could* do it the nasty way. Get a 16bit app to make the call to SetSysModal. Pass your hWnd as the command line. I used to like doing this as a joke...

Avatar of grahampegrahampe

ASKER

PaulHews your answer is very good and it works but I need it to happen on form load and then I need to be able to type in a password and click a command button if the password is right it will close the form and give access back to the user if the password is wrong a message box says its wrong and loops back to allow the password to be entered again. I have tried modifying your code to do this but it completely blocks me out and won't let me type into the password text box or click the command button.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


This is what I have so far:

Option Explicit
Private Const SPI_SCREENSAVERRUNNING = 97&
      Private Declare Function SystemParametersInfo Lib "user32" _
          Alias "SystemParametersInfoA" _
         (ByVal uAction As Long, _
          ByVal uParam As Long, _
          lpvParam As Any, _
          ByVal fuWinIni As Long) As Long
' SetWindowPos Function
      Private Declare Function SetWindowPos Lib "user32" _
         (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

      ' SetWindowPos Flags
      Private Const SWP_NOSIZE = &H1
      Private Const SWP_NOMOVE = &H2
      Private Const HWND_TOPMOST = -1
      Private Const HWND_NOTOPMOST = -2

Public LoginSucceeded As Boolean


Private Sub cmdOK_Click()
    'check for correct password
    If txtPassword = Form1.Text1.Text Then
        'place code to here to pass the
        'success to the calling sub
        'setting a global var is the easiest
        LoginSucceeded = True
        Dim lngRet As Long
        Dim blnOld As Boolean
        lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, _
        blnOld, _
           0&)
        End
    Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        SendKeys "{Home}+{End}"
    End If
End Sub

Private Sub Command1_Click()
    'check for correct password
    If txtPassword = Form1.Text1.Text Then
        'place code to here to pass the
        'success to the calling sub
        'setting a global var is the easiest
        LoginSucceeded = True
        Dim lngRet As Long
        Dim blnOld As Boolean
        lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, _
        blnOld, _
        0&)
        Form1.Show
        Unload Me
    Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        SendKeys "{Home}+{End}"
    End If

End Sub

Private Sub Form_Load()
    Me.Left = 0
    Me.Top = 0
    SetTopMostWindow Me.hwnd, True
    Dim lngRet As Long
    Dim blnOld As Boolean
    lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, _
    blnOld, _
    0&)
End Sub

Private Sub Form_Resize()
    Me.Width = Screen.Width
    Me.Height = Screen.Height
     
End Sub

Avatar of PaulHewsPaulHews🇨🇦

This worked for me.  Of course I had to add Form2, reverse name of Form1 with Form2 and put Text1 on Form1, then I set the Text property to "password".

Have you setup Form2 as the startup object for the project?  Is there any code in form1 I should know about?

If not, save your project and reboot.  
Try it when your machine is cleanly booted.

Yes form2 is the start up form and here is the code on form1 so far.

Option Explicit
Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal _
   lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
   lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Const pass = "yepper.ini"


Private Sub Command1_Click()
Dim lReturn As Long
If Check1.Value = 1 Then
  lReturn = fCreateShellLink("\Startup", "Protector", _
  App.Path & "\protector.exe", "")
End If
ChDir "c:\windows"
Open pass For Output As #1
Print #1, Text1.Text
Close #1
Unload Me
End Sub

Private Sub Command2_Click()
frmLogin.Show
Unload Me
End Sub

Private Sub Form_Load()
Check1.Value = CInt(GetSetting("MyApp", "Controls", "Checkbox", "0"))

IGNORE THIS PART OF CODE FOR NOW I NEED TO FIX IT
'Dim getit
'Open pass For Input As #1
'Print #1, getit
'Close #1
'Text1.Text = getit
End Sub

Private Sub Form_Unload(Cancel As Integer)
SaveSetting "MyApp", "Controls", "Checkbox", Check1.Value
End Sub

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Thanks I have sorted out my problems I started from scratch.

Avatar of PaulHewsPaulHews🇨🇦

That's great!  Thanks for the points.  I was going to post saying your Form2 code was also locking up my machine, but I was still in Scandisk while you were posting this.
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.