closing an opend application

S

Sam

for closing another application i use the following code
it's work's ok but i have a little problem:
if the appliction changed the user get's a popup
asking for saveing yes or no
how can i force it to close with or without saveing?

thanks a head
sam

Private Const WM_CLOSE = &H10
Private Const INFINITE = &HFFFFFFFF

Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wparam As Long, _
lparam As Any) _
As Long

Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Private Declare Function apiWaitForSingleObject _
Lib "kernel32" Alias "WaitForSingleObject" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) _
As Long

Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiGetWindowThreadProcessId _
Lib "user32" Alias "GetWindowThreadProcessId" _
(ByVal hWnd As Long, _
lpdwProcessID As Long) _
As Long

Function fCloseApp(lpClassName As String) As Boolean

Dim lngRet As Long, hWnd As Long, pID As Long

hWnd = apiFindWindow(lpClassName, vbNullString)
If (hWnd) Then
lngRet = apiPostMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
Call apiGetWindowThreadProcessId(hWnd, pID)
Call apiWaitForSingleObject(pID, INFINITE)
fCloseApp = (apiIsWindow(hWnd) = 0)
End If
End Function

Public Function CloseAppl()
fCloseApp (fEnumWindows)
End Function
 
A

Andi Mayer

for closing another application i use the following code
it's work's ok but i have a little problem:
if the appliction changed the user get's a popup
asking for saveing yes or no
how can i force it to close with or without saveing?
you have to do the same and find the window with the yes no button

and simulate the no-button
 
A

Andi Mayer

thanks
but what is the code for simulating the no-button?
the "easy" methode:
if it's the default then
send an EnterKey
else
send tabs to go to the No and then the Enter key
endif

find the No-button with enumerate child windows, position the cursor
and send a mouse click

luckily till now I only had use the "easy" methode
 
S

Sam

it's not working

Andi Mayer said:
the "easy" methode:
if it's the default then
send an EnterKey
else
send tabs to go to the No and then the Enter key
endif

find the No-button with enumerate child windows, position the cursor
and send a mouse click

luckily till now I only had use the "easy" methode
 
S

Sam

cliking a butten opens open's the kodakimaging
from there user scan's a document and creating a temp tif file
the user return to the access application and by cliking the OK butten copy
the tif file to a folder and close the tmp flie
in this stage the access application has the focus and the tif file is on
the backround
because it was changed a popup comes up for saving but user don't see it
because it is on the backround
i think that sendkey command is not working because the popup is not on the
focus
 
A

Andi Mayer

cliking a butten opens open's the kodakimaging
from there user scan's a document and creating a temp tif file
the user return to the access application and by cliking the OK butten copy
the tif file to a folder and close the tmp flie
in this stage the access application has the focus and the tif file is on
the backround
because it was changed a popup comes up for saving but user don't see it
because it is on the backround
i think that sendkey command is not working because the popup is not on the
focus

the use the following api
if no window is available the api returns 0

I use this (in this example) for logging into a Database-Programm
Note: I use the VBA sendkey, because the api for sendkeys needs a few
lines and a lot of Variables for keys, which are all included in VBA
I don't have to look for the result because I opened the app and
checked for the Loggin-Window before. The Hwnd is from the main-App in
this case

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd
As Long) As Long

sub aaaaaaa()
dim st as string
st = "MyUser" & Chr(9) & "Mypassword"

SetForegroundWindow hWnd
SendKeys st, True
SendKeys "{ENTER}", True
end sub
 
S

Sam

it's not working
thanks for help

Andi Mayer said:
the use the following api
if no window is available the api returns 0

I use this (in this example) for logging into a Database-Programm
Note: I use the VBA sendkey, because the api for sendkeys needs a few
lines and a lot of Variables for keys, which are all included in VBA
I don't have to look for the result because I opened the app and
checked for the Loggin-Window before. The Hwnd is from the main-App in
this case

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd
As Long) As Long

sub aaaaaaa()
dim st as string
st = "MyUser" & Chr(9) & "Mypassword"

SetForegroundWindow hWnd
SendKeys st, True
SendKeys "{ENTER}", True
end sub
 
A

Andi Mayer

I had to write a function today to close my Ebanking, where the
confirmationbox was also a little bit stupid

maybe this works for you:
"BusinessLine" is for both (main and confirm) the exact windows titel

watch for line breaks!!!!! and don't try to step throught the code,
this doesn't work, because the {enter} gets send to the VBE

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd
As Long) As Long
Private Declare Function apiFindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Private Declare Function apiPostMessage Lib "user32" Alias
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam
As Long, ByVal lParam As Long) As Long

Function CloseEbanking()
Dim hwnd As Long
hwnd = apiFindWindow(vbNullString, "BusinessLine")
apiPostMessage hwnd, &H10&, 0, 0
hwnd = apiFindWindow(vbNullString, "BusinessLine")
SetForegroundWindow hwnd
SendKeys "{ENTER}", True
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top