|
I have a need to access the properties of controls in a VB6 executable from VC++. I've tried various MFC/Windows calls to do this, and know the classnames of the windows that correspond to the controls, but haven't managed to find a procedure that works as of yet.
If anyone has a clue on how to do this, I'd appreciate suggestions... thanks.
Bob
|
|
|
|
|
This question is better off in the C++ forum. But are you trying to get at the controls of a VB app you've written, or something you don't have the source code to?
RageInTheMachine9532
|
|
|
|
|
RageInTheMachine9532 wrote:
This question is better off in the C++ forum. But are you trying to get at the controls of a VB app you've written, or something you don't have the source code to?
I can understand why you think this is more of a C++ question; the truth is, it is at its core a "VB internals" question, and with some info on that I might end up in the C++ forum or the ATL forum...
I'm trying to get at properties of objects within a VB executable, and though in my "pilot project" I have access to the source, I need to be able to do this in programs where I do not have source. The base question I have is where this info is stored and/or (more importantly) what structured access, if any, is provided to it.
I'm hoping that VB windows and controls are, from the MFC perspective, COM/ATL objects that are wrapped in CWindow objects, and that I can get an IUnknown interface pointer from them and from there explore whatever info they expose. I haven't found any info on how VB implements their objects from a C++/MFC perspective, though, so I'm speculating based on what I can deduce using Spy++ and other similar tools.
Any clues?
Thanks-
Bob
|
|
|
|
|
BobAshforth wrote:
I'm hoping that VB windows and controls are, from the MFC perspective, COM/ATL objects that are wrapped in CWindow objects,
I think your on the right track, but I remember seeing soemthing a few years back that said that with VB5 and 6, the standard controls all use vtable COM interfaces. I also remember seeing something about using IDispatch to get to an already running instance but I can't find the article anymore. I haven't found any examples of this on the web either.
From what I know about what your doing, you're in for ALOT of work if you have to use IDispatch to "generically" get to the controls. Either way, it's not going to be an easy to solve.
RageInTheMachine9532
|
|
|
|
|
|
If you are using Managed C++ to access VB.NET control it would definitely easier.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
... Great- now all I have to do is demand that the creators of the apps I need to interact with rewrite them in .NET, and I'll be all set! LOL...
Unfortunately, I need to do this with non-.NET apps, so my quest continues...
|
|
|
|
|
I am working on trying to get a specific part out of an array element and making a descision based on what number is presented. The number is 10 decimal digits long before conversion to hex. Once it is converted to hex the upper four numbers are the key to what get done next. How do you get the four upper bits out of a string and then determine what they are in a case statement? The following is what I have for the function so far
Function manipdata() As Integer
'Look at the 3rd and 4th values from each array and determine what type of data it is and display it
'to the user in some format.
Dim i As Integer = 1
Dim a As Boolean
Dim b As String
Do While i < icount
b = Hex(son(i).data)
a = b.StartsWith("1708")
If a = True Then
MessageBox.Show("You found a fwd one")
End If
'MessageBox.Show("You found an aft one")
'Case "0812"
' MessageBox.Show("Go home")
'end case
i = i + 1
Loop
End Function
Thanks and any help would be appreciated.
|
|
|
|
|
Your description seems be a little vague and the code sample doesn't make much sense either, but we'll try this. What I think your doing is looking at the first four hex characters, or 3rd and 4th characters only (?) and doing some processing base on what you find. I THINK(!) your looking for something like this: (This example will look at the 3rd and 4th characters only!: ie. 1708)
Dim i As Integer = 1
Dim b As String
Do While i < icount
' Grab the 3rd and 4th characters of the Hex code.
' This assumes that the Hex code is ALWAYS 4 digits long!
b = Hex(son(i).data).ToString().SubString(3, 2)
Select b
Case "08"
MessageBox.Show("You found a fwd one")
Case "12"
MessageBox.Show("Go Home")
Case Else
MessageBox.Show("Unknown code found: " & b)
End Select
Remember that Hex will NOT return a value padded with 0's on the left. An integer (15) converted to hex will return F, not 000F. So this method will NOT work in all cases. There may be a better method for making this determination, but it depends ENTIRELY on the data that you have in son().data.
RageInTheMachine9532
|
|
|
|
|
I have an vb.net 2003 application that is converting very large files that dies when the application loses focus. The application is updating several textboxes on screen that show the file names and record counts so I can see the progress. If I switch to another application while this is running, it dies. I am wondering if the fact that the application is attempting to update a screen that does not have focus is causing the problem. How do I get the code to continue execution and show me the current progress when focus is returned?
|
|
|
|
|
Umm...you don't. Losing the focus has absolutely no bearing on updating a text boxes or your applications windows in the way your describing.
What exactly does 'dies' mean? Does your app crash with a message box or does the entire thing just freeze?
Your app sounds like it's pretty much automated. If your in a loop for an extended period of time, do you give up control occasionaly with DoEvents() so Windows can handle other events in your app?
RageInTheMachine9532
|
|
|
|
|
Thanks for the reply.
When the application loses focus (e.g. I go to MS word or whatever) and then return to the application, the window is completely blank and an hourglass is displayed when the mouse is on any part of the window with the exception of the close button. I have broken the app into pieces and I am sure that the piece that is running should complete in a few minutes, but it never does.
Jim
|
|
|
|
|
OK. If your app never repaints (you get a white window for instance), you have to place Application.DoEvents() in you automation loop so your app can actually process the WM_PAINT messages that are being sent to your app and repaint the screen:
Dim Index as Integer
For Index = 0 to 10000
'.
'... Do some processing here...
'.
' Let our app respond to other messages here, like repaint our forms...
Application.DoEvents()
Next
RageInTheMachine9532
|
|
|
|
|
Thanks again. I will give that a try.
Jim
|
|
|
|
|
Language - Visual Basic.Net (home edition, or the non-proffessional at any rate)
Okay, I have a problem with three parts.
Part the first: I want to be able to save certain settings of a program to a text file. Now, I know how to create a text file and write to it, but I need to be able to read specific lines from it, and I'm not really sure how to do that.
Part the second: I need to find the bin folder (or whatever folder the program is running in) at runtime, so that I can figure out where the text file is.
Part the third: I need to know how to confirm whether or not that text file already exists.
Any help at all would be greatly appreciated. Thanks!
|
|
|
|
|
RandomGuy85 wrote:
Part the first: I want to be able to save certain settings of a program to a text file. Now, I know how to create a text file and write to it, but I need to be able to read specific lines from it, and I'm not really sure how to do that.
Pretty much the same way that you write to the file. First, how are you writing to the file? There are different classes and methods for File I/O and I'd like to match the technique with what your already doing. A sample of your code would help.
Part the second: I need to find the bin folder (or whatever folder the program is running in) at runtime, so that I can figure out where the text file is.
You can get the path to the executable from Application.StartupPath. The only problem with what you are doing is that every user that saves setting from your application will overwrite the previous users settings. A better choice would be to use the path stored in Application.UserAppDataPath.
Part the third: I need to know how to confirm whether or not that text file already exists.
Easy enough...You can use File.Exists(filepath) to see if the file exists or not.
This is a good excersize in reading/writing files...but there is another way to do application settings without them. SaveSetting and GetSetting will allow you to read and write settings to the registry without having to handle files at all.
RageInTheMachine9532
|
|
|
|
|
Using the registry is not the ".NET Way", for what it's worth. Also, I believe you need additional CAS permissions to do so that are not required when using isolated storage.
Charlie
Here I am. Love me.
|
|
|
|
|
Charlie Williams wrote:
Using the registry is not the ".NET Way", for what it's worth. Also, I believe you need additional CAS permissions to do so that are not required when using isolated storage.
The '.NET Way'?? Are you talking about XML config files?
The Save/GetSetting write their information to the CurrentUser Key of the registry. Unless the desktop load has been severely restricted, no out of the ordinary permissions are required by the code or user to use these functions.
RageInTheMachine9532
|
|
|
|
|
I simply meant that Microsoft recommends against using the registry when there are other options available. Certainly, there is nothing wrong with using the registry to store app information on a Windows machine, but if you intend to port your app to other platforms (not that it's realistic to do so now, but that's one of the stated goals of .net in the first place, right?) you'll have to come up with a different way of doing it.
GetSetting requires registry permissions. This isn't a problem with a locally installed app, but apps run over an intra/internet do not have this permission by default.
If neither of those two issues apply to a given situation, then register away.
Charlie
Here I am. Love me.
|
|
|
|
|
as topic, how to select the text in richtextbox and copy them to clipboard to be ready to paste in other document?
|
|
|
|
|
Are you selecting the text in code or is a user doing it?
If your doing it, use the Select method of the RichTextBox:
RichTextBox1.Select() ' selects everything in the RichTextBox
RichTextBox1.Select( start, length ) ' selects everthing starting at position 'start' for 'length' characters
After the selection is made all you have to do to get it on the Clipboard is this:
Clipboard.SetDataObject(RichTextBox1.SelectedRtf) or if you want just the text (without the formatting):
Clipboard.SetDataObject(RichTextBox1.SelectedText)
RageInTheMachine9532
|
|
|
|
|
thank you for replying me!! i tried out ur solution and it works!!
however the output actually is not my expectation..
for example, the text in my richtext box is like following:
hello!
how are u?
i am fine...
after i copy these 3 lines of texts into clipboard using
Clipboard.SetDataObject(RichTextBox1.SelectedText)
then paste it into notepad, the output is following:
hello!how are u?i am fine...
the 3 lines text become one line and all the text were combined?!
what i actually expect is the same format as in the multiline richtextbox...
can u figure out another solution for me??
i really appreciate ur help...
thank you very much!!
|
|
|
|
|
Easy! Replace every copy of ControlChars.Lf with ControlChars.CrLf before you set the DataObject on the Clipboard:
Dim strText As String
strText = RichTextBox1.SelectedText.Replace(ControlChars.Lf, ControlChars.CrLf)
Clipboard.SetDataObject(strText, True)
BTW: The 'True' in the SetDataObject just means that the data is to be left on the clipboard if your app quits.
RageInTheMachine9532
|
|
|
|
|
thanks man!! it works!!
by the way do u know how create a floating pop up menu when i right click in the richtextbox??
wat i actually wan to do is create a copy command in the popup menu when user selected the text and right click...
|
|
|
|
|
ClipBoard.Clear
ClipBoard.SetText rtfText1.SelRTF ,vbCFRTF
|
|
|
|