CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    Join Date
    Sep 2002
    Posts
    924
    What other controls are you not able to get working? (different contol's respond to different messages. A message that works with 1 control, will not necessarily work for another. The same message may have a different meaning for different controls)

    I tried with a quick sample VB application I created to test with.
    I added 2 Labels, 2 TextBoxes, and a Button, and was able to get the text of all of the controls.

    BTW: To differentiate between 2 controls that are the same type, you need either the HWND of the control, the control's title (which may not be unique) or the control's Control ID. (You need something that is unique for that control, the HWND being the best candidate).

    Again HTML dialogs, or web browser controls (or similair type of controls) work differently. You would have to use COM/DOM , etc with these type of controls.

    If you are trying to build an application that will work (without modification) with all the different possible applications that the developers may build, that would be difficult as you would have to account for every type of control, and know what messages work with different types of controls, and try to figure out how to pull it all together.

    There are probably better ways to do whatever it is you are going to be doing in the long run. Maybe the developers could develop the programs so that the controls can be accessed externally (through VBScript or similair), etc.

  2. #17
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    Some details would help:

    What interface you have between the caller and the callee. Are you using some kind of dll ? It looks like you have 2 apps and one app is trying to get the text of controls in another app. What is not clear is what kind of inter process communication you use to pass stuff back and forth.

  3. #18
    Join Date
    Apr 2004
    Posts
    1
    How would you get the text for a label within a form that is not its own window but to which you know its control ID? I am looking for a code example. Say the hwnd to the form was "h_form" and the control id for the label was "1276"

  4. #19
    Join Date
    Sep 2002
    Posts
    924
    I assume you mean using VC++ code to get the text of a VB Label control.

    h_form would have to be the HWND of the form.
    The following code assumes the label control is a direct child of the form.
    PHP Code:
    // get handle of Label Control
    HWND hWnd = ::GetDlgItem(h_form1276);
    // Get the length of the label's text
    int Len = ::SendMessage(hWndWM_GETTEXTLENGTH00);
    // create variable to hold text (plus null terminator)
    TCHAR lpszText = new TCHAR[Len 1];
    // get the text
    ::SendMessage(hWndWM_GETTEXT, (WPARAM)Len+1, (LPARAM)lpszText);
    // text is in lpszText, do something with text...
    ::MessageBox(NULLlpszText"Message"MB_OK);
    // delete pointer
    delete [] lpszText
    Last edited by RussG1; April 7th, 2004 at 08:12 PM.

  5. #20
    Join Date
    Jul 2002
    Posts
    788
    Originally posted by RussG1
    What other controls are you not able to get working? (different contol's respond to different messages. A message that works with 1 control, will not necessarily work for another. The same message may have a different meaning for different controls)

    I tried with a quick sample VB application I created to test with.
    I added 2 Labels, 2 TextBoxes, and a Button, and was able to get the text of all of the controls.
    So far, from VB application,i can grab text for TextBox, ComboBox, Button.. from my VC++ application, across the process. All this i am using WM_GETTEXT to achieve the task.

    Now, VERY INTERESTING!! interesting part is, this is not enough. I really need to be able to grab text from ListBox, MSFlexControl (an add in components available both in VB and VC++). I believe this controls doesn't process the WM_GETTEXT message.

    So fro list box, i do the following, which works fine., i got back the text according to the index.

    Code:
    	
    ListBox_GetText(listboxHwnd, 1, Mybuffer);
    For ListView control, this doesn't work:-
    The reason simply because the address of structure lvi is interpreted differently across the process.
    Code:
    ListView_GetItem(listViewHwnd, &lvi);
    However, i can solve this problem by passing a pointer to a buffer that is relative to the remote process, initialize the pointer to the byte in the remotely allocated memory block using Read and Write ProcessMemory. This is a bit complicated, but that is ok, as long as i got what i want.

    Now, the problem is with other controls such as MSFlexGrid Control. I can get the handle for this control, but how can i send a message to this remote control to ask him to do the task as in listView control, such as GetText, GetRows, GetColumns etc etc, the rest of the operations can be seen if you add this components into yout VC++ project, it created the Class called CMSFlexGrid. If you can provide some sample codes to me on how to get around this problem, i really appreciate.. it may not be easy, but i am getting very desperate now. Come to that, MSFlexGrid is actually an activeX, but i just don know how i can make use of this feature to get what i want.. i need some working examples.. really.

    Originally posted by RussG1
    Again HTML dialogs, or web browser controls (or similair type of controls) work differently. You would have to use COM/DOM , etc with these type of controls.
    Does this apply to the MSFlexGrid? it is an activex control, but again, if so, really appreciate your working samples..

    Originally posted by RussG1
    If you are trying to build an application that will work (without modification) with all the different possible applications that the developers may build, that would be difficult as you would have to account for every type of control, and know what messages work with different types of controls, and try to figure out how to pull it all together.
    That is what i plan to do, however, for now, i just want to have those common controls, label, and some uncommon one such as MSFlexGrid.. listbox etc. then i would be very happy already.

    Originally posted by RussG1
    There are probably better ways to do whatever it is you are going to be doing in the long run. Maybe the developers could develop the programs so that the controls can be accessed externally (through VBScript or similair), etc.
    Well, i can't think of better way now, i have totally no control of the application source or the way it is being developed. All i want is to support existing application with those common controls and a couple of uncommon controls such as MSFlexGrid.
    Last edited by mce; April 7th, 2004 at 09:03 PM.

  6. #21
    Join Date
    Jul 2002
    Posts
    788
    Originally posted by RussG1
    I assume you mean using VC++ code to get the text of a VB Label control.

    h_form would have to be the HWND of the form.
    The following code assumes the label control is a direct child of the form.
    PHP Code:
    // get handle of Label Control
    HWND hWnd = ::GetDlgItem(h_form1276); 
    if i do not have the label ID, how? There is no windows handle in VB label.. it is not a windows class, is there a way out in this case??

  7. #22
    Join Date
    Sep 2002
    Posts
    924
    I do not know much about the MSFlexGrid control. I have never used it. I can't even try it out, because I get an error about not having a design time license for it (something must have messed up when I upgraded to .NET). I do not not what type of messages it handles.

    Try using Spy++ with Internet Explorer (click the find tool and drag it to a web page) so you can see what I mean abou the differences with a web browser control, etc.. The window that shows up in Spy++ will be class type "Internet Explorer_Server". You will notice that you do not see TextBoxes or any other elements that make up the web page. This is what I mean by html dialogs, or web browser controls (or similair). The content (i.e. textboxes within the web page) is html, thus they do not have window handles, etc, and will not show up it Spy++. You can access the data using Active Accessibility and the IHTMLDocument2 Interface , but it is more complicated.

    When you look at the MSFlexGrid control in Spy++ what does it look like? (do you see all of the controls that make up that control?)

    You can also use Spy++ to log all messages to window, so you might try doing that with the FlexGrid control to see some of the messages it handles, etc (if it is a regular window, and not like the "Internet Explorer_Server" window).

  8. #23
    Join Date
    Sep 2002
    Posts
    924
    Originally posted by mce
    if i do not have the label ID, how? There is no windows handle in VB label.. it is not a windows class, is there a way out in this case??
    What do you mean there is no windows handle?
    Look at it is Spy++, and you will see the handle of the label control.

    BTW: I noticed that with every VB control I looked at, the Handle and Control ID value was the same.

    If you know the handle of the parent window, and you know the caption of the label (and if the caption is unique within the app), you can use FindWindowEx, to get the handle of the control by it's caption.

    Also, note that you can use the GetWindowText API function to get the "Caption" of a control as well (this is not necessarly the same text you would get when sending the WM_GETTEXT message).

    *edit*
    BTW: The Class Name I get for the labels I used for testing is "WindowsForms10.STATIC.app1"
    Last edited by RussG1; April 7th, 2004 at 11:19 PM.

  9. #24
    Join Date
    Jul 2002
    Posts
    788
    when i check with spy++, it brought me to

    000204FC""MSFlexGridWndClass", there is no child class from it. so i suppose this is similar to web controls you said... how to "access this object" then... inside this control are actually columns and rows... i need to be able to "invoke methods" on this object, but i guess i can do it in a similar way like ListView where i would read and write process memory.

    So i think my concern is how to send message to this beast to ask him like to return information to me?? how to find out the messages it handles?? i may not need to access or invoke its methods directly from a windows handle from another process, but i should be able to send messsage to him(which is in another process) to perform some of the methods it exposes..... i need you help...

  10. #25
    Join Date
    Jul 2002
    Posts
    788
    Originally posted by RussG1
    What do you mean there is no windows handle?
    Look at it is Spy++, and you will see the handle of the label control.

    BTW: I noticed that with every VB control I looked at, the Handle and Control ID value was the same.

    *edit*
    BTW: The Class Name I get for the labels I used for testing is "WindowsForms10.STATIC.app1"
    well, i guess the problem is that you are using VB.net and i am using VB6.0... if you create a form in VB6, you can't find any windows handle for label... drag the Spy++ eye over the label, nothing happen.... and all other controls have different handle values. ................

  11. #26
    Join Date
    Sep 2002
    Posts
    924
    It is possible that you may by able to send messages to the MSFlexGridWndClass window to get the data you want. I do not know enough about that control to help much with that.

    If it has a COM interface that you may be able to access through COM as well (I do not know a lot about COM either. I have only played around with it a little, but have been able to grab text from TextBoxes on a webage, change properties of the page, etc). You would get an IDispatch Interface to the control, and then use QueryInterface to find out what it supports, and you can invoke methods using those interfaces, etc. Though it is not as easy as it sounds. You would have to read about COM, and find out what type of Interfaces and methods that the control exposes for you to access, etc.

    Again do not know enough about the FlexGrid control (or COM) to provide much help there...

  12. #27
    Join Date
    Sep 2002
    Posts
    924
    Originally posted by mce
    well, i guess the problem is that you are using VB.net and i am using VB6.0... if you create a form in VB6, you can't find any windows handle for label... drag the Spy++ eye over the label, nothing happen.... and all other controls have different handle values. ................
    Ahh, yeah that is probably it. It really did not use VB6 much (actually don't use VB much at all, since verison 4). Controls like that (if they are controls), probably can't be accessed directly through the Windows API, as there functionality is probably only in the VB Runtime libraries. Not sure how you would go about getting that text.

  13. #28
    Join Date
    Jul 2003
    Posts
    116
    originally posted by mce...
    Not sure how you would go about getting that text.

    i saw Mercury's WinRunner 5 not recognising that text either, its explicitely written in winrunner manuals that the text on VB applications cannot be recognised.

    At my time My requirements were such that i stopped workking on that issue and headed towards others but i donot know your requirements so you have to decide.
    I havent seen the latest version of Winrunner yet and i dont know whether it recognizes it or not...
    as for the flexgrid control i think you can emulate the mouse clicks and get the results, (learnt that from Winrunner !!!)
    if you have access to the interfaces or the messages used by that control then u can do that otherwise its a head scratcher.

    One more thing if that could help, tools like winrunner and rational robot do a bit of same thing as u r trying to do they clearly say that only standard window controls will be recognised and if u(company) have their own controls developed then they require the control specs and they ship a patch for that to recognise these inhouse controls, and for that they "cost". This also holds for ActiveX controls.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured