finally i have the blink working:
//blinktext.h
#include <process.h>
#include <string>
#include <memory.h>
#include <windows.h>
using namespace std;
struct Blink
{
string Text;
int x;
int y;
int TextColor;
int BackColor;
};
unsigned __stdcall BlinkLoop(void *params)
{
Blink *p = static_cast<Blink *>(params);
size_t tlen = p->Text.length()-2;
char *EmptyText = new char[tlen];
memset(EmptyText, 'd', tlen);
HDC hDC=GetDC(GetConsoleWindow());
while (true)
{
SetBkMode(hDC,TRANSPARENT);
SetTextColor(hDC,RGB(0,255,0));
TextOut(hDC,p->x,p->y,p->Text.c_str(),(int)p->Text.length()+1);
Sleep(500);
SetTextColor(hDC,RGB(0,0,0));
SetBkMode(hDC,OPAQUE);
SetBkColor(hDC,RGB(0,0,0));
TextOut(hDC,p->x,p->y,EmptyText,(int)p->Text.length()+2);
Sleep(500);
}
return 0;
}
void TextBlink(string text, int x, int y, int TextColor, int BackColor)
{
Blink *b=new Blink;
b->Text=text;
b->BackColor=BackColor;
b->TextColor=TextColor;
b->x=x;
b->y =y;
_beginthreadex(NULL, 0, BlinkLoop ,b, 0, NULL);
}
//main.cpp
#include <iostream>
#include "blinktext.h"
using namespace std;
int main()
{
TextBlink("Hello world", 20,20,3,3);
cout << "hello world";//like you see, the caret(text cursor) isn't losed
cin.get();
return 0;
}
why (int)p->Text.length()+2)??
because some issue..i don't know, if i don't use it the text isn't showed... sorry, but test it and see yourself...
the colors aren't programmed, but works fine