Solved

Win32 API (GetConsoleScreenBufferInfo)

Posted on 1998-03-26
3
1,268 Views
Last Modified: 2008-02-01
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
 
 
0
Comment
Question by:jvhew
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
abel earned 100 total points
ID: 1459866
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
 

Author Comment

by:jvhew
ID: 1459867
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
 
LVL 39

Expert Comment

by:abel
ID: 1459868
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now