If I know the main window to be of class TBoardWindow (thats what Spy++ says), can I do this then:
// I have the app process ID as dwMyProcess;
HWND hWnd = NULL;
DWORD dwProcess = NULL;
do {
hWnd = FindWindowEx(NULL, hWnd, _T("TBoardWindow"), NULL);
if (!hWnd) break;
dwProcess = GetWindowThreadProcessId(h
if (dwProcess == dwMyProcess) break;
else dwProcess=NULL;
} while(true);
To find my window instead of using EnumWindows?
And then I will use the same way to locate the TStringGrid instance. The thing I have no idea how to achieve is how to get the data from the first entry of the TStringGrid control. What API function I have for that? Also, if it is within a tab control and not visible at the moment, would it make any difference when I come to read its data?
Stilgar.
Main Topics
Browse All Topics





by: NickGeorghiouPosted on 2007-11-02 at 06:02:26ID: 20200405
Hi,
/en-us/lib rary/ms682 425.aspx for ::CreateProcess /en-us/lib rary/ms684 873.aspx for PROCESS_INFORMATION structure
/en-us/lib rary/ms633 497.aspx for EnumWindows /en-us/lib rary/ms633 498.aspx for EnumWindowsProc /en-us/lib rary/ms633 522.aspx for GetWindowThreadProcessId
/en-us/lib rary/ms633 500.aspx for FindWindowEx
Ok, there are few steps you need to do:
1. If you are using the ::CreateProcess api to run the process then you can get the process id from the PROCESS_INFORMATION structure (dwProcessId member).
- refer to http://msdn2.microsoft.com
- refer to http://msdn2.microsoft.com
2. The next step is to enumerate all top-level windows using the ::EnumWindows and an EnumWindowsProc. You must write your own EnumWindowsProc and then pass a pointer to EnumWindows. Your EnumWindowsProc will be called multiple times; each time the handle to a top-level window will be passed in the callback. At this point you can use the GetWindowThreadProcessId api to check whether the process id of a particular top-level window matches the process id of the process you kicked off. If it does then store the handle because this is the processes main window. (Although note that some applications may have multiple top-level windows in which case you will get more than one match).
- refer to http://msdn2.microsoft.com
- refer to http://msdn2.microsoft.com
- refer to http://msdn2.microsoft.com
3. Once you have your top level window(s) you can use the FindWindowEx to attempt to findow a window of the TStringGrid class.
- refer to http://msdn2.microsoft.com
NOTE: If you know the name of the main window of the process you can skip points 1 and 2 and use FindWindowEx to first retrieve a handle to the main window by setting the first parameter to null and passing the name as the 4th parameter.
Hope this helps,
Nick