Constancia icon

VB_Window_Primer_Plano

Constancia | PRO | 05/28/13 06:29:23 AM UTC | 0 ⭐ | 144 👁️ | Never ⏰ | []
VisualBasic |

1.19 KB

|

None

|

0 👍

/

0 👎

   Option Explicit
      Dim THandle As Long
 
      Private Declare Function BringWindowToTop Lib "user32" (ByVal _
         hwnd As Long) As Long
 
      Private Declare Function FindWindow Lib "user32" Alias _
         "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName _
         As Any) As Long
 
      Private Sub Form_Load()
         Command1.Caption = "Run the Calculator"
         Command2.Caption = "Find Calculator's Handle"
         Command3.Caption = "Bring Calculator To The Top"
         Command2.Enabled = False
         Command3.Enabled = False
      End Sub
 
      Private Sub Command1_Click()
         Dim X As Long
         X = Shell("Calc.exe", 1)
         If X <> 0 Then
            Command2.Enabled = True
         End If
      End Sub
 
      Private Sub Command2_click()
         THandle = FindWindow(vbEmpty, "Calculator")
         If THandle = 0 Then
            Command3.Enabled = False
            MsgBox "Sorry, the calculator is running"
            Exit Sub
         End If
         Command3.Enabled = True
      End Sub
 
      Private Sub Command3_click()
         Dim iret As Long
         iret = BringWindowToTop(THandle)
      End Sub

Comments