Link to home
Start Free TrialLog in
Avatar of jvhew
jvhew

asked on

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
 
 
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jvhew
jvhew

ASKER

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                              
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