acantor Posted December 5, 2013 Report Share Posted December 5, 2013 I am trying to use Handle variables to positively identify a window when there are two (or more) windows with the same title. This test script does the following 1. Sets a handle variable based on the current window title 2. Activates Microsoft Word. 3. Types some text. 4. Activates the original window (from Step 1.) 5. Types out the title and handle. // Get title and handle for the current window. There may be two or three windows with exactly the same title Variable Set String %WindowTitle% to topmost window title Variable Set Handle %WindowHandle% from a window with the title, "%WindowTitle%" // Jump to a different window, and do something, e.g., type into Microsoft Word Window Activate: Microsoft Word Delay: 500 milliseconds Text Type (Simulate Keystrokes): This is Microsoft Word Delay: 500 milliseconds // Activate the original window, and output the title and handle Window Activate: %WindowHandle% Delay: 500 milliseconds Text Type (Simulate Keystrokes): This is the original window. Title = %WindowTitle% Handle = %WindowHandle% It seems to work, but I am not understanding something. Assuming the original window is an unsaved Notepad document, this is what the final text type command outputs: This is the original window.Title = Untitled - NotepadHandle = Untitled - Notepad Huh? Why is %WindowTitle% the same as %WindowHandle%? My understanding is that each window has a unique handle. Therefore, I expect the value of %WindowHandle% to be different than %WindowTitle%. If there are two windows titled "Untitled - Notepad," how can MEP determine which one I want if the value of the handle variable has the same value as the window title? Maybe I am displaying handle variable values in the wrong way. If this is the case, how do I monitor the true values of handle variables? Quote Link to comment Share on other sites More sharing options...
Samrae Posted December 5, 2013 Report Share Posted December 5, 2013 A Window Handle should be a numberic value. Are you saying that Macro Express Pro is not displaying the handle (a number) but instead is displaying the title of the window containing the handle? Quote Link to comment Share on other sites More sharing options...
Cory Posted December 5, 2013 Report Share Posted December 5, 2013 This is just the way the variable is being cast I think. Open your variables window and run a debug test. F5 to open the window. This will show you the actual variable handle value. But when you display it where it expects text it will show you the window title. I'm pretty sure this is something to do with the casting. Casting is an very important topic in programming and MEP does a very good job of dealing with this for you. And in most cases this helps but in a few it will confuse. The best example of casting I can tell you is that a date is actually stored as an decimal variable. So although you might ask MEP to display a date in the message box and it will appear as 12/5/2013 7:52 AM it's actually 41613.328192963 to the computer. You see it CAST the decimal to a string variable. I think the same is happening here with MEP. In the larger programming world you can control how things are cast. In MEP we don't often have that flexibility. And in this case I don't see a way to convert a handle to string. And BTW handles are actually binary so even the integer representation is a cast ;-) Quote Link to comment Share on other sites More sharing options...
acantor Posted December 6, 2013 Author Report Share Posted December 6, 2013 Cory, I think you are on to something. Here are the results when I ran the script with the "Variables" window open. The value of %WindowHandle% displayed as "1181220" not "Document - WordPad." I closed WordPad, opened it, and ran the macro again.The value of %WindowHandle% was completely different. It would appear that MEP does not provide a way to manipulate Handle variables. But the Handles are there, working in the background. There probably is no way to convert them to String or Integer variables. Thanks for the good lead, Cory. I understand Handle variables much better now. Alan Quote Link to comment Share on other sites More sharing options...
Cory Posted December 9, 2013 Report Share Posted December 9, 2013 I'm glad you now have a 'handle' on handles. And they are in constant flux. Quote Link to comment Share on other sites More sharing options...
acantor Posted December 11, 2013 Author Report Share Posted December 11, 2013 But now I see a problem. Without the ability to convert a handle variable to a string or integer variable, there is no way to check whether there are two windows or one. You cannot rely on window titles, as it's possible to open several windows with identical titles. Here is an example, partially in pseudo code... // Click somewhere.... Wait for Left Mouse Click // Get title and handle for the current window [1] Variable Set String %WindowTitle1% to topmost window title Variable Set Handle %WindowHandle1% from a window with the title, "%WindowTitle1%" // Click somewhere else... Wait for Left Mouse Click // Get title and handle for the current window [2] Variable Set String %WindowTitle2% to topmost window title Variable Set Handle %WindowHandle2% from a window with the title, "%WindowTitle2%" // Did the two clicks occur in the same window, or in different windows? // Note, pseudo code follows, because testing Handle variables, or converting them to strings or integers, is not (yet) supported... If %WindowHandle1% = %WindowHandle2% // Clicks were in the same window Else // Clicks were in two different window End If // Alternatively.... Convert %WindowHandle1% to Integer Variable %WindowHandle1Integer% Convert %WindowHandle2% to Integer Variable %WindowHandle2Integer% If %WindowHandle1Integer% Equals %WindowHandle2Integer% // Clicks were in the same window Else // Clicks were in two different window End If Quote Link to comment Share on other sites More sharing options...
Cory Posted December 12, 2013 Report Share Posted December 12, 2013 I'm not sure what your after but I'm pretty sure if you Repeat With Windows you will see very window title, even duplicates. That being the case it would be a simple matter to determine if two of the same title exist. In general it seems to me that in order to use handles one needs to help the macro out initially to determine which is which. Something like %WindowsSource% and %WindowDestination% if you were moving text from one to the other. Perhaps the user starts in one and it finds the other. In any case I think you need to do something to help the program understand which is which. Quote Link to comment Share on other sites More sharing options...
Look_Up Posted December 14, 2013 Report Share Posted December 14, 2013 Do you talking about window or a Tab ? Quote from the help (F1): Method to Set Handle(s) Window with a Specific Title Window with a Specific Title saves the name of a single window to a handle variable. If more than one running window contains the same Title, the first window found by Macro Express is saved to the variable. You can try to identify the window with "Get Control" / "Cature Control", and compare it with "if variable" %control1% equal %control2% then, else. But ME Pro is not very accurate to identify window title. Look_Up Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.