Win32 API (GetConsoleScreenBufferInfo)

I had been told by my friend (hellome) to send this question because he is not enough point.

Regarding to the use of the win32 api (GetConsoleScreenBufferInfo), Abel (the expert from expert-exchange) had give the comment as below :

(Unless you make the console yourself, you cannot use this function. If you want that information from another application and you can't get the hConsoleInput, you'll have to do some seriously difficult tricks (especially when doing that from VB). At the other hand, when you create the console yourself, it's very handy information, as clifABB points out, for copying the screencontents of the DOS-window somehow. If this is what you want, I can provide you an example for using it.)

What hellome actually want is, to get the screen contents of the Dos Window but not the screen properties of the Dos Window. For example: compiling the java file(App.java) by using the javac.exe.
This can be done in VB5 by just calling the shell function. However, if any compilation error, the error messages will display in the Dos Window and this window will disappear immediately after the compilation. So, in order to get the error messages from Dos Window, he had tried several methods including this :

  shell "c:\jdk1.1.1\bin\javac App.java >c:\tmp.txt"
  and also
 shell"command.com /cc:\jdk1.1.1\bin\javac App.java >c:\tmp.txt"    
Unfortunately, both also unable to get the output error messages from Dos Window. (tmp.txt file is empty).

So, if the win API (GetConsoleScreenBufferInfo) can get the output of the Dos Window then can Abel give the example how to use it.
Or may be someone know the solution, please help me. Thank you.

my email : jvhew@hotmail.com
 
 
jvhewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelCommented:
If it would be enough when the console window doesn't appear at once, then you might just try another trick, since getting the contents another way can get difficult.
For example, try this:

Create a .BAT file with the command you use and put on the next line the command "PAUSE" this will pause the execution and prevent the console window to disappear immediately. In stead of calling javac, you just call the BAT file.

Or try this:
Call a command prompt and send the keystrokes to it that start the java compiler (you can do this in VB using the SendKeys function). Then End the session sending the keys "EXIT" to the command prompt.

In either case, the solution to get what you want is much easier then trying to get the screenbuffer or otherwise copy the console window's contents.

I hope this helps enough. If not, just comment and I'll try to help you out.

BTW Windows is not very eager about giving you information about what's happening in console windows, so as long as you can do it with workarounds, I think that's the best solution.

Regards, Abel
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jvhewAuthor Commented:
Hello Abel, I had tried the sendkeys function in vb5. I create two command button, one is for compilation another is for closing the Dos Window after compiled.
So, I wrote the code as bellow:

dim x   'general declaration
Sub Command1_Click()

   x = shell("command.com",1)
   AppActivate x
   sendkeys "javac App.java{ENTER}", True
   
End sub  

Sub Command2_Click()

    AppActivate x
    sendkeys "EXIT{ENTER}", True

End sub

But it can't work. What I meant is that, When I press Command1 button or Command2 button, the Dos Window was displayed and showed liked this :

c:\jdk1.1.1\bin>  \
                            \
                            \
                            \

Even I try to send character A [ sendkeys "A", True ], it's also give me [ \ ] simbol. I really do not know how to solve it. Please help.

Questions: - If there has a space, how should I write in sendkeys function?
                      example : sendkeys "javac App.java"  or  "javac{SPACE}App.java"
                    - How about the dot (.)?                                                              
                                                             

I really need to know the solution code and hope Abel can show me the code. Thank you                              
0
abelCommented:
I've had this problem before and also made a workaround for it using the windows API, but at the moment I can't find the project ro reference I used for it. (I tried your code on NT and then it works fine, but on 95 you get this strange behaviour...)
But what about the other solution? Making a .BAT file is much easier and can be run with one single command under your command1 button, like:

Shell "command.com /cc:\javacmpl.bat", vbNormalFocus

where javacmpl.bat looks like:

javac.exe app.java
pause

And it's very easy to make that batch file at runtime, or you can use a commandline parameter like:

Shell "command.com /cc:\javacmpl.bat app.java", vbNormalFocus

and in the .BAT it'll look like:

javac.exe %1
pause

Isn't that much easier then doing it cumbersome with the SendKeys (or Post/SendMessage api's with WM_KEYDOWN and WM_KEYUP and all the virtual key scan codes and so on?)

Let me know if this workaround works for you, or if you need more info.

Regards, Abel
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.