XPost: microsoft.public.vb.general.discussion, microsoft.public.vb   
   From: dsarvas@yahoo.com   
      
   Bill,   
      
   Sounds like I AM doing something wrong with GetDlgCtrlID(). I was   
   getting a return of a very high number - not 15 as you are getting   
   which does convince me you have the answer I'm looking for.   
      
   Regarding your question why I needed the ID, from all my searching of   
   Usenet groups and the web, I was under the impression the only way to   
   find the text from all the controls on all the windows, I would need   
   to use the GetDlgCtrlItem() function and that required finding the   
   control's ID. Now that you've replied that you found the ID via   
   GetDlgCtrlID(), that will be the answer I'm looking for. I would   
   still need the ID to find the text using GetDlgCtrlItem() (unless you   
   have a better idea), but now it looks like using GetDlgCtrlID() will   
   grab all those IDs without my having to loop through a huge range of   
   numbers to find the ID I need to get that text.   
      
   I'll look at GetDlgCtrlID() again as you suggest.   
      
   Thanks,   
      
   Don   
      
   On Mon, 8 Dec 2008 13:14:01 +1100, "Bill McCarthy"   
    wrote:   
      
   >Hi Don,   
   >   
   >I tested GetDlgCtrlID here with notepad and it returns 15. (&HF) So I'd   
   >suggest try looking at it again.   
   >   
   >I'm still not clear on why you need the ID's though as you can just get the   
   >dialogues child windows directly. For example, if you have Notepad's handle,   
   >then you can use FindWindowEx to loop through the child windows:   
   >   
   > Dim lastHandle As Long   
   > lastHandle = 0   
   > Do   
   > lastHandle = FindWindowEx(NotePadHandle, lastHandle, vbNullString,   
   >vbNullString)   
   > Debug.Print Hex$(lastHandle)   
   > Loop While lastHandle <> 0   
   >   
   >Control ID's I'd either expect you to know before handle to get the handle,   
   >and to possibly track window handle creation and releasing, but not to just   
   >get the text because you only need the handle to get the text.   
   >   
   >   
   >"Don" wrote in message   
   >news:493bfa78.9593625@news.west.cox.net...   
   >> The program I wrote monitors all windows running at a users   
   >> workstation, frequently testing those windows for text boxes, list   
   >> boxes, etc. for a specific string of characters that might contain   
   >> names of clients. Any number of programs might be run at the user's   
   >> workstation that might contain such info. If that string is found, my   
   >> program reacts by searching our own databases, documents, etc. for all   
   >> info pertaining to that client as an alert to the user of specific   
   >> procedures that must not be missed should they forget to check   
   >> themselves.   
   >>   
   >> It works, but using the windows handle for each window found by   
   >> enumerating through the windows using EnumWindowProc() and   
   >> EnumChildProc() I still need to loop through each of those windows to   
   >> find the ID of the text boxes, etc. using the following code which   
   >> will find the text I'm searching in the variable strWindowsText below:   
   >>   
   >> For lngCtrlId = 1 to 100   
   >> lngCtrlHWND = GetDlgItem(hWnd, lngCtrlId)   
   >> strWindowText = String(80, Chr(0))   
   >> SendMessage lngCtrlHWND, WM_GETTEXT, 100, ByVal strWindowText   
   >> Next lngCtrlId   
   >>   
   >> As an example, if you open Notepad and type "Test" in Notepad's edit   
   >> screen, my program will find the string "Text" since I already know   
   >> that the ID of Notepad's edit screen is 15. But if I didn't know the   
   >> ID is 15, I would need to loop through all possible values until I   
   >> reached 15 and my program would then find the text. But an ID can be   
   >> as high as the maximum number for the ID data type, and to run a loop   
   >> to such a high number for all windows running may cause enough of a   
   >> delay to be ineffective.   
   >>   
   >> I've already tried using GetDlgID() as you and others suggested, but   
   >> using the Notepad example, it doesn't seem to return a value of 15 as   
   >> the ID for the Notepad edit screen.   
   >>   
   >> I'm going on the assumption I'm missing something here so I still plan   
   >> to play around with these suggestions. Maybe I'm just not using these   
   >> functions properly or perhaps the method I've been using is the only   
   >> way?   
   >>   
   >> Ideally, I would like to get a list of all control IDs from all   
   >> windows and then use the ID and the hwnd values to grab the text from   
   >> each using SendMessage.   
   >>   
   >> Don   
   >> On Sun, 7 Dec 2008 14:14:33 +1100, "Bill McCarthy"   
   >> wrote:   
   >>   
   >>>Hi Don,   
   >>>   
   >>>As others have said, use GetDlgCtrlID :   
   >>>   
   >>>Public Declare Function GetDlgCtrlID Lib "user32" Alias "GetDlgCtrlID"   
   >>>(ByVal hwnd As Long) As Long   
   >>>   
   >>>Loop through the child windows, get the hwnd then call GetDlgCtrlID using   
   >>>the control's hwnd.   
   >>>   
   >>>Just out of curiosity, why do you want the control ID's ?   
   >>>   
   >>>   
   >>>"Don" wrote in message   
   >>>news:493a9d6d.2039234@news.west.cox.net...   
   >>>> Thanks. That's what I've been doing all along to get all windows,   
   >>>> child windows and so on as deeply nested as necessary. But to get the   
   >>>> IDs of all the text boxes, etc. on each window required that I run a   
   >>>> loop to test all possible ID numbers in existence. Looks like the way   
   >>>> I've been doing it is the best I can hope for, then. Unfortunately,   
   >>>> if I use a loop of 0 to 100, for instance, I won't find an control ID   
   >>>> with a very high number. If I run a loop with a very high limit then   
   >>>> it may take longer than I want . . . but works.   
   >>>>   
   >>>> Don   
   >>>>   
   >>>> On Sat, 6 Dec 2008 16:21:42 +1100, "Bill McCarthy"   
   >>>> wrote:   
   >>>>   
   >>>>>Hi Don,   
   >>>>>   
   >>>>>You use those same functions to recurse children of children. You won't   
   >>>>>get   
   >>>>>all controls, such as labels; only those that have windows.   
   >>>>>   
   >>>>>   
   >>>>>"Don" wrote in message   
   >>>>>news:49394812.3110859@news.west.cox.net...   
   >>>>>> Regarding the two suggestions offered so far, I see I wasn't clear in   
   >>>>>> my original post..   
   >>>>>>   
   >>>>>> I'm using EnumWindows and EnumChildWindows to get all the window   
   >>>>>> handles and their IDs which works fine. But it's all the controls   
   >>>>>> inside each window for which I need their IDs (text boxes, command   
   >>>>>> buttons, etc.). Creating a loop to test all possible ID numbers does   
   >>>>>> work, but it would be much better if there an equivalent of the   
   >>>>>> EnumWindows function that also enumerates all the control IDs inside   
   >>>>>> the window.   
   >>>>>>   
   >>>>>> Don   
   >>>>>>   
   >>>>>> On Thu, 04 Dec 2008 21:07:40 GMT, dsarvas@yahoo.com (Don) wrote:   
   >>>>>>   
   >>>>>>>I'm using the GetDlgItem function to get the text from a specific   
   >>>>>>>control in external apps. Works fine, but if I don't know the control   
   >>>>>>>ID, I create a loop (e.g. 0 to 100) to test all the control IDs in   
   >>>>>>>that range to find the control. Problem is that a control can have a   
   >>>>>>>very large number as the ID and I enumerate through all windows and   
   >>>>>>>their child windows so that can create a little more delay than I want   
   >>>>>>>and I would never be sure my loop is a range that covers the highest   
   >>>>>>>control ID number.   
   >>>>>>>   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|