示例#1
0
unsigned int __stdcall Rain(void *param)
{
    DWORD		dwRead;
    SMALL_RECT	srcScrollRect;
    char		*bLengthOfRain, *bIsSpace, *buff;
    COORD		coordLine0 = {0, 0}, coordLine2 = {0, 2};
    CHAR_INFO	char_info = {' ', FOREGROUND_GREEN|FOREGROUND_INTENSITY};

    // 设置要移动的范围
//	srcScrollRect.Top		= coord.Y;
    srcScrollRect.Left		= 0;
    srcScrollRect.Right		= sColNum - 1;
    srcScrollRect.Bottom	= sRowNum - 1;

    buff			= (char *)malloc(sColNum);
    bIsSpace		= (char *)malloc(sColNum);
    bLengthOfRain	= (char *)malloc(sColNum);
    memset(bIsSpace, 0, sColNum);
    memset(bLengthOfRain, 0, sColNum);

    do
    {
        Sleep(50);
        /*		if (bStart)	coord.Y = 2;
        		else coord.Y = 0;
        */
        // 上面的if...else...简化如下
        coord.Y = bStart << 1;
        coordDest.Y = coord.Y + 1;
        srcScrollRect.Top = coord.Y;

        // 移动一块字符, 并用 char_info 填充空出来的区域
        ScrollConsoleScreenBuffer(hStdOut, &srcScrollRect, 0, coordDest, &char_info);

        // 输出一行字符
        for (char index = 0; index != sColNum; ++index)
        {
            if (!bLengthOfRain[index]--)
            {
                bIsSpace[index]			= GetRandom(0, 4);		// 25% 概率出字符
                bLengthOfRain[index]	= GetRandom(10, 25);	// 每列最短10, 最长25
            }
            buff[index] = bIsSpace[index] ? ' ' : GetRandom(0x30, 0x7E);
        }
        WriteConsoleOutputCharacter(hStdOut, buff, sColNum, coord, NULL);
        if (bStart)			// 读取第3行的内容并写到第1行
        {
            ReadConsoleOutputCharacter(hStdOut,  buff, sColNum, coordLine2, &dwRead);
            WriteConsoleOutputCharacter(hStdOut, buff, dwRead,  coordLine0, NULL);
        }
    } while (!kbhit());

    bRainExit = true;
    free(bLengthOfRain);
    free(bIsSpace);
    free(buff);
//	MessageBox(NULL, _T("t1 free success"), NULL, 0x40);
    return 0;
}
示例#2
0
文件: mainc.cpp 项目: MakSim345/cpp
/* Bounce - Thread to create and and control a colored letter that moves
 * around on the screen.
 *
 * Params: ch - the letter to be moved
 */
