Constancia

VB_Window_Primer_Plano

May 28th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    Option Explicit
  2.       Dim THandle As Long
  3.  
  4.       Private Declare Function BringWindowToTop Lib "user32" (ByVal _
  5.          hwnd As Long) As Long
  6.  
  7.       Private Declare Function FindWindow Lib "user32" Alias _
  8.          "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName _
  9.          As Any) As Long
  10.  
  11.       Private Sub Form_Load()
  12.          Command1.Caption = "Run the Calculator"
  13.          Command2.Caption = "Find Calculator's Handle"
  14.          Command3.Caption = "Bring Calculator To The Top"
  15.          Command2.Enabled = False
  16.          Command3.Enabled = False
  17.       End Sub
  18.  
  19.       Private Sub Command1_Click()
  20.          Dim X As Long
  21.          X = Shell("Calc.exe", 1)
  22.          If X <> 0 Then
  23.             Command2.Enabled = True
  24.          End If
  25.       End Sub
  26.  
  27.       Private Sub Command2_click()
  28.          THandle = FindWindow(vbEmpty, "Calculator")
  29.          If THandle = 0 Then
  30.             Command3.Enabled = False
  31.             MsgBox "Sorry, the calculator is running"
  32.             Exit Sub
  33.          End If
  34.          Command3.Enabled = True
  35.       End Sub
  36.  
  37.       Private Sub Command3_click()
  38.          Dim iret As Long
  39.          iret = BringWindowToTop(THandle)
  40.       End Sub
Advertisement
Add Comment
Please, Sign In to add comment