473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

odd problem with watsup and VB6 application with modal dialog

For various reasons, I've found myself in the position of needing to
automate the operation of a small VB6 application from an external
process. After a bit of searching, I found watsup, and it has fit the
bill nicely, except for one problem.

Roughly, I have a script that fills in a field, sets a combobox, then
clicks a button via clickButton. At this point, the python interpreter
hangs. The only thing I've been able to identify as different about this
form is that it is set as dialog-modal.

I've managed to work around this by adding a second python script that
contains just enough code to click the offending button. I call it via
os.system('start other.py') and it starts in a different process, clicks
the button then hangs.

But the main script continues on to fill in the following form, and
click another button. When the VB app returns to its starting form,
destroying the other form instances, the hung interpreter ends.

This works, but it is quite the ugly kludge isn't it?

Is this a normal behaviour for watsup with modal windows? Is there a
saner way around it?

I should point out I spend my days in the midrange world, so I'm largely
ignorant of the vagaries of the windows API and such.
Nov 11 '06 #1
3 2160
Grumman wrote in news:JN**************@newsfe03.lga in comp.lang.python:

[snip]
Roughly, I have a script that fills in a field, sets a combobox, then
clicks a button via clickButton. At this point, the python interpreter
hangs. The only thing I've been able to identify as different about
this form is that it is set as dialog-modal.

I've managed to work around this by adding a second python script that
contains just enough code to click the offending button. I call it via
os.system('start other.py') and it starts in a different process,
clicks the button then hangs.

But the main script continues on to fill in the following form, and
click another button. When the VB app returns to its starting form,
destroying the other form instances, the hung interpreter ends.

This works, but it is quite the ugly kludge isn't it?

Is this a normal behaviour for watsup with modal windows? Is there a
saner way around it?
AFAICT the problem is that the clickButton() function calls
the internal windows API function SendMessage(), which waits
for the buttons event handler to return something.

There is an alternative PostMessage(), which returns as soon as
the message is put in the target windows message queue.

A potential proplen with this is that it will return immediately
so the caller will need to wait (time.sleep) until the button
handler has recieved the message and done something about it.

Here's a rewrite of the winGuiAuto.clickButton function,
post_clickButton() that uses PostMessage:

def post_clickButton( hwnd ):
'''All code here adapted from winGuiAuto.py
see http://www.tizmoi.net/watsup/intro.html
'''

def _buildWinLong(high, low):
'''Build a windows long parameter from high and low words.

See http://support.microsoft.com/support.../q189/1/70.asp
'''
return int( 0xFFFFFFFF & ( (high << 16) | (low & 0xFFFF) ) )

def _postNotifyMessage(hwnd, notifyMessage):
'''Post a notify message to a control.'''
import win32gui
import win32con
import win32api

win32gui.PostMessage(
win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(
notifyMessage, win32api.GetWindowLong(hwnd, win32con.GWL_ID)
),
hwnd
)

import win32con
_postNotifyMessage( hwnd, win32con.STN_CLICKED )

if __name__=='__main__':

'''Just here to show how it works, this code won't actually
work unless you have a sutible GUI programme running.
'''

from watsup.winGuiAuto import \
findControl,setEditText, \
findTopWindow,clickButton
from time import sleep

def main():

form=findTopWindow(wantedText='Main_Form')
button=findControl(form,wantedText='Open')

print 'clicking button to open dialog...'
post_clickButton(button)

sleep( 0.5 )

form=findTopWindow(wantedText='Dialog_Form')
button=findControl(form,wantedText='Close')

print "clicking close button"
post_clickButton(button)

main()

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Nov 11 '06 #2
Rob Williscroft wrote:
Here's a rewrite of the winGuiAuto.clickButton function,
post_clickButton() that uses PostMessage:
Thanks for the info, I'll give it a try.
Nov 12 '06 #3
ina
At my work we had the same problem. We found that the best solution
was to use a thread with the code to handle the model dialog. This
worked best for us because the only models in our product are the error
messages, and using a thread gave us the ability to check and see if
the modal dialog was found.

In this post there is some example code. I will post up a more
complete solution when I get to work on monday.

http://groups.google.com/group/comp....7ec7cf2d12801d

Nov 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: martin de vroom | last post by:
Hi, I have a web page that opens a modal dialog (client side) in the following manner onclick="window.showModalDialog('/dialog.asp',null,'dialogHeight: 200px; dialogWidth: 400px; dialogTop:...
2
by: Joe | last post by:
Is there a way to enable scrolling in a modal dialog box even if the call to open the modal has "scroll:no"? I am looking to dynamically size the modal dialog box for starters and if the modal is...
1
by: wendy | last post by:
I have got a problem while using the modal dialogs. In my code I need to open a modal dialog from the parent page and I need to enter some values in the dialog and save it. It takes the values...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
10
by: =?Utf-8?B?Tm90cmUgUG91YmVsbGU=?= | last post by:
Hello, I have a legacy MFC application that has a lot of editor functionality associated with a class that extends CFrameWnd. This editor watches for key down events by using the OnKeyDown...
1
by: Satya | last post by:
Hello, I am using ShowModalDialog to display modal dialog in our application. I am displaying modal dialog (WebForm1.aspx - DropdownList's ,TextBox's and Ok and Cancel buttons placed on it) from...
5
by: GraffixNYC | last post by:
We have a model dialog box(well a bunch of them) and it seems that when you cancel one of the in our application it will activate and bring the focus to another open window (not in our application)...
4
by: Lester | last post by:
I have main application (with main window) created in C++/MFC. From there I call function in C# class library to display a modal WPF dialog. Dialog shows up OK, but it doesn't behave really modal....
2
by: diogenes | last post by:
I have created many shortcut/popup (aka context, or right-click) menus for my application - instead of toolbars or standard drop-down menus. Within my custom menu, I am using...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.