[python-win32] python-win32 Digest, Vol 69, Issue 23

Ferdinand Sousa ferdinandsousa at gmail.com
Tue Dec 16 12:53:32 CET 2008


---------- Forwarded message ----------

> From: Tim Roberts <timr at probo.com>
> To: Python-Win32 List <python-win32 at python.org>
> Date: Mon, 15 Dec 2008 10:03:17 -0800
> Subject: Re: [python-win32] Post Message
> Ferdinand Sousa wrote:
> >
> > I have written a small script to automate a process. The issue is that
> > a "Save As" pops up at the end. Using Winspector, I could come up with
> > this:
> > win32gui.PostMessage(win_hdl,con.WM_COMMAND,1,0) # handle to the "Save
> > As" window, message type, Control ID of the "Save"
> > button
> >  This works perfectly. However, now I would like to modify the "File
> > name" field so that I can change the default save location. It is a
> > combo box and has a control ID 1148. Using intuition, I tried
> > WM_SETTEXT, but no luck. Any pointers?
> > If possible, could any one point out any general, simple-to-use help
> > on the PostMessage function?
>
> What process are you automating?  Many big applications today can be
> controlled by COM, which is a much more reliable and predictable method
> of control than hacking window messages.
>
> Remember that the "Save As" dialog is in a separate top-level window,
> and because it is modal, it has its own message loop.
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
>
Actually, I am using COM to control Adobe Acrobat 7. I searched high and low
for methods to enable pdfs for commenting in Adobe Reader, and the only
method I could find was to execute the appropriate menu item in Acrobat. I
did all this in COM. The problem is that once that option is executed, the
Save As dialog pops up. Now, I am able to click the Save button (as
mentioned in my previous mail).

Between yesterday and now, I have got this:

gui.PostMessage(combo_hwnd,con.WM_SETFOCUS,0,0)
gui.SendMessage(combo_hwnd,con.WM_SETTEXT,0,'F:\Sample File.pdf' )

I am now able to set the text in the combo box. How ever this requires the
handle of the combo box. I can obtained the handles to the owner of Save As
and Save As itself.

w_hwnd=1573334
>>> gui.GetWindowText(w_hwnd)
'Save As'
>>> child=gui.GetWindow(w_hwnd, con.GW_CHILD)
>>>
>>> for i in range (20):
           child=gui.GetWindow(child, con.GW_HWNDNEXT)
           print b,'=',gui.GetWindowText(child)

3342844 =
459416 =
2031970 =
655960 =
917912 =
1114744 =
1573478 = File &name:
1442168 =                             #### this is the  handle of the combo
box
787024 = Save as &type:
852368 =
1114516 = Open as &read-only
1049194 = &Save
1900908 = Cancel
1442464 = &Help
1180026 =
1442306 =
0 =
Traceback (most recent call last):
  File "<pyshell#114>", line 2, in <module>
    child=gui.GetWindow(child, con.GW_HWNDNEXT)
error: (1400, 'GetWindow', 'Invalid window handle.')
>>>

I feel this is not the correct way to get the handle of the combo. Any
ideas?
The WM_COMMAND is sent to the Save As window with control ID = 1
(Referencing the Save button). Is there any way I can modify the filename by
sending messages to the Save As window using the control ID of the combo as
a parameter?


Thanks for taking the trouble to read!
Ferdi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081216/466d6eb2/attachment.htm>


More information about the python-win32 mailing list