void Bounce( void *ch )
{
    /* Generate letter and color attribute from thread argument. */
    char    blankcell = 0x20;
    char    blockcell = (char) ch;
    BOOL    first = TRUE;
    COORD   oldcoord, newcoord;
    DWORD   result;


    /* Seed random number generator and get initial location. */
    srand( _threadid );
    newcoord.X = GetRandom( 0, csbi.dwSize.X - 1 );
    newcoord.Y = GetRandom( 0, csbi.dwSize.Y - 1 );
    while( repeat )
    {
        /* Pause between loops. */
        Sleep( 10L );

        /* Blank out our old position on the screen, and draw new letter. */
        if( first )
            first = FALSE;
        else
        {
            WriteConsoleOutputCharacter( hStdOut, &blankcell, 1, oldcoord, &result );
            WriteConsoleOutputCharacter( hStdOut, &blockcell, 1, newcoord, &result );
        }

        /* Increment the coordinate for next placement of the block. */
        oldcoord.X = newcoord.X;
        oldcoord.Y = newcoord.Y;
        newcoord.X += GetRandom( -1, 1 );
        newcoord.Y += GetRandom( -1, 1 );

        /* Correct placement (and beep) if about to go off the screen. */
        if( newcoord.X < 0 )
            newcoord.X = 1;
        else if( newcoord.X == csbi.dwSize.X )
            newcoord.X = csbi.dwSize.X - 2;
        else if( newcoord.Y < 0 )
            newcoord.Y = 1;
        else if( newcoord.Y == csbi.dwSize.Y )
            newcoord.Y = csbi.dwSize.Y - 2;

        /* If not at a screen border, continue, otherwise beep. */
        else
            continue;
        //Beep( ((char) ch - 'A') * 100, 175 );
    }
    /* _endthread given to terminate */
	printf ("Bounce: endthread\n");
    _endthread();
}
示例#3
0
void gra::czas()
{
    string sec = sec_const;
    string czas_g;
    czas_gracza = 0;
    int odejmowanie_czasu = 1;
    string outbuf;
    LPWORD buferkoloru;
    buferkoloru = new WORD[outbuf.length()];
    COORD cWhere;
    HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwCharsWritten;
    while (true)
    {
        if (zgnieciony == true || wygrana == true || escape == true || ukaszony == true)
            break;
        if (odejmowanie_czasu == 0)
        {
            koniec_czasu = true;
            break;
        }
        cWhere.X = 52;
        cWhere.Y = 4;
        outbuf = sec;
        istringstream iss(sec);
        iss >> odejmowanie_czasu;
        odejmowanie_czasu--;
        ostringstream ss;
        ss << odejmowanie_czasu;
        sec = ss.str();
        if (sec.length() == 2)
            sec.insert(0, " ");
        if (sec.length() == 1)
            sec.insert(0, "  ");
        WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
        cWhere.X = 52;
        cWhere.Y = 6;
        ostringstream ss2;
        ss2 << czas_gracza;
        czas_g = ss2.str();
        if (czas_g.length() == 2)
            czas_g.insert(0, " ");
        if (czas_g.length() == 1)
            czas_g.insert(0, "  ");
        outbuf = czas_g;
        WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
        czas_gracza++;
        Sleep(1000);
    }
}
示例#4
0
unsigned int __stdcall Joy(void *param)
{
    DWORD dwRead, dwStrLen;
    const char *szStr;
    char *buff	= (char *)malloc(sColNum);
    char *space = (char *)malloc(sColNum);
    COORD coordLine1 = {0, 0},
          coordLine2 = {0, 1},
          coordMid	 = {sColNum / 3, 1},
             coordStr;

    coordStr.Y = 1;
    memset(space, 0x20, sColNum);

    do
    {
        szStr = szStrings[GetRandom(0, sizeof(szStrings) / 4 - 1)];		// 随机选取一个字符串
        dwStrLen = lstrlenA(szStr);
        coordStr.X = sColNum / 2 - (SHORT)dwStrLen / 2 - 1;					// 计算中间位置
        Sleep(GetRandom(1000, 1000));
        bStart = true;
        Sleep(100);			// 确保另一个线程已完成转换
        if (bRainExit)
            break;

        // 用空格填充第2行
        WriteConsoleOutputCharacter(hStdOut, space, sColNum, coordLine2, NULL);

        for (byte index = 0; index != 15; ++index)
        {
            for (byte ix = 0; ix != coordMid.X; ix += 1)
                buff[ix] = GetRandom('A', 'z');
            WriteConsoleOutputCharacter(hStdOut, buff, coordMid.X, coordMid, NULL);
            Sleep(20);
        }

        WriteConsoleOutputCharacter(hStdOut, space, sColNum, coordLine2, NULL);
        WriteConsoleOutputCharacter(hStdOut, szStr, dwStrLen, coordStr, NULL);
        Sleep(GetRandom(1000, 1000));

        ReadConsoleOutputCharacter(hStdOut,  buff, sColNum, coordLine1, &dwRead);
        WriteConsoleOutputCharacter(hStdOut, buff, dwRead,  coordLine2, NULL);
        bStart = false;
    } while (!kbhit());

    free(space);
    free(buff);
//	MessageBox(NULL, _T("t2 free success"), NULL, 0x40);
    return 0;
}
示例#5
0
void
WriteStringAt(
	LPTSTR	lpString,
	COORD	xy,
	WORD	wColor
	)
{
	DWORD	cWritten = 0;
	WORD	wLen = lstrlen(lpString);

	if (0 == wLen)
		return;
	// don't bother writing text when erasing
	if( wColor )
	  WriteConsoleOutputCharacter( ScreenBuffer,
				       lpString,
				       wLen,
				       xy,
				       & cWritten
				       );
	FillConsoleOutputAttribute(
		ScreenBuffer,
		wColor,
		wLen,
		xy,
		& cWritten
		);
}
示例#6
0
void Display::updatePos(Position pos_)
{
	if (!m_map.count(pos_))
		return;
    Position CurrentPosition;
    CurrentPosition=pos_;
    const char graphic=m_map[CurrentPosition].getGraphic();
    WORD color=m_map[CurrentPosition].getColor();
    if(m_map[CurrentPosition].getBackground()!=0)
    {
        color=color | m_map[CurrentPosition].getBackground();
    }
	if (isSelected_.count(pos_))
	{
		if (isSelected_[pos_] == true)
		{
			color = S_Box | C_White;
		}
	}
    pos.X=CurrentPosition.getX();
    pos.Y=CurrentPosition.getY();
    //ReadConsoleOutputCharacter(h, &readConsole_, nlength, pos, &output);
    //if (readConsole_ == graphic) return;
    WriteConsoleOutputCharacter(h, &graphic, nlength, pos, &output);
    WriteConsoleOutputAttribute(h, &color, nlength , pos, &output);
}
示例#7
0
ThinConsole& ThinConsole::WriteToConsole(string_type const& outputString, console_location_type const& location, console_color_type const& foreground, console_color_type const& background) {
	assert(outputHandle != NULL && "Output Handle Not Initialized");
	std::vector<console_attribute_type> outputAttributes(outputString.size(), foregroundColorMap[foreground] | backgroundColorMap[background]);
	console_information_type charsWritten;
	ExceptionCheck(WriteConsoleOutputCharacter(outputHandle, std::wstring(outputString.begin(), outputString.end()).c_str(), outputString.size(), location, &charsWritten), __FUNCTION__, __LINE__);
	ExceptionCheck(WriteConsoleOutputAttribute(outputHandle, outputAttributes.data(), outputAttributes.size(), location, &charsWritten), __FUNCTION__, __LINE__);
	return *this;
}
示例#8
0
static int outputChars(struct current *current, const char *buf, int len) {
    COORD pos = {(SHORT) current->x, (SHORT) current->y};
    DWORD n;

    WriteConsoleOutputCharacter(current->outh, buf, len, pos, &n);
    current->x += len;
    return 0;
}
示例#9
0
void Display::setPos(Position ipos, char graphic)
{
    pos.X=ipos.getX();
    pos.Y=ipos.getY();
    //ReadConsoleOutputCharacter(h, &readConsole_, nlength, pos, &output);
    //if(readConsole_ == graphic) return;
    WriteConsoleOutputCharacter(h, &graphic, nlength, pos, &output);
}
void
ConsoleDebugger::OnWriteConsoleOutputCharacterW(Process *proc,
    ThreadInfo *threadInfo, Breakpoint *brkpt, PDWORD returnValue,
    DWORD direction)
{
    static WCHAR buf[1024];
    static CHAR ansi[2048];
    PVOID ptr;
    DWORD nLength, dwWritten;
    PWCHAR p;
    PCHAR lpCharacter;
    COORD dwWriteCoord;
    int asize;

    if (*returnValue == 0) {
	return;
    }
    // Get number of bytes written
    ptr = (PVOID) threadInfo->args[4];
    if (ptr == 0L) {
	nLength = threadInfo->args[2];
    } else {
	ReadSubprocessMemory(proc, ptr, &nLength, sizeof(DWORD));
    }

    dwWriteCoord = *((PCOORD) &threadInfo->args[3]);
    CreateVtSequence(proc, dwWriteCoord, nLength);

    if (nLength >= 1024) {
	p = new WCHAR [nLength + 1];
	asize = nLength * 2 * sizeof(CHAR);
	lpCharacter = new CHAR [asize + 1];
    } else {
	p = buf;
	lpCharacter = ansi;
	asize = sizeof(ansi);
    }

    ptr = (PVOID) threadInfo->args[1];
    ReadSubprocessMemory(proc, ptr, p, nLength * sizeof(WCHAR));

    // Convert to ASCI and Write the intercepted data to the pipe.
    nLength = WideCharToMultiByte(CP_ACP, 0, p, nLength, lpCharacter,
				  asize, 0L, 0L);
    lpCharacter[nLength] = '\0';
    WriteMaster(lpCharacter, nLength);

    WriteConsoleOutputCharacter(hCopyScreenBuffer, lpCharacter, nLength,
				dwWriteCoord, &dwWritten);

    if (p != buf) {
	delete [] p;
	delete [] lpCharacter;
    }
    CursorKnown = FALSE;
}
示例#11
0
// formatted write console output
int PrintConsole(HANDLE out, COORD pos, char const *format, ...)
{
	va_list ap;
	va_start(ap, format);
	char buf[256];
	vsnprintf_s(buf, sizeof(buf), format, ap);
	DWORD written;
	WriteConsoleOutputCharacter(out, buf, strlen(buf), pos, &written);
	return written;
}
示例#12
0
void Display(void *argv)
{//display memory
    char    MyCell, OldCell;
    WORD    MyAttrib, OldAttrib;
    char    BlankCell = 0x20;//' '
	COORD   Coords = {0,0}, Delta;
    COORD   Old = {0,0};
    DWORD   Dummy;

	address_type disp_addr = MEMORY_DISP_ADDR;

    // Generate update increments and initial 
    // display coordinates.
    MyAttrib = 0x0F;   // force black background 
	size_t count = 0;
	ClearScreen();
	const size_t TOTAL_SIZE = csbiInfo.dwSize.X * MAX_Y;
	csbiInfo.dwSize.Y = MAX_Y;
	bool last_scanf_flag = 0;	//if program ends then refresh for last time

    do{//print every char
		Coords.X = Coords.Y = 0;
		for(size_t i = 0; i <= (TOTAL_SIZE+PAGE_SIZE-1)/PAGE_SIZE ; i++){//for every part
			//get every page's first addr
			WaitForSingleObject(hScreenMutex, INFINITE);
			byte *mem_ptr = GetPageBlock(disp_addr+i*PAGE_SIZE);

			size_t blockSize = PAGE_SIZE;
			if(i == (TOTAL_SIZE+PAGE_SIZE-1)/PAGE_SIZE)
				blockSize = (TOTAL_SIZE - i*PAGE_SIZE) % PAGE_SIZE;//remain

			WriteConsoleOutputCharacter(hConsoleOut, (LPCSTR)mem_ptr, blockSize, Coords, &Dummy);
			WriteConsoleOutputAttribute(hConsoleOut, &MyAttrib, 1, Coords, &Dummy);
			ReleaseMutex(hScreenMutex);//unlock 

			Coords.Y += blockSize / csbiInfo.dwSize.X;
			Coords.X = (Coords.X + blockSize % csbiInfo.dwSize.X) % csbiInfo.dwSize.X;

			// Increment the coordinates for next placement of the block. 
			if(Coords.Y >= MAX_Y){
				if(last_scanf_flag){
					display_finished = true;
					while(1) ;//wait
				}	
				if(prog_finished){//end
					last_scanf_flag = true;
				}
				break;
			}
		}//for every part
	}//end of while
    while (WaitForSingleObject(hRunMutex, 75L) == WAIT_TIMEOUT);
	// Repeat while RunMutex is still taken. 
}
示例#13
0
void WriteText(char* msg,WORD x,WORD y)
{
	COORD	pos;
	pos.X = x;
	pos.Y = y;
	
	DWORD lenout;
	WriteConsoleOutputCharacter(g_hOut,msg,lstrlen(msg),pos,&lenout);

	return;
}
void DisplayKeyVolumeEnvelope::Init(HANDLE hOut)
{
	// show the note keys
	DWORD written;
	WriteConsoleOutputCharacterW(hOut, LPCWSTR(keys), KEYS, key_pos, &written);
	FillConsoleOutputAttribute(hOut, env_attrib[EnvelopeState::OFF], KEYS, key_pos, &written);

	// voice indicators
	CHAR voice[VOICES];
	memset(voice, 7, VOICES);
	WriteConsoleOutputCharacter(hOut, voice, VOICES, voice_pos, &written);
}
示例#15
0
														// Here is our function that draws a color string in a DOS window.
														// We just pass in the string, the X and Y position, then the color we desire.
														// The color can be a background color AND a foreground color.  Here are some color examples:
														// FOREGROUND_GREEN; FOREGROUND_RED; FOREGROUND_BLUE; - BACKGROUND_RED; BACKGROUND_BLUE; BACKGROUND_GREEN;
														// You can mix and match these to create other colors.  Look in "Main()" to see how.
void DrawColorString(char *szText, int X, int Y, WORD color)
{
	COORD  screenPos={X, Y};							// Put the X and Y position in a structure.
	WORD   *colorBuf=NULL;								// Create a pointer to a buffer that holds the color for each character.
    DWORD  dwResult=0;									// This holds the amount of characters drawn to the screen. (We don't care about this though...)
	HANDLE OutputH;										// This is an OUTPUT handle.  Think of this as our link to the video card.
	int    length=0;									// This will hold the length of the string passed in.
	int    i=0;											// This is used as a counter.
	
	if(szText == NULL)									// Check if the string is NULL (This makes something was passed in).
      return;											// Quit from the function if no string was passed in.

	OutputH = GetStdHandle(STD_OUTPUT_HANDLE);			// Get an OUTPUT handle to our screen.

	length = strlen(szText);							// strlen() finds the amount of characters in a string.
														// Ok, here is a new concept called "dynamic allocation".  Since we don't
														// know how big the string is that is passed in, we can't just create a colorBuffer like this:
														// WORD colorbuf[I don't know yet];
														// So what we do is just make a pointer, then fill it in on the fly.  This is called "dynamically allocating memory".
														// In, C, we use a function called malloc().  You might notice that it has a weird thing in front of it.  (WORD *).
														// This is called "type-casting".  Since malloc returns a "void *", we need to "cast" the information received into a "WORD *".
														// A "void *" is used so you don't have to have a malloc() for each type of variable, like a WordMalloc(), or an IntMalloc().
														// We can just "cast" the "void *" to what ever variable we are using.  Nifty huh?
														// You can cast anything.  Like, if you want to take a floating point number, and store it into
														// an integer, just say, var1 = (int)var2.  say var2 = 1.2; now var1, being an integer, = 1.  It cuts off the excess.
														// The parameter for malloc() is the number of bytes of memory to allocate.
														// You might say, "But I don't know how many bytes a WORD is..."  That's fine, the sizeof() function does it for you.
														// So, now that we have the bytes of a WORD, we need to figure out how many WORDs we want to allocate.
														// Since we know the length of the string passed in, we just times the amount of bytes by the length.  bytes*length.
	colorBuf = (WORD*)malloc(sizeof(WORD) * length);	// So sizeof(WORD) * length gives us how many bytes of memory we will need to allocate.  Later, we must "free()" the memory.

	for (i=0; i < length; i++)							// Now we go through the color buffer and assign a color for each character.
	{													// A pointer is a one dimensional array.  so we can use the "[]" brackets.
		colorBuf[i] = color;							// Here we assign each cell of colorBuf a color.  The color is what we passed into the function.
	}													// We could say "colorBuf[i] = rand(); and every character in the string would be a random color.
															
														// These bad boys are what draws the text and the text's color to the screen.
														// The first one draws the color to the screen. It's parameters are:
														// "(Output handle, an array to hold the color of each character, the length of the string, the screen position, and the address of a DWORD to hold the number of characters drawn)"
	WriteConsoleOutputAttribute(OutputH, colorBuf, length, screenPos, &dwResult);
														// The next function draws the actual characters to the screen.  It's parameters are:
														// "(Output handle, the string to print, the length of the string, the screen position, and the address of a DWORD to hold the number of characters drawn)"
	WriteConsoleOutputCharacter(OutputH, szText, length, screenPos, &dwResult);
														// The last parameter, we don't care about, we just need it or else the program will crash :)
	free(colorBuf);										// This is how we free memory that we allocated.  There should ALWAYS be a "free()" for every "malloc()".
	colorBuf = NULL;									// After we free a pointer, we should always set it to NULL.  Checking if a pointer equals NULL is the way a pointer is determined if it's "valid" or not.
														// If we didn't set this pointer to NULL it would still point to an address in memory.  However, if we tried to access that memory we'd get a CRASH.  So just set freed pointers to NULL always.
														// You know how you are playing a game, or leave a program running for a while? ... And your computer starts to slow down after a while...?
														// Or when you quit the program, your computer runs slower?  That's not the computer getting tired... that because the programmers
														// didn't free their memory.  If you ask the OS for memory, it locks that memory address so no other program can use it.
														// If you don't free that memory, then the computer still assumes that it's still being used.  You have to restart your computer
														// to get that memory back.  It resets all the permissions you could say.
}
示例#16
0
bool KConsoleDriver::flushCharacters(int fromX,int fromY,int toX,int toY,const char *characters)
{
#ifdef USE_M_API
	coord top = { (SHORT)fromX, (SHORT)fromY };
	dword result;
	if (!WriteConsoleOutputCharacter(hStdOut, characters, toX * toY, top, &result))
	{
		return false;
	}
#endif
	return true;
}
示例#17
0
static void
scflush(void)
{
    if (bufpos) {
	COORD coordCursor;
	DWORD written;
#ifdef UNICODE
	W32_CHAR *actual;
	char save_buf;
#endif

	coordCursor.X = (SHORT) ccol;
	coordCursor.Y = (SHORT) crow;
	TRACE2(("scflush %04x [%d,%d]%.*s\n",
		currentAttribute, crow, ccol, bufpos, linebuf));
#ifdef UNICODE
	save_buf = linebuf[bufpos];
	linebuf[bufpos] = 0;
	if ((actual = w32_charstring(linebuf)) != 0) {
	    WriteConsoleOutputCharacter(
					   hConsoleOutput, actual, bufpos,
					   coordCursor, &written
		);
	    free(actual);
	}
	linebuf[bufpos] = save_buf;
#else
	WriteConsoleOutputCharacter(
				       hConsoleOutput, linebuf, bufpos,
				       coordCursor, &written
	    );
#endif
	FillConsoleOutputAttribute(
				      hConsoleOutput, currentAttribute,
				      bufpos, coordCursor, &written
	    );
	ccol += bufpos;
	bufpos = 0;
    }
}
示例#18
0
void Display::setPos(Position ipos, char graphic, WORD color)
{
    pos.X=ipos.getX();
    pos.Y=ipos.getY();

    //ReadConsoleOutputCharacter(h, &readConsole_, nlength, pos, &output);
    //if(readConsole_ != graphic)
        WriteConsoleOutputCharacter(h, &graphic, nlength, pos, &output);

    //ReadConsoleOutputAttribute(h, &readAttribute_, nlength, pos, &output);
    //if(readAttribute_ != color)
        WriteConsoleOutputAttribute(h, &color, nlength, pos, &output);
}
示例#19
0
main()
{
	//设置console窗口的标题
	SetConsoleTitle("copying...");
	printf("\n");

	int i = 0;
	printf("files copied %3d%%...\n", i);

	COORD origin = {13, 1};	//只有在声明时可以这样赋值
	HANDLE hConsoleOut;
	DWORD charWritten;
	char buf[16];

	//得到console的句柄
	hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);

	while(i < 100)
	{
		i++;
		//转换成10进制的数的字符串,存到buf中。
		_itoa(i, buf, 10);	

		//在指定的位置输出字符串,charWritten表示输出的字符数
		WriteConsoleOutputCharacter( hConsoleOut, buf, 3, origin, &charWritten);
		Sleep(200);

	}

	strcpy( buf, "completed. \n");
	WriteConsoleOutputCharacter( hConsoleOut, buf, strlen(buf) + 1 , origin, &charWritten);

	//关闭标准输出的句柄。
	//CloseHandle减少object的引用计数
	//当引用计数为0时,系统会清除该对象
	CloseHandle( hConsoleOut);

}
示例#20
0
int Screen::writeText (int x, int y, const char *text, int count)
{
    DWORD charsWritten;
    if (text == 0)
	throw AppException (WHERE, ERR_INTERNAL);
    if (count <= 0)
	count = (int) strlen (text);
    COORD c;
    c.X = (SHORT) x;
    c.Y = (SHORT) y;
    if (WriteConsoleOutputCharacter (mScreenBuf, text, count, c, &charsWritten) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "WriteConsoleOutputCharacter", GetLastError ());
    return charsWritten;
}
示例#21
0
文件: 2000.cpp 项目: yifanlu/Josh
JNIEXPORT void JNICALL Java_com_yifanlu_Josh_Josh_WRITECONSOLEOUTPUTCHARACTER
  (JNIEnv *env, jclass jcls, jlong pointer, jintArray data, jint length, jint x, jint y)
{
	HANDLE hConsole = pointerToHandle(pointer);
	COORD coordBufCoord = {x , y};
	char *buffer = new char[length];
	DWORD numWrote;

	jint *body = env->GetIntArrayElements(data, 0);

	for(int x = 0; x < length; x++)
		buffer[x] = (char)body[x];

	WriteConsoleOutputCharacter(hConsole, buffer, length, coordBufCoord, &numWrote);
}
示例#22
0
文件: Player.cpp 项目: 88er/tutorials
void CPlayer::Draw()
{
	char szPlayer[2] = {0};
	DWORD dwResult = 0;

	// Get an output handle for drawing
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

	// Add the player character to a string (We need a string for WriteConsoleOutputCharacter())
	sprintf(szPlayer, "%c", m_image.Char);

	// Finally, we draw our player's character and then draw it's color
	WriteConsoleOutputCharacter(hOutput, szPlayer, 1, m_position, &dwResult);
	WriteConsoleOutputAttribute(hOutput, &m_image.Attributes, 1, m_position, &dwResult);
}
示例#23
0
文件: pmon.c 项目: shuowen/OpenNT
BOOL
WriteConsoleLine(
    HANDLE OutputHandle,
    WORD LineNumber,
    LPSTR Text,
    BOOL Highlight
)
{
    COORD WriteCoord;
    DWORD NumberWritten;
    DWORD TextLength;

    WriteCoord.X = 0;
    WriteCoord.Y = LineNumber;
    if (!FillConsoleOutputCharacter( OutputHandle,
                                     ' ',
                                     NumberOfCols,
                                     WriteCoord,
                                     &NumberWritten
                                   )
       ) {
        return FALSE;
    }

#if 0
    if (!FillConsoleOutputAttribute( OutputHandle,
                                     (WORD)(Highlight ? HighlightAttribute : NormalAttribute),
                                     NumberOfCols,
                                     WriteCoord,
                                     &NumberWritten
                                   )
       ) {
        return FALSE;
    }

#endif
    if (Text == NULL || (TextLength = strlen( Text )) == 0) {
        return TRUE;
    }
    else {
        return WriteConsoleOutputCharacter( OutputHandle,
                                            Text,
                                            TextLength,
                                            WriteCoord,
                                            &NumberWritten
                                          );
    }
}
示例#24
0
void CTextConsoleWin32::UpdateStatus()
{
	COORD coord;
	DWORD dwWritten = 0;
	WORD wAttrib[ 80 ];

	for (int i = 0; i < 80; i++)
	{
		wAttrib[i] = Attrib; // FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
	}

	coord.X = coord.Y = 0;

	WriteConsoleOutputAttribute(houtput, wAttrib, 80, coord, &dwWritten);
	WriteConsoleOutputCharacter(houtput, statusline, 80, coord, &dwWritten);
}
示例#25
0
文件: Mem.cpp 项目: elfmz/far2l
void ShowMemInfo(void)
{
	static BOOL into = FALSE;

	if(into) return;

	into = TRUE;
	CONSOLE_SCREEN_BUFFER_INFO ci;
	char                       str[100];
	HANDLE                     h = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD                      dw;
	sprintf(str,"%6ld in %-6ld ",MemUsage,MemCount);
	ci.dwSize.X = FP_ConWidth() - strlen(str);
	ci.dwSize.Y = 0;
	WriteConsoleOutputCharacter(h,str,strlen(str),ci.dwSize,&dw);
	into = FALSE;
}
示例#26
0
VALUE
rb_WriteConsoleOutputCharacter(VALUE self, VALUE h, VALUE s,
			       VALUE x, VALUE y)
{
    HANDLE handle = ULongToPtr( NUM2ULONG( h ) );
    DWORD written;
    COORD coords;
    Check_Type( s, T_STRING );
    
    coords.X=NUM2INT( x );
    coords.Y=NUM2INT( y );
    if (WriteConsoleOutputCharacter(handle,(LPCTSTR)RSTRING_PTR(s),
				    RSTRING_LEN(s),coords,&written)) {
       return UINT2NUM( written );
    }
    return rb_getWin32Error();
}
void
ConsoleDebugger::OnWriteConsoleOutputCharacterA(Process *proc,
    ThreadInfo *threadInfo, Breakpoint *brkpt, PDWORD returnValue, DWORD direction)
{
    static CHAR buf[1024];
    PVOID ptr;
    DWORD nLength, dwWritten;
    PCHAR lpCharacter;
    COORD dwWriteCoord;

    if (*returnValue == 0) {
	return;
    }
    // Get number of bytes written
    ptr = (PVOID) threadInfo->args[4];
    if (ptr == 0L) {
	nLength = threadInfo->args[2];
    } else {
	ReadSubprocessMemory(proc, ptr, &nLength, sizeof(DWORD));
    }

    dwWriteCoord = *((PCOORD) &threadInfo->args[3]);
    CreateVtSequence(proc, dwWriteCoord, nLength);

    if (nLength >= 1024) {
	lpCharacter = new CHAR [nLength + 1];
    } else {
	lpCharacter = buf;
    }

    ptr = (PVOID) threadInfo->args[1];
    ReadSubprocessMemory(proc, ptr, lpCharacter, nLength * sizeof(CHAR));
    lpCharacter[nLength] = '\0';
    WriteMaster(lpCharacter, nLength);

    WriteConsoleOutputCharacter(hCopyScreenBuffer, lpCharacter, nLength,
				dwWriteCoord, &dwWritten);

    if (lpCharacter != buf) {
	delete [] lpCharacter;
    }
    CursorKnown = FALSE;
}
示例#28
0
int PutText( char *szText )
{
    CONSOLE_SCREEN_BUFFER_INFO csbi; 
    BOOL		  bSuccess;
    unsigned long cWritten;
	// QUESTION K When is iLen created, and where? What's it's storage class?
	int			  iLen;
	BOOL		  bHasNewLine;

   // Get the current text attributes.
   if( !GetConsoleScreenBufferInfo( hStdout, &csbi ))
      return(0);

    iLen = cWritten = strlen(szText);
	if ( iLen <= 0 ) return(0);

	// if the line ends in a newline, don't show it.
	bHasNewLine = (	szText[iLen-1] == '\n' );
	if ( bHasNewLine ) --iLen;
	
    // Set the buffer's attributes accordingly.
    if( !FillConsoleOutputAttribute( hStdout, csbi.wAttributes,
         cWritten, coordCurrent, &cWritten ))
        return(0);

    bSuccess = WriteConsoleOutputCharacter( hStdout, szText, iLen, 
							coordCurrent, &cWritten);
    coordCurrent.X += (short)cWritten;

	// if final character written is a \n, fix next pos.
	if ( bHasNewLine ) {
	    coordCurrent.X = 0;
	    coordCurrent.Y += 1;
	}

	// Dec 4/03 jc move the cursor there
    SetConsoleCursorPosition( hStdout, coordCurrent );

    return(bSuccess);
}
示例#29
0
void BarConsoleEraseCharacter()
{
    TCHAR buffer[256];
    WORD buffer2[256];
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    COORD coords;
    HANDLE handle = BarConsoleGetStdOut();
    int length, read, write;

    if (!GetConsoleScreenBufferInfo(handle, &csbiInfo))
        return;

    length = csbiInfo.dwSize.X - csbiInfo.dwCursorPosition.X - 1;
    read = csbiInfo.dwCursorPosition.X + 1;
    write = csbiInfo.dwCursorPosition.X;

    while (length >= 0)
    {
        int size = min(length, 256);
        DWORD chRead = 0, chWritten = 0;
        coords = csbiInfo.dwCursorPosition;
        coords.X = read;
        ReadConsoleOutputAttribute(handle, buffer2, size, coords, &chRead);
        ReadConsoleOutputCharacter(handle, buffer, size, coords, &chRead);

        if (chRead == 0)
            break;

        coords.X = write;
        WriteConsoleOutputAttribute(handle, buffer2, chRead, coords, &chWritten);
        WriteConsoleOutputCharacter(handle, buffer, chRead, coords, &chWritten);

        read += chRead;
        write += chRead;
        length -= chRead;
    }
}
示例#30
0
int   PDC_putctty( chtype character, chtype color )
/***********************************************************************/
{
   int curRow=0, curCol=0;
   WORD buffer;
   COORD coord;
   DWORD written;


#ifdef PDCDEBUG
   if (trace_on) PDC_debug("PDC_putctty() - called\n");
#endif

   buffer = color; 
   PDC_get_cursor_pos (&curRow, &curCol);
   coord.X = curCol;
   coord.Y = curRow;
//   WriteConsoleOutputAttribute(hConOut, &buffer, 1, coord, &written);
       
   buffer = character; 
   WriteConsoleOutputCharacter(hConOut, (char*)&buffer, 1, coord, &written);
       
   return (OK);
}