[Python-au] win32gui question

jt1masters at optusnet.com.au jt1masters at optusnet.com.au
Mon Apr 18 05:44:14 CEST 2005


The python code is indeed external to the MFC process, and the MFC code is internal.

The confusion arises from the fact that the python and mfc code have different
results, even though they are supposedly calling the same code. The mfc code gives
the -expected- result (based on ms documentation) of setting the text in the
editbox, where as the python code gives the -desired- result of setting the caption
of the edit box without touching what's inside the edit box.

But yes, I think you are correct about using the dialog ID's from resource.h to
identify the controls, that hadn't occurred to me.

Thanks, Justin

> Tony McGee <tony.mcgee at eracom-tech.com> wrote:
> 
> 
> At the risk of being off-topic...
> 
> Since you're trying to perform automated gui testing for an external
> product, is it safe to assume that your python code is an external 
> process
> attempting to call SetWindowText() for another process (i.e. your MFC 
> based
> product), and the MFC code is internal to the process itself? If this 
> is
> the case then to change the edit box you have to send the WM_SETTEXT
> message yourself.
> 
> >From the MSDN SetWindowText() documentation:
> "If the target window is owned by the current process, SetWindowText 
> causes
> a WM_SETTEXT message to be sent to the specified window or control.
> To set the text of a control in another process, send the WM_SETTEXT
> message directly instead of calling SetWindowText."
> 
> In response to your question:
> What I'd like to know is: What is win32gui.SetWindowText actually doing 
> so
> we can do
> the same thing in the MFC code so that  the gui will have all the 
> controls
> named on
> startup?
> 
> If all you want to do is identify dialog controls, then I believe you 
> can
> still identify them by their dialog control ID at runtime, if you are
> willing to accept the coupling between the testing process and dialog
> resources from the development process. You already have hinted that 
> this
> might be acceptable when you wanted the controls to be named on 
> startup.
> 
> Tony McGee
> Software Engineer
> Privacy of Information Products
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> Eracom Technologies Australia Pty. Ltd.
> 
> 
> 
>                                                                         
>                                               
>                     jt1masters at optusne                                  
>                                               
>                     t.com.au                  To:     
> python-au at python.net                                            
>                     Sent by:                  cc:                       
>                                               
>                     python-au-bounces@        Subject:     [Python-au] 
> win32gui question                              
>                     python.net                                          
>                                               
>                                                                         
>                                               
>                                                                         
>                                               
>                     18/04/2005 11:58                                    
>                                               
>                     AM                                                  
>                                               
>                                                                         
>                                               
>                                                                         
>                                               
> 
> 
> 
> Hi all,
> 
> I'm new to the list, and new to python for that matter.
> I have a question regarding the win32gui module/win32 extensions.
> 
> My current task is to investigate the possibility of automated gui 
> testing
> for one
> of our products using python, specifically WATSUP (Windows Application 
> Test
> System
> Using Python)
> 
> A concern was raised that edit boxes would not be able to be 
> distinguished
> because
> it was not possible to name an edit box without the name appearing in 
> the
> edit box.
> Writing a small MFC app with a single richedit box, I was able to name 
> the
> edit box
> using python by calling win32gui.SetWindowText() and it would not show 
> up
> in the
> box, and I was able to verify the caption of the edit box using Spy++.
> 
> I then tried to achieve the same result with MFC code using the
> CWnd::SetWindowText() but for some reason this behaved differently. The
> text
> appeared in the box, and a caption was not set.
> 
> I then used Spy++ to check the messages being sent for each operation, 
> and
> as far as
> I can tell, win32gui.SetWindowText doesn't send any messages, but 
> achieves
> the
> desired result.
> 
> What I'd like to know is: What is win32gui.SetWindowText actually doing 
> so
> we can do
> the same thing in the MFC code so that  the gui will have all the 
> controls
> named on
> startup?
> 
> Below is the python code I used to test this, the source for
> setEditText(minus the
> commenting), the MFC code I used and the Spy++ output I got when 
> running
> the python
> code and the mfc code.
> 
> Any help would be most appreciated
> Thanks
> 
> Justin
> 
> ----------------------------------------------------------------
> Python code
> 
> form=findTopWindow(wantedText='MFCTestProgram',wantedClass='#32770')
>       #from winGuiAuto
> edit=findControl(form,wantedClass='RICHEDIT')
>                 #from winGuiAuto
> setEditText(edit, 'Calling SetWindowText on next line')
>                 #from winGuiAuto
> win32gui.SetWindowText(edit, 'BondEditBox')
> setEditText(edit, 'SetWindowText was called')
>            #from winGuiAuto
> 
> ----------------------------------------------------------------
> setEditText()
> 
> def setEditText(hwnd, text, append=False):
> 
>     # Ensure that text is a list
>     try:
>         text + ''
>         text = [text]
>     except TypeError:
>         pass
> 
>     # Set the current selection range, depending on append flag
>     if append:
>         win32gui.SendMessage(hwnd,
>                              win32con.EM_SETSEL,
>                              -1,
>                              0)
>     else:
>         win32gui.SendMessage(hwnd,
>                              win32con.EM_SETSEL,
>                              0,
>                              -1)
> 
>     # Send the text
>     win32gui.SendMessage(hwnd,
>                          win32con.EM_REPLACESEL,
>                          True,
>                          os.linesep.join(text))
> 
> ----------------------------------------------------------------
> MFC Code
> 
> CWnd* pWnd = GetDlgItem(IDC_RICHEDIT1);
> pWnd->SetWindowText(_T("ButtonClicked"));
> 
> ----------------------------------------------------------------
> Spy++ Output
> 
> PYTHON
> 
> <00001> 000C0370 S EM_SETSEL nStart:0 nEnd:-1 (select all text)
> <00002> 000C0370 R EM_SETSEL
> <00003> 000C0370 S EM_REPLACESEL lpszReplace:0012FD0C("Calling
> SetWindowText on next
> line")
> <00004> 000C0370 R EM_REPLACESEL
> <00005> 000C0370 P WM_PAINT hdc:00000000
> <00006> 000C0370 S EM_SETSEL nStart:0 nEnd:-1 (select all text)
> <00007> 000C0370 R EM_SETSEL
> <00008> 000C0370 S EM_REPLACESEL lpszReplace:0012FD14("SetWindowText 
> was
> called")
> <00009> 000C0370 R EM_REPLACESEL
> <00010> 000C0370 P WM_PAINT hdc:00000000
> 
> MFC
> 
> <00023> 000C0370 S WM_GETDLGCODE
> <00024> 000C0370 R WM_GETDLGCODE
> fuDlgCode:DLGC_WANTARROWS|DLGC_WANTTAB|DLGC_HASSETSEL|DLGC_WANTCHARS
> <00025> 000C0370 S .WM_SETTEXT lpsz:00415108("ButtonClicked")
> <00026> 000C0370 R .WM_SETTEXT fSucceeded:True
> <00027> 000C0370 P WM_PAINT hdc:00000000
> 
> 
> 
> 
> _______________________________________________
> python-au maillist  -  python-au at starship.python.net
> http://starship.python.net/mailman/listinfo/python-au
> 
> 
> 
> 
> 
> _______________________________________________
> python-au maillist  -  python-au at starship.python.net
> http://starship.python.net/mailman/listinfo/python-au



More information about the python-au mailing list