API PARA FECHAR JANELAS

PEGUDO 23/11/2010 11:23:18
#358028
Alguém sabe alguma API ou código para fechar as janelas abertas no windows, inclusive as que não fazem parte do meu programa, como a calculadora por exemplo?

Estou usando este código no módulo:

[txt-color=#0000f0]Module[/txt-color] ModulTeste
[txt-color=#0000f0]Public Declare Function[/txt-color] DestroyWindow [txt-color=#0000f0]Lib[/txt-color] [txt-color=#e80000][Ô]user32[Ô][/txt-color] [txt-color=#0000f0]Alias[/txt-color] [txt-color=#e80000][Ô]DestroyWindow[Ô][/txt-color] ([txt-color=#0000f0]ByVal[/txt-color] hwnd [txt-color=#0000f0]As Long[/txt-color]) [txt-color=#0000f0]As Long[/txt-color]

[txt-color=#0000f0]Public Declare Function[/txt-color] FindWindow [txt-color=#0000f0]Lib[/txt-color] [txt-color=#e80000][Ô]user32[Ô][/txt-color] [txt-color=#0000f0]Alias[/txt-color] [txt-color=#e80000][Ô]FindWindowA[Ô][/txt-color] ([txt-color=#0000f0]ByVal[/txt-color] lpClassName [txt-color=#0000f0]As String[/txt-color], [txt-color=#0000f0]ByVal[/txt-color] lpWindowName [txt-color=#0000f0]As String[/txt-color]) [txt-color=#0000f0]As Long[/txt-color]

[txt-color=#0000f0]Public Declare Function[/txt-color] ShowWindow [txt-color=#0000f0]Lib[/txt-color] [txt-color=#e80000][Ô]user32[Ô][/txt-color] ([txt-color=#0000f0]ByVal[/txt-color] hwnd [txt-color=#0000f0]As Long[/txt-color], [txt-color=#0000f0]ByVal[/txt-color] nCmdShow [txt-color=#0000f0]As Long[/txt-color]) [txt-color=#0000f0]As Long
End Module
[/txt-color]

E isto no código:

[txt-color=#0000f0]Private Sub[/txt-color] Button2_Click([txt-color=#0000f0]ByVal[/txt-color] sender [txt-color=#0000f0]As[/txt-color] System.Object, [txt-color=#0000f0]ByVal[/txt-color] e [txt-color=#0000f0]As[/txt-color] System.EventArgs) [txt-color=#0000f0]Handles[/txt-color] Button2.Click
[txt-color=#0000f0]Dim[/txt-color] processList() [txt-color=#0000f0]As[/txt-color] Process
processList = Process.GetProcesses


[txt-color=#0000f0] Dim [/txt-color]h [txt-color=#0000f0]As Long[/txt-color]

[txt-color=#0000f0]For[/txt-color] X = LBound(processList) [txt-color=#0000f0]To[/txt-color] UBound(processList)
[txt-color=#0000f0]If[/txt-color] processList(X).ProcessName = [txt-color=#e80000][Ô]calc[Ô][/txt-color] [txt-color=#0000f0]Then[/txt-color]
h = FindWindow(vbNullString, [txt-color=#e80000][Ô]calc[Ô][/txt-color]) [txt-color=#007100][ô]Pega o [ô]Handle[ô] da calculadora do Windows. OBS: A calculadora tem que está aberta![/txt-color]
DestroyWindow(h) [txt-color=#007100][ô]Destrói a janela do aplicativo Calculadora.[/txt-color]
ShowWindow(h, 0)
[txt-color=#0000f0]End If[/txt-color]
[txt-color=#0000f0]Next[/txt-color]
MsgBox([Ô]Acabou[Ô])
[txt-color=#0000f0]End Sub[/txt-color]

Mas a calculadora não está fechando.
PEGUDO 23/11/2010 11:37:08
#358029
Amigos programadores,

Consegui fazer o que eu queria.
Aí está o código, caso alguém queira.

[txt-color=#0000f0]Private Sub [/txt-color]Button2_Click([txt-color=#0000f0]ByVal[/txt-color] sender [txt-color=#0000f0]As[/txt-color] System.Object, [txt-color=#0000f0]ByVal[/txt-color] e [txt-color=#0000f0]As[/txt-color] System.EventArgs) [txt-color=#0000f0]Handles[/txt-color] Button2.Click
[txt-color=#0000f0]Dim[/txt-color] processList1() [txt-color=#0000f0]As[/txt-color] Process

processList1 = Process.GetProcessesByName([txt-color=#e80000][Ô]calc[Ô][/txt-color])
[txt-color=#0000f0]For Each[/txt-color] proc [txt-color=#0000f0]As[/txt-color] Process [txt-color=#0000f0]In[/txt-color] processList1
[txt-color=#0000f0]If[/txt-color] MsgBox([txt-color=#e80000][Ô]Encerrar [Ô][/txt-color] & proc.ProcessName & [txt-color=#e80000][Ô]?[Ô][/txt-color], MsgBoxStyle.YesNo, [txt-color=#e80000][Ô]Encerra aplicativo?[Ô][/txt-color]) = MsgBoxResult.Yes [txt-color=#0000f0]Then[/txt-color]
proc.Kill()
[txt-color=#0000f0]End If
Next
End Sub[/txt-color]
Tópico encerrado , respostas não são mais permitidas