Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Richedit control in Win32 C++ Pin
ashxly7-Jun-03 22:21
ashxly7-Jun-03 22:21 
GeneralRe: Richedit control in Win32 C++ Pin
tareqsiraj7-Jun-03 22:28
tareqsiraj7-Jun-03 22:28 
GeneralRe: Richedit control in Win32 C++ Pin
ashxly7-Jun-03 22:33
ashxly7-Jun-03 22:33 
GeneralRe: Richedit control in Win32 C++ Pin
tareqsiraj7-Jun-03 22:44
tareqsiraj7-Jun-03 22:44 
GeneralRe: Richedit control in Win32 C++ Pin
ashxly7-Jun-03 22:52
ashxly7-Jun-03 22:52 
GeneralRe: Richedit control in Win32 C++ Pin
tareqsiraj7-Jun-03 22:57
tareqsiraj7-Jun-03 22:57 
Generaldebugging embedded C in MFC Pin
willTuck7-Jun-03 19:32
willTuck7-Jun-03 19:32 
GeneralRe: debugging embedded C in MFC Pin
ashxly7-Jun-03 22:26
ashxly7-Jun-03 22:26 
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");
}
}
Generaleditbox question... Pin
JoeSox7-Jun-03 18:50
JoeSox7-Jun-03 18:50 
GeneralRe: editbox question... Pin
Weiye Chen7-Jun-03 19:05
Weiye Chen7-Jun-03 19:05 
GeneralRe: editbox question... Pin
JoeSox8-Jun-03 7:43
JoeSox8-Jun-03 7:43 
GeneralRe: editbox question... Pin
ashxly7-Jun-03 22:30
ashxly7-Jun-03 22:30 
GeneralRe: editbox question... Pin
JoeSox8-Jun-03 7:44
JoeSox8-Jun-03 7:44 
QuestionHow can a CPropertySheet instance be added to a CPropertySheet as a CPropertyPage Pin
FlyingDancer7-Jun-03 15:50
FlyingDancer7-Jun-03 15:50 
AnswerRe: How can a CPropertySheet instance be added to a CPropertySheet as a CPropertyPage Pin
Weiye Chen7-Jun-03 19:11
Weiye Chen7-Jun-03 19:11 
GeneralRe: How can a CPropertySheet instance be added to a CPropertySheet as a CPropertyPage Pin
FlyingDancer7-Jun-03 19:53
FlyingDancer7-Jun-03 19:53 
GeneralI pay you $ USD Pin
balu_pl7-Jun-03 13:14
balu_pl7-Jun-03 13:14 
GeneralSmart Card Inserts &amp; Removes Pin
Fad B7-Jun-03 12:53
Fad B7-Jun-03 12:53 
GeneralRe: Smart Card Inserts &amp; Removes Pin
JohnnyG7-Jun-03 13:29
JohnnyG7-Jun-03 13:29 
Generalview file Pin
balu_pl7-Jun-03 12:04
balu_pl7-Jun-03 12:04 
GeneralRe: view file Pin
Bartosz Bien8-Jun-03 2:03
Bartosz Bien8-Jun-03 2:03 
GeneralHelp me please Pin
DENISFINN7-Jun-03 11:50
DENISFINN7-Jun-03 11:50 
GeneralRe: Help me please Pin
includeh107-Jun-03 12:07
includeh107-Jun-03 12:07 
GeneralRe: Help me please Pin
William Brendel7-Jun-03 17:11
William Brendel7-Jun-03 17:11 
Generaladd a short cut Pin
aguest7-Jun-03 11:17
aguest7-Jun-03 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.