|
use console output option;
#include <windows.h>
void NewLine(void);
void ScrollScreenBuffer(HANDLE, INT);
HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
void main(void)
{
LPSTR lpszPrompt1 = "Type something and press Enter:\n";
LPSTR lpszPrompt2 = "Type any key: ";
CHAR chBuffer[256];
DWORD cRead, cWritten, fdwMode, fdwOldMode;
WORD wOldColorAttrs;
// Get handles to STDIN and STDOUT.
hStdin = GetStdHandle(STD_INPUT_HANDLE);
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE ||
hStdout == INVALID_HANDLE_VALUE)
{
MyErrorExit("GetStdHandle");
}
// Save the current text colors.
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
MyErrorExit("GetConsoleScreenBufferInfo");
wOldColorAttrs = csbiInfo.wAttributes;
// Set the text attr. to draw red text on black background.
if (! SetConsoleTextAttribute(hStdout, FOREGROUND_RED))
MyErrorExit("SetConsoleTextAttribute");
// Write to STDOUT and read from STDIN by using the default
// modes. Input is echoed automatically, and ReadFile
// does not return until a carriage return is typed.
//
// The default input modes are line, processed, and echo.
// The default output modes are processed and wrap at EOL.
while (1)
{
if (! WriteFile(
hStdout, // output handle
lpszPrompt1, // prompt string
lstrlen(lpszPrompt1), // string length
&cWritten, // bytes written
NULL) ) // not overlapped
break;
if (! ReadFile(
hStdin, // input handle
chBuffer, // buffer to read into
255, // size of buffer
&cRead, // actual bytes read
NULL) ) // not overlapped
break;
if (chBuffer[0] == 'q') break;
}
// Turn off the line input mode, and echo the input mode.
if (! GetConsoleMode(hStdin, &fdwOldMode))
MyErrorExit("GetConsoleMode");
fdwMode = fdwOldMode &
~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
if (! SetConsoleMode(hStdin, fdwMode))
MyErrorExit("SetConsoleMode");
// Prompt for input.
if (! WriteFile(
hStdout, // output handle
lpszPrompt2, // prompt string
lstrlen(lpszPrompt2), // string length
&cWritten, // bytes written
NULL) ) // not overlapped
MyErrorExit("WriteFile");
// Without line and echo input modes, ReadFile returns
// when any input is available. Carriage returns must
// be handled, and WriteFile is used to echo input.
while (1)
{
if (! ReadFile(hStdin, chBuffer, 1, &cRead, NULL))
break;
if (chBuffer[0] == '\r')
NewLine();
else if (! WriteFile(hStdout, chBuffer, cRead,
&cWritten, NULL)) break;
if (chBuffer[0] == 'q') break;
}
// Restore the original console mode.
if (! SetConsoleMode(hStdin, fdwOldMode))
MyErrorExit("SetConsoleMode");
// Restore the original text colors.
if (! SetConsoleTextAttribute(hStdout, wOldColorAttrs))
MyErrorExit("SetConsoleTextAttribute");
}
// The NewLine function handles carriage returns when the processed
// input mode is disabled. It gets the current cursor position
// and resets it to the first cell of the next row.
void NewLine(void)
{
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
MyErrorExit("GetConsoleScreenBufferInfo");
csbiInfo.dwCursorPosition.X = 0;
// If it is the last line in the screen buffer, scroll
// the buffer up.
if ((csbiInfo.dwSize.Y-1) == csbiInfo.dwCursorPosition.Y)
{
ScrollScreenBuffer(hStdout, 1);
}
// Otherwise, advance the cursor to the next line.
else csbiInfo.dwCursorPosition.Y += 1;
if (! SetConsoleCursorPosition(hStdout,
csbiInfo.dwCursorPosition))
{
MyErrorExit("SetConsoleCursorPosition");
}
}
|
|
|
|
|
stupid question here?
where would I start to get an editbox receiving strings one line at a time to display the last line. example
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7
right now line 6 and 7 are out of view in the editbox, but I want the editbox to show 6 and 7, and hide 1 and 2. In other words just auto display the last messages sent to the editbox.
thanks, JoeSox
dev in VC++ 6.0
|
|
|
|
|
Did you try out CEdit::LineScroll(...)?
from msdn:
void LineScroll(int nLines, int nChars = 0);<br />
<br />
Parameters:<br />
nLines <br />
Specifies the number of lines to scroll vertically. <br />
nChars<br />
<br />
Specifies the number of character positions to scroll horizontally. This value is ignored if the edit control has either the ES_RIGHT or ES_CENTER style.
Weiye, Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
thanks, I've decided to use this.
Later, JoeSox www.humanaiproject.org
"Dream as if you'll live forever; live as if you'll die tomorrow."
- James Dean(ISTP)
|
|
|
|
|
just use WM_VSCROLL like this:
::SendMessage(WM_VSCROLL,hWnd,SB_BOTTOM,0);
the hWnd is the handle of edit box;
good luck!
|
|
|
|
|
thanks
Later, JoeSox www.humanaiproject.org
"Dream as if you'll live forever; live as if you'll die tomorrow."
- James Dean(ISTP)
|
|
|
|
|
Recently I meet a problem, that is:
How can a ropertySheet instance be added to a CPropertySheet as a CPropertyPage?
Who can tell me this promblem and its realization?
|
|
|
|
|
|
Yeah, that is the point!
It is so perfect!
Thank you very much!
LeonOrient
|
|
|
|
|
for program to ras monitoring
end term create is 15.06.2003
more info: balu2@o2.pl
|
|
|
|
|
Hi,
Did any one know how to get a message in Visual C++ when a smart card was inserted or removed ?
Thanks Very much
|
|
|
|
|
I don't know the answer but asking the questions 3 times in two days isn't going to help you get an answer.
Why don't you just read all of the messages posted on this board for the last two weeks? I do that all the time and I seem to recall someone asking a question about how to detect new hardware inserted and registering your application for notification from the operating system.
As a last resort, do a search. Though, I know that can be hard getting the right keywords.
|
|
|
|
|
How to view in messagebox
sample file: http://dziennik.naczasie.pl/testfile.txt
if I try messagebox return only """
|
|
|
|
|
Load file contents to the string (CString or simply char* ), then display it. Consider scrollable edit box or some decent UI instead of a MessageBox , unless the file is always small and formatted in a way that MessageBox can handle.
Regards,
BB
|
|
|
|
|
hello,
I just recently got visual studio given to me. I am very interested in programming and I would be very appreciative if someone could point me in the right direction. I know nothing about C++ or any other computer language for that matter. Please help me.
My AIM screen name(s) are: Orch1d 7, FiveInchesOfFury
Thank you
|
|
|
|
|
download a c++ book (from any University for free), read line by line, try line by line.
then come back to post second question.
includeh10
|
|
|
|
|
I'd strongly recommend Beginning Visual C++ 6 by Ivor Horton. It starts off with a pretty good introduction to the C++ language, and it has some very nice examples for you to try. The God-forsaken painting program the author focuses on throughout the book is a little frustrating (unless the sole reason you bought Visual C++ was to write a simple painting program), but it covers most major topics pretty well. I'd also recommend buying the physical book. I really hate reading books from PDFs, but maybe that's just me.
Also be sure to check online for examples. If you have a problem to solve, there is almost certainly at least a partial solution somewhere online.
As for Visual Studio .NET (you didn't say which version you got for free), I don't own any books on it, so I can't really comment on any of them.
Good luck and asincludeh10 said, do post more questions
William Brendel
|
|
|
|
|
hello
i have a a DIALOGBAR when i make some control(button ,slider,..)
and i want to make in the menu bar a shortcut to this Button ,in one menu?
can u help in this ?
|
|
|
|
|
did u try to add a menu item with same ID of the button?
includeh10
|
|
|
|
|
|
add few message handlers in some suspected windows (i.e. main-frame) to see where the message is sent.
it must be somewhere, then transfer it from the window to required place.
includeh10
|
|
|
|
|
sorry,but can u explain more .
how i can handel meassage and which message??
|
|
|
|
|
i.e. the button ID is ID_TEST, add a menu item as ID_TEST.
in main-frame, wait for the message (messge=WM_COMMAND, wParam=ID_TEST).
"wait" means u put a messagebox there then click the menu to see if the message is processed to the window.
includeh10
|
|
|
|
|
ok,i will try it.
thank you
|
|
|
|
|
I have an unusual task: slow down process in Windows(I have only executable(s) of this process.
If there's no way to slow down stand-alone process, I could slow down oll system. What is the better way to do it? Is it effective to make infinite loop process with real time priority.
|
|
|
|
|