home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 10,704 of 10,840   
   Bill McCarthy to Don   
   Re: Get Control IDs more efficiently (1/   
   09 Dec 08 07:16:25   
   
   XPost: microsoft.public.vb.general.discussion, microsoft.public.vb   
   From: Bill@localhost.com   
      
   Hi Don,   
      
   Cool. Let us know if you have any more problems with it, but sounds like the   
   bits are coming together now.   
      
      
   "Don"  wrote in message   
   news:493d43f9.2360921@news.west.cox.net...   
   > Bill,   
   >   
   > For whatever reason, I didn't see all the text from your follow-up.  I   
   > just reread it, and I see you do have an alternative method for my   
   > grabbing up the text I need.  I'll give that try.  That sounds like   
   > the direction I should have taken from the beginning.  Most all the   
   > research I did on the net indicated that just knowing the handle was   
   > not enough to get the text I needed; that I needed both the handle and   
   > the ID of the control.   
   >   
   > I could certainly find the ID using a program such as WinSPY (I forget   
   > the name) or other such programs, but I need for my program to find   
   > the IDs on the fly as the user goes from one app to another and I may   
   > not even know what they are using.   
   >   
   > Only in a few cases do I think I still need to know the ID - for   
   > instance if I'm targeting a specific control on a specific window.   
   > But in those cases, I already know the ID.   But still, I'll give your   
   > code a try to see if even that's necessary any more.   
   >   
   > 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   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca