Open the VB6 and create a new Standard EXE program, delete the window, and then add a module.
Add the API declarations for AllocConsole, Freeconsole, Setconsoletitle, and sleep in the module:
Public Declare Function allocconsole Lib "Kernel32.dll" () as Long
Public Declare Function freeconsole Lib "Kernel32.dll" () as Long
Public Declare Function setconsoletitle Lib "kernel32.dll" Alias "Setconsoletitlea" (ByVal Lpconsoletitle as String) as Lo Ng
Public Declare Sub Sleep Lib "Kernel32.dll" (ByVal dwmilliseconds as Long)
Here's a look at these APIs:
AllocConsole:
Of course is to create a console window, no parameters, very simple an API, haha
Freeconsole:
This is used to destroy the console window just created, and of course there are no parameters
Setconsoletitle:
This is also very simple, is to set the console window title, parameter one is the title ha
Sleep:
This is no use, just let the program rest. In this example, it is used to pause for a moment to see the effect of creating a console
So, quite simply, enter the following code in Sub main:
Sub Main ()
Call AllocConsole
Call Setconsoletitle ("My Console")
Call Sleep (2000)
Call Freeconsole
End Sub
It's not ugly. This program is simple: first create a console window, then change the window title to My console, then rest for 2 seconds, and finally end the ha.
In this case, invoking the API function uses the call statement, which can be used directly as usual, but requires a variable to store the return value. If the calling API does not need to process the return value, you can save some space by using the call statement.
Well, this is a very simple example, of course, the difficult is still behind, the next tutorial will be gradual, in-depth exploration of VB6 console programming. Nevertheless, I recommend that you use VC + + to write Kazakhstan.
So, finally, the note to write a console program with VB6:
1, make sure that the API declaration is correct, otherwise the console will easily hang up
2, the console API is easy to hang up, so if you want to publish the console finished, you must remember to increase the return value of the judgment and fault tolerance section
3, test do not directly in the VB6 program test, should generate EXE and then open the test in the folder (this is very important, strictly abide by)
4, should be good habits: the common API, constants and so on all written in a module, other projects as long as the addition of the module on the line
VB6 How to create a standard console program