Hey,
I was trying to automate a program (AVI ReComp) using FindWindow and SendMessage. All is working just fine till I got to my next problem:
When I'm starting this application: AVI ReComp I only see 2 out of 5 tabs I'm supposed to see using the spy++ tool but when I actually look at the program I see all 5 tabs.
Weird?
Wait it gets even weirder...
When I click on the tab that's not been showing in spy++, when I refresh the windows in spy++ tool it suddenly appears with all its controls.
Also, the same thing happens when I'm trying to get the handle for that same tab.
If I put a breakpoint after the program is loaded but before the handle is created and click on the tab before I continue, the handle works fine and gets all the correct values.
BUT, if I don't the handle is empty.
What could be the problem?
PS. When I try to wait before I try to retrieve the handle for the other tab, it still doesn't change anything so I think that prevents the possibility that it has to do something with the loading of that element.
Loading
Sam HobbsPosted Oct 2, 2011, 4:03 PM
You are sure getting good with Spy++. It can sure help with things like this. It is good that you have learned how to monitor messages too. I enjoy helping people that are good at figuring things out such as you are.
Imri BarrPosted Oct 2, 2011, 2:57 PM
The issue contained 2 problems:
1. Each tab was created only when a click event occurred on it.
2. There was no way to switch between the tabs using the regular methods of TCM_SETCURSEL and such.
The answer to both questions is to generate a click event for each tab you want to use during the program. The click must happen from the tab container (The empty window which has the sys32tabcontrol class) and you must supply the right control coordinates (this can be retrieved from spy++ WM_LBUTTONUP/WM_LBUTTONDOWN events). Finally, use the MakeLParam function to combine the x and y coordinates of the click and insert them as parameters to SendMessage function.
Here's the code to generate these clicks:
//Force creation of Additions Tab
SendMessage(hwnd_tabContainer, WM_LBUTTONDOWN, 0, (IntPtr)MakeParam(120, 10));
SendMessage(hwnd_tabContainer, WM_LBUTTONUP, 0, (IntPtr)MakeParam(120, 10));
//Force creation of Settings Tab
SendMessage(hwnd_tabContainer, WM_LBUTTONDOWN, 0, (IntPtr)MakeParam(210, 10));
SendMessage(hwnd_tabContainer, WM_LBUTTONUP, 0, (IntPtr)MakeParam(210, 10));
//Force creation of Queue Tab
SendMessage(hwnd_tabContainer, WM_LBUTTONDOWN, 0, (IntPtr)MakeParam(270, 10));
SendMessage(hwnd_tabContainer, WM_LBUTTONUP, 0, (IntPtr)MakeParam(270, 10));
VulpesPosted Oct 1, 2011, 5:16 PM
You can do this either using the managed SendKeys.Send or SendWait methods (http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx) or its unmanaged equivalents keybd_event (http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304(v=vs.85).aspx) or SendInput (http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx).
Imri BarrPosted Oct 1, 2011, 2:53 PM
The problem is not only that, I simply can't switch between the tabs no matter what I try. Even when I manage to get the handle correctly after I click on it manually and then run the program it still doesn't switch between the tabs.
The program is AVI ReComp, if you want to help you could try to download this program and just try to switch between the tabs.
Thanks for the help!
VulpesPosted Oct 1, 2011, 8:56 AM