Originally posted by: pegas
i know console api.
i wanna execute the ConsoleApp and send the data.
flow chart is below..
main program is windows application.
in main program, createprocess ConsoleApp(exe)
then, i wanna control the consoleapp in main program.
But i cant get the handle of ConsoleApp..
How Method can i...
Originally posted by: MTJ
The code below was the code I used:
Public Type COORD
Public Type SMALL_RECT
Public Type CONSOLE_SCREEN_BUFFER_INFO
Public Declare Function GetStdHandle Lib "kernel32" Alias "GetStdHandle" _
Private Declare Function WriteFile Lib "kernel32" Alias "WriteFile" _
Private Declare Function ReadFile Lib "kernel32" Alias "ReadFile" _
Public Declare Function GetConsoleScreenBufferInfo Lib "kernel32" _
Public Declare Function SetConsoleCursorPosition Lib "kernel32" _
Public Declare Function FillConsoleOutputCharacter Lib "kernel32" _
Public Declare Function FillConsoleOutputAttribute Lib "kernel32" _
Public Const STD_OUTPUT_HANDLE = -11&
Public Sub clrscr()
Dim coordScreen As COORD
Call GetConsoleScreenBufferInfo(hConsole, csbi)
'
Dim point As COORD
End Sub
I'm using Visual Basic 5.0, I'm trying to write a console
application in it. I translated the VC++ code into Visual
Basic format, added "Types" and API Declarations and then
compiled and changed the App mode to Console User
Interface. Text printing was all right, text inputing
worked, but gotoxy() and clrscr() didn't work! What can I
do now?
x As Integer
y As Integer
End Type
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
dwSize As COORD
dwCursorPosition As COORD
wAttributes As Integer
srWindow As SMALL_RECT
dwMaximumWindowSize As COORD
End Type
(ByVal nStdHandle As Long) As Long
(ByVal hFile As Long, ByVal lpBuffer As Any, _
ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, _
ByVal lpOverlapped As Any) As Long
(ByVal hFile As Long, ByVal lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Any) As Long
(ByVal hConsoleOutput As Long, _
lpConsoleScreenBufferInfo As CONSOLE_SCREEN_BUFFER_INFO) As Long
(ByVal hConsoleOutput As Long, _
dwCursorPosition As COORD) As Long
Alias "FillConsoleOutputCharacterA" _
(ByVal hConsoleOutput As Long, _
ByVal cCharacter As Byte, _
ByVal nLength As Long, _
dwWriteCoord As COORD, _
lpNumberOfCharsWritten As Long) As Long
(ByVal hConsoleOutput As Long, _
ByVal wAttribute As Long, _
ByVal nLength As Long, _
dwWriteCoord As COORD, _
lpNumberOfAttrsWritten As Long) As Long
Public Const STD_INPUT_HANDLE = -10&
coordScreen.x = 0: coordScreen.y = 0
Dim cCharsWritten As Long
Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
Dim dwConSize As Long
Dim hConsole As Long: hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
dwConSize = csbi.dwSize.x * csbi.dwSize.y
Call FillConsoleOutputCharacter(hConsole, CByte(Asc(" ")), dwConSize, coordScreen, cCharsWritten)
Call GetConsoleScreenBufferInfo(hConsole, csbi)
Call FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, cCharsWritten)
Call SetConsoleCursorPosition(hConsole, coordScreen)
End Sub
' Moves the cursor to x, y in console window
' ie x=left\right y=top\bottom
'
Public Sub gotoxy(ByVal x As Integer, ByVal y As Integer)
point.x = x: point.y = y
Call SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point)
Originally posted by: Alon Weiss
void SetScrnSize(int W, int H)
SetConsoleWindowInfo(
COORD Sz;
SetConsoleScreenBufferSize(
you can call it with 80,25 and it works!
SetScrnSize(80,25);
hope it will help someone..
I wanted my app to resemble to an old 80x25 DOS program.
Here is how i did it:
{
SMALL_RECT SR;
SR.Top = 0;
SR.Left = 0;
SR.Bottom = H-1;
SR.Right = W-1;
GetStdHandle(STD_OUTPUT_HANDLE),
TRUE,
&SR);
Sz.X = W;
Sz.Y = H;
GetStdHandle(STD_OUTPUT_HANDLE),
Sz
);
in console.cpp example, add these lines after the clrscr() call:
for (i=0; i<8;i++)
{
for (int j=0;j<9;j++)
cout<<"-";
cout<<"|";
}
for (i=2;i<=25;i++)
{
cout <<i;
if (i<25) cout <<endl;
};
Alon Weiss.
Originally posted by: blue-bon
i had try the code n it's work...thx
but somthing bothering me that i dont know what does its statement mean. esp. -SetConsoleTextAtribute-. any one can help me to find out the description for this syntax....
thx
Originally posted by: Wes Baldwin
#include "stdafx.h"
const unsigned char horiz_line = '�';
using namespace std;
void draw_hLine(int length, int x = 0, int y = 0);
int main(int argc, char* argv[])
draw_Rect(1, 1, 15, 75);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
void set_Cursor(int x, int y) //contributed by Roger McElfresh
if(x > 0 || y > 0)
for(i = 0; i < length; i++)
void draw_vLine(int length, int x, int y)
if(x > 0 || y > 0)
for(i = 0; i < length; i++)
void draw_Rect(int x, int y, int l, int w)
// drawing.cpp : A simple set of drawing functions by Wes Baldwin
//Code date 09.01.03
#include <iostream>
#include <windows.h>
const unsigned char vert_line = '�';
const unsigned char ul_corner = '�';
const unsigned char ur_corner = '�';
const unsigned char ll_corner = '�';
const unsigned char lr_corner = '�';
void draw_vLine(int length, int x = 0, int y = 0);
void draw_Rect(int x, int y, int l, int w);
void set_Cursor(int x, int y);
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY |
FOREGROUND_RED); //contributed by Roger McElfresh
draw_Rect(2, 2, 15, 75);
set_Cursor(15,9);
cout << "Line and Rectangle Drawing Code by: Wes Baldwin";
FOREGROUND_INTENSITY |
FOREGROUND_RED |
FOREGROUND_GREEN |
FOREGROUND_BLUE); //contributed by Roger McElfresh
return 0;
}
{
COORD point;
point.X = x; point.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
return;
}
void draw_hLine(int length, int x, int y)
{
int i = 0;
set_Cursor(x, y);
{
cout << horiz_line;
}
return;
}
{
int i = 0;
set_Cursor(x, y);
{
set_Cursor(x, y + i);
cout << vert_line;
}
return;
}
{
set_Cursor(x, y);
cout << ul_corner;
draw_hLine(w - 2);
cout << ur_corner;
set_Cursor(x, y + 1);
draw_vLine(l - 2, x, y + 1);
set_Cursor(x, y + (l - 1));
cout << ll_corner;
draw_hLine(w - 2, x + 1, y + (l - 1));
cout << lr_corner;
draw_vLine(l - 2, x + w - 1, y + 1);
return;
}
Originally posted by: Adam
What's the most straighforward way to size the console window programmatically so the code determines the console size when the program is launched.
ReplyOriginally posted by: Lord of the Things
How can i get back that fine DOS-Gray after using these funcs?
(Cause your default isn't exactly the same)
Originally posted by: Retief
I just poped in your function for font color into my program..added the windows.h and pow! works great
thanks a lot
ReplyOriginally posted by: SGL
I would like to minimize (at least) my console app, but don't see a function which allows this. Any ideas?
Thanks,
Steve
Originally posted by: Dan
A friend and I are sitting here in class and he wanted to use your color thing to create a line of characters in his program that flickers different colors. The problem is, whatever was the last color he chose, the compiler made the entire thing that color. We found though that this problem is solved - so far as we can tell - by using 'printf' instead of 'cout'. I am posting here to let any other VC++ 5.0 users know this, but also to see if anyone has an answer as to why the compiler did this.
Reply