cambalinho 142 Practically a Posting Shark

resolved:

SMALL_RECT c={x, y,SHORT(x+tlen),SHORT(y+1)};

seems the '+' operator put them to 'int', that's why i must use SHORT like a function(the casting don't works)
thanks for all

cambalinho 142 Practically a Posting Shark

the c++ is case sensitive, so we must use:

Text.length();

sorry i continue with warnings on that line

cambalinho 142 Practically a Posting Shark

finally i resolve it:

Blink *p = static_cast<Blink *>(params);
    SHORT tlen = (SHORT)p->Text.length();
    SHORT x=p->x, y=p->y;
    HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    const char *text=(char*)p->Text.c_str();
    SHORT stringlen=strlen(text);
    CHAR_INFO *ConsoleText= new CHAR_INFO[tlen];
    CHAR_INFO *EmptyConsoleText= new CHAR_INFO[tlen];
    COORD a={tlen,1}, b={0,0};
    SMALL_RECT c={x,y,x+tlen,y+(SHORT)1};

    int i=0;
    for (i=0; i<stringlen;i++)
    {
        ConsoleText[i].Char.AsciiChar  =text[i];
        ConsoleText[i].Attributes=FOREGROUND_GREEN;
        EmptyConsoleText[i].Char.AsciiChar  =' ';
        EmptyConsoleText[i].Attributes=FOREGROUND_GREEN;
    }

    while (true)
    {
        WriteConsoleOutput(hout,ConsoleText,a,b,&c);
        Sleep(500);
        WriteConsoleOutput(hout,EmptyConsoleText,a,b,&c);
        Sleep(500);
    }

but i get 2 warnings on:

SMALL_RECT c={x,y,x+tlen,y+(SHORT)1};

1 - "warning: narrowing conversion of '(((int)x) + ((int)tlen))' from 'int' to 'SHORT {aka short int}' inside { } [-Wnarrowing]";

2 - "warning: narrowing conversion of '(((int)y) + 1)' from 'int' to 'SHORT {aka short int}' inside { } [-Wnarrowing]".

but the 'p' pointer structure are in SHORT's, so why the warnings?

cambalinho 142 Practically a Posting Shark

yes again i did a mistake:

Blink *p = static_cast<Blink *>(params);
    SHORT tlen = (SHORT)p->Text.length();
    SHORT x=p->x, y=p->y;
    HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    const char *text=(char*)p->Text.c_str();
    SHORT stringlen=strlen(text);
    CHAR_INFO *ConsoleText= new CHAR_INFO[tlen];
    CHAR_INFO *EmptyConsoleText= new CHAR_INFO[tlen];
    COORD a={tlen,1}, b={0,0};
    SMALL_RECT c={x,y,x+tlen,y+(SHORT)1};

    int i=0;
    for (i=0; i<stringlen;i++)
    {
        ConsoleText[i].Char.AsciiChar  =text[i];
        ConsoleText[i].Attributes=FOREGROUND_GREEN;
        EmptyConsoleText[i].Char.AsciiChar  =' ';
    }

i have 1 question: when the EmptyConsoleText is printed, the 3st characters are showed with a backcolor, why?

cambalinho 142 Practically a Posting Shark

now i'm add it to my code:

Blink *p = static_cast<Blink *>(params);
SHORT tlen = (SHORT)p->Text.length();
SHORT x=(SHORT)p->x, y=(SHORT)p->y;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
char *text=(char*)p->Text.c_str();
SHORT stringlen=strlen(text);
CHAR_INFO *ConsoleText= new CHAR_INFO[tlen];
CHAR_INFO *EmptyConsoleText= new CHAR_INFO[tlen];
COORD a={tlen,1}, b={0,0};
SMALL_RECT c={x,y,x+tlen,y+(SHORT)1};

int i=0;
for (i=0; i<=stringlen;i++)
{
    ConsoleText[i].Char.AsciiChar  =text[i];
    ConsoleText[i].Attributes=FOREGROUND_GREEN;
    ConsoleText[i].Char.AsciiChar  =' ';
}

output errors :(
on SMALL_RECT i get these warnings:

1 - "warning: narrowing conversion of '(((int)x) + ((int)tlen))' from 'int' to 'SHORT {aka short int}' inside { } [-Wnarrowing]"

2 - "warning: narrowing conversion of '(((int)y) + 1)' from 'int' to 'SHORT {aka short int}' inside { } [-Wnarrowing]"

why these warnings if the x and y are SHORT?

another problem: the output give me strange characters, can you tell me why?

cambalinho 142 Practically a Posting Shark

now works.. thanks
i did a mistake between x,y:

HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    char text[]={'h','e','l','l','o',' ','w','o','r','l','d'};
    SHORT stringlen=strlen("hello world");
    CHAR_INFO *consoletext= new CHAR_INFO[stringlen];
    COORD a={stringlen,1}, b={0,0};
    SMALL_RECT c={0,0,stringlen,1};

    int i=0;
    for (i=0; i<=stringlen;i++)
    {
        consoletext[i].Char.AsciiChar  =text[i];
        consoletext[i].Attributes=FOREGROUND_GREEN;

    }

    WriteConsoleOutput(hout,consoletext,a,b,&c);

thanks for all

cambalinho 142 Practically a Posting Shark

sorry you have right:

HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    char text[]={'h','e','l','l','o',' ','w','o','r','l','d'};
    SHORT stringlen=strlen("hello world");
    CHAR_INFO *consoletext= new CHAR_INFO[stringlen];
    COORD a={1,stringlen}, b={0,0};
    SMALL_RECT c={0,0,1,1};

    int i=0;
    for (i=0; i<stringlen;i++)
    {
        consoletext[i].Char.AsciiChar  =text[i];
        consoletext[i].Attributes=FOREGROUND_BLUE|BACKGROUND_RED;
    }

    WriteConsoleOutput(hout,consoletext,a,b,&c);

but i have more errors: the text only show me 2 letters on vertical.
so i belive that my SMALL_RECT and maybe the 2 COORD are wrong. can you explain to me, please?

cambalinho 142 Practically a Posting Shark

see these post: http://forums.codeguru.com/showthread.php?423599-WriteConsoleOutput
i'm trying, but i don't know where i mistake

cambalinho 142 Practically a Posting Shark
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    char text[]="hello world";
    SHORT stringlen=strlen("hello world");
    CHAR_INFO *consoletext= new CHAR_INFO[stringlen];
    COORD a={1,stringlen}, b={0,0};
    SMALL_RECT c={0,0,1,1};

    int i=0;
    for (i=0; i<stringlen;i++)
    {
        text[i].AsciiChar=(int) text[i];
        text[i].Attributes=FOREGROUND_BLUE|BACKGROUND_RED;
    }

    WriteConsoleOutput(hout,consoletext,a,b,&c);

but i get 2 errors:
"error: request for member 'AsciiChar' in 'text[i]', which is of non-class type 'char'"
and
"error: request for member 'Attributes' in 'text[i]', which is of non-class type 'char'"
can you advice me?

cambalinho 142 Practically a Posting Shark

Moderator: Please change the thread title to: "how use WriteConsoleOutputAttribute() and WriteConsoleOutput()?"

can you give a example of WriteConsoleOutput()?

BOOL WINAPI WriteConsoleOutput(
  _In_     HANDLE hConsoleOutput,
  _In_     const CHAR_INFO *lpBuffer,
  _In_     COORD dwBufferSize,
  _In_     COORD dwBufferCoord,
  _Inout_  PSMALL_RECT lpWriteRegion
);




typedef struct _CHAR_INFO {
  union {
    WCHAR UnicodeChar;
    CHAR  AsciiChar;
  } Char;
  WORD  Attributes;
} CHAR_INFO, *PCHAR_INFO;

i don't understand where i put the string :(
can you explain better, please?

cambalinho 142 Practically a Posting Shark

"Copies a number of character attributes to consecutive cells of a console screen buffer, beginning at a specified location."
so the WriteConsoleOutputAttribute() just change the rectangule attributes and then i use WriteConsoleOutput() on that rectangule and print the characters, right?
(i'm a little confuse)

cambalinho 142 Practically a Posting Shark

so i just need to use:

&varname

right?

cambalinho 142 Practically a Posting Shark

the prototype function is:

BOOL WINAPI WriteConsoleOutputAttribute(
  _In_   HANDLE hConsoleOutput,
  _In_   const WORD *lpAttribute,
  _In_   DWORD nLength,
  _In_   COORD dwWriteCoord,
  _Out_  LPDWORD lpNumberOfAttrsWritten
);

i'm trying use it for the 1st time... what means:
"lpNumberOfAttrsWritten [out]

A pointer to a variable that receives the number of attributes actually written to the console screen buffer."

i'm trying use it but i don't understand what means:(
where i put the text?
can anyone explain to me?

cambalinho 142 Practically a Posting Shark

i didn't understand what means 'fixed-width font'. now i understand.
you have right... sorry about that.
i will 'close' the thread.
thanks for all

cambalinho 142 Practically a Posting Shark

sorry how i do fixed-width font?

cambalinho 142 Practically a Posting Shark

but if i use a letter(instead spaces), shows me normaly

cambalinho 142 Practically a Posting Shark

sorry about that. or it's compiler mingw bbug, i don't know...
see my new code with colors working:

//blinktext.h

#define WINVER 0x0501
#define _WIN32_WINNT WINVER
#include <windows.h>
#include <process.h>

#include <string>
#include <iostream>
using namespace std;

struct Blink
{
    string Text;
    int x;
    int y;
    COLORREF TextColor;
    COLORREF BackColor;
};

unsigned __stdcall BlinkLoop(void *params)
{
    Blink *p = static_cast<Blink *>(params);

    int tlen = (int)p->Text.length();

    HDC hDC = GetDC(GetConsoleWindow());

    HBRUSH hb = CreateSolidBrush(p->BackColor);

    LOGFONT lf;

    GetObject(GetStockObject(OEM_FIXED_FONT), sizeof(LOGFONT), &lf);
    lf.lfWeight = FW_REGULAR;

    HFONT hf = CreateFont(lf.lfHeight, lf.lfWidth,
            lf.lfEscapement, lf.lfOrientation, lf.lfWeight,
            lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut, lf.lfCharSet,
            lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality,
            lf.lfPitchAndFamily, lf.lfFaceName);

    SelectObject(hDC, (HGDIOBJ)(HFONT)hf);
    SetTextColor(hDC, p->TextColor);
    SetBkMode(hDC, TRANSPARENT);

    TEXTMETRIC tm;

    GetTextMetrics(hDC, &tm);

    RECT rt;

    rt.left = p->x * tm.tmAveCharWidth;
    rt.top = p->y * tm.tmHeight;
    rt.right = rt.left + tlen * tm.tmAveCharWidth;
    rt.bottom = rt.top + tm.tmHeight;

    while (true)
    {
        TextOut(hDC, rt.left, rt.top, p->Text.c_str(), tlen+1);//readers if the text isn't showed take of the '+1'
                Sleep(500);
        FillRect(hDC, &rt, hb);
                Sleep(500);
    }
    return 0;
}

void TextBlink(const string& Text, int x, int y, COLORREF TextColor, COLORREF 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("This text blinks ok", 0, 0, RGB(0, 255, 0), RGB(0, 0, 0));
    TextBlink("and so does this text", 4, 5, RGB(255, 255, 255), RGB(0, 0, 0));
    TextBlink("this text also blinks ok", 6, 8, RGB(255, 255, 255), RGB(0, 0, 0));


    cin.get();
    return 0;
}
kal_crazy commented: This does blink +2
cambalinho 142 Practically a Posting Shark

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

kal_crazy commented: This doesn't blink +0
cambalinho 142 Practically a Posting Shark

another question: why don't accept an empty spaces string?

(like "                       "... only show me some spaces and not all)
cambalinho 142 Practically a Posting Shark
#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);

     string Text="hello world";
    char *EmptyText;
    EmptyText=new char[ p->Text.length() ] ;
    int i;
    for( i=0;i<=(int)Text.length();i++)
    {
        EmptyText[i] = ' ';
    }
    EmptyText[i] ='\0';

    HDC hDC=GetDC(GetConsoleWindow());
    SetTextColor(hDC,RGB(0,255,0));
    SetBkMode(hDC,TRANSPARENT);

    while (true)
    {
        TextOut(hDC,p->x,p->y,p->Text.c_str(),(int)p->Text.length()+1);
        Sleep(1000);
        TextOut(hDC,p->x,p->y,EmptyText,(int)p->Text.length()+1);
        Sleep(500);
    }
    return 0;
}
void TextBlink(string Text, int x, int y, int TextColor, int BackColor)
{
    Blink *b;
    b->Text=Text;
    b->BackColor=BackColor;
    b->TextColor=TextColor;
    b->x=x;
    b->y =y;

    _beginthreadex(NULL, 0, BlinkLoop  ,&b, 0, NULL);
}

finally i have the code, but i belive the error is from pointers... because the windows tell me that the program stops to working and then close it.
can anyone advice me?

cambalinho 142 Practically a Posting Shark

i found the problem;)
my problem was with

strlen("hello world")

if i do:

strlen("hello world")+1

the text is showed.
thanks

cambalinho 142 Practically a Posting Shark

by some reason the TextOut() function don't show me the text:(
but see these code:

#include <iostream>
#include <string.h>
#include <windows.h>

using namespace std;

int main()
{
    HDC a=GetDC(GetForegroundWindow());
    cout << GetLastError();//i get 0(no errors)

    Rectangle(a,3,4,3+80,4+20);//the rectangule is showed
    TextOut(a,10,10,"hello world",strlen("hello world"));
    cout << GetLastError();//i get 0(no errors)
    cin.get();
}

why i can show the rectangule without problems, and the text isn't showed?
(on my game i use a double buffer, but i belive these isn't the problem)

cambalinho 142 Practically a Posting Shark

i will do another thread, because i'm doing these wrong with forum :(

cambalinho 142 Practically a Posting Shark

i have 1 project for a console, on VSC++ and the function works fine.

cambalinho 142 Practically a Posting Shark
#ifndef WINVER
#define WINVER 0x0501
#else
#if defined(_WIN32_WINNT) && (WINVER 0x0400)
#error WINVER setting conflicts with _WIN32_WINNT setting
#endif
#endif

do you know these code?
i don't know use it, but maybe can resolve it ;)
can you advice me?

cambalinho 142 Practically a Posting Shark

yes i did it. but the text isn't showed

cambalinho 142 Practically a Posting Shark

i add it on linker options, but the text wasn't showed

#include <iostream>
#include <string.h>
#include <windows.h>
//#include "blinktext.h"
//#pragma comment(lib,"gdi32.dll")
using namespace std;

int main()
{
    //TextBlink("hello world", 10,20,3,5);
    HDC hDC=GetDC(GetForegroundWindow());
    SetTextColor(hDC,5);
    TextOut(hDC,1,5,"hello world",11);
    cin.get();
}
cambalinho 142 Practically a Posting Shark

i belive that i know why the error: can i add the GDI32.a by code?
the:

#pragma comment(lib,"gdi32.dll")

is ignored:
"warning: ignoring #pragma comment [-Wunknown-pragmas]"
i'm using CodeBlocks

cambalinho 142 Practically a Posting Shark
#include <process.h>
#include <string>
#include <memory.h>
#include <windows.h>

using namespace std;

void SetCaretPosition (int x, int y)
 {
     COORD coord; // coordinates
     coord.X = x; coord.Y = y; // X and Y coordinates
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); // moves to the coordinates
 }

COORD GetCaretPosition()
{
    COORD s;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    s.X=csbi.dwCursorPosition.X;
    s.Y=csbi.dwCursorPosition.Y;
    return s;
}

struct Blink
{
    string Text;
    int x;
    int y;
    int TextColor;
    int BackColor;
};

unsigned __stdcall BlinkLoop(void *params)
{
    Blink *p = static_cast<Blink *>(params);

    char EmptyText[p->Text.length()+1];
    memset(EmptyText,' ', sizeof(EmptyText));
    EmptyText[ sizeof(EmptyText)-1 ] ='\0';
    HDC hDC=GetDC(GetForegroundWindow());
    while (true)
    {
        TextOut(hDC,p->x,p->y,p->Text.c_str(),(int)p->Text.length());
        Sleep(1000);
        TextOut(hDC,p->y,p->x,EmptyText,(int)p->Text.length());
        Sleep(500);
    }
    return 0;
}
void TextBlink(string Text, int x, int y, int TextColor, int BackColor)
{
    Blink *b=NULL;
    b->Text=Text;
    b->BackColor=BackColor;
    b->TextColor=TextColor;
    b->x=x;
    b->y =y;
    _beginthreadex(NULL, 0, BlinkLoop  , b, 0, NULL);
}
cambalinho 142 Practically a Posting Shark

so you need see all the code?

cambalinho 142 Practically a Posting Shark

yes

cambalinho 142 Practically a Posting Shark

finally i fix several errors. now i just have 2 errors because of pointers:

unsigned __stdcall BlinkLoop(void *params)
{
    Blink *p = static_cast<Blink *>(params);

    char EmptyText[p->Text.length()+1];
    memset(EmptyText,' ', sizeof(EmptyText));
    EmptyText[ sizeof(EmptyText)-1 ] ='\0';
    HDC hDC=GetDC(GetForegroundWindow());
    while (true)
    {
        TextOut(hDC,p->x,p->y,p->Text.c_str(),(int)p->Text.length());
        Sleep(1000);
        TextOut(hDC,p->y,p->x,EmptyText,(int)p->Text.length());
        Sleep(500);
    }
    return 0;
}

see the TextOut(). what i'm doing wrong?
error message:
"C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|45|undefined reference to `_imp__TextOutA@20'|"

cambalinho 142 Practically a Posting Shark

i resolve that.. i found ')'.. was the problem.
and i fixed these line too:

TextOut(hDC,x,y,Text.c_str(),(int)Text.length());

i must cast it to int and use '()';)
thanks for all

cambalinho 142 Practically a Posting Shark

i get errors:
EmptyText[ sizeof(EmptyText)-1) ] ='\0';
"C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|39|error: expected ']' before ')' token|"

cambalinho 142 Practically a Posting Shark

i allways have the same problem with some API functions :(
see these function:

unsigned __stdcall BlinkLoop(string Text, int x, int y)
{
    char *EmptyText;
    const char *CharText=Text.c_str();
    EmptyText=new char[ Text.length() ] ;
    int i;
    for( i=0;i<=(int)Text.length();i++)
    {
        EmptyText[i] = ' ';
    }
    EmptyText[i] ='\0';
    HDC a=GetDC(GetForegroundWindow());
    char *v;
    while (true)
    {

        sprintf(v,Text.c_str());
        TextOut(a,x,y,v,Text.length);
        Sleep(1000);
        sprintf(v,EmptyText);
        TextOut(a,y,x,v,Text.length);
        Sleep(500);
    }
    return 0;
}

my problem is with TextOut() with strings:(
please tell me what is my problem

cambalinho 142 Practically a Posting Shark

the best is show you all the file:

#include <process.h>
#include <string>


using namespace std;

class MultiThread
{
    private:
        void *b;
    public:
        void ParameterList(void *c)
        {
            b=c;
        }

        void Thread(unsigned (__stdcall*) (void *)  )
        {
            _beginthreadex(NULL, 0, (__stdcall*) (void *)  , &b, 0, NULL);
        }
};

void SetCaretPosition (int x, int y)
 {
     COORD coord; // coordinates
     coord.X = x; coord.Y = y; // X and Y coordinates
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); // moves to the coordinates
 }

COORD GetCaretPosition()
{
    COORD s;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    s.X=csbi.dwCursorPosition.X;
    s.Y=csbi.dwCursorPosition.Y;
    return s;
}

struct Blink
{
    string Text;
    int x;
    int y;
    int TextColor;
    int BackColor;
};

unsigned __stdcall BlinkLoop(string Text, int x, int y)
{
    char *EmptyText;
    EmptyText=new char[ Text.length() ] ;
    int i;
    for( i=0;i<=Text.length();i++)
    {
        EmptyText[i] = ' ';
    }
    EmptyText[i] ='\0';
    HDC a=GetDC(GetForegroundWindow());
    while (true)
    {
        TextOut(a,x,y,Text.c_str(),Text.length);
        Sleep(1000);
        TextOut(a,y,x,EmptyText,Text.length);
        Sleep(500);
    }
    return 0;
}

void TextBlink(string Text, int x, int y, int TextColor, int BackColor)
{
    MultiThread blink;
    Blink b;
    b.Text=Text;
    b.BackColor=BackColor;
    b.TextColor=TextColor;
    b.x=x;
    b.y =y;
    blink.ParameterList(&b);
    blink.Thread(&BlinkLoop);
}

seems that i have several errors on these file :(
"C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h||In member function 'void MultiThread::Thread(unsigned int (attribute((stdcall)) )(void))':|
C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|19|error: expected primary-expression before 'attribute'|
C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|19|error: expected ')' before 'attribute'|
C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h||In function 'unsigned int BlinkLoop(std::string, int, int)':|
C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|55|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|63|error: cannot convert 'std::basic_string<_CharT, _Traits, _Alloc>::length<char, std::char_traits<char>, std::allocator<char> >' from type 'std::basic_string<char>::size_type (std::basic_string<char>::)()const noexcept (true) {aka unsigned int (std::basic_string<char>::)()const noexcept (true)}' to type 'int'|
C:\Users\Joaquim\Documents\CodeBlocks\blinktext\blinktext.h|65|error: cannot convert …

cambalinho 142 Practically a Posting Shark

by some reasons i prefere my own code:
- for change the textcolor and backcolor;
- the loop will be like a thread;
- and i can change the caret position ;)
but i get some errors with my multithread class :(
do me a favor see my last thread: http://www.daniweb.com/software-development/cpp/threads/466459/multithread

after resolve that i will came back here

cambalinho 142 Practically a Posting Shark

i have 1 class Multithread, but seems that i have some errors:(

#include <process.h>
#include <string>

using namespace std;

class MultiThread
{
    private:
        void * b;
    public:
        void ParameterList(void *c)
        {
            b=c;
        }

        void Thread(unsigned (__stdcall*) (void *)  )
        {
            _beginthreadex(NULL, 0, (__stdcall*) (void *)  , b, 0, NULL);
        }
};

the parameterlist is a struture for the thread arguments.

error message:
"error: expected primary-expression before 'attribute'"
"error: expected ')' before 'attribute'"
can anyone advice me?

cambalinho 142 Practically a Posting Shark

i'm trying do that and i must put that loop on a thread..

#include <iostream>
 #include <windows.h>

 using namespace std;

 void gotoxy (int x, int y);

 int main()
 {
     while (true)
     {
         gotoxy(0,0); // move to where we want to output
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
         string Text="hello world";
         char *EmptyText;
         EmptyText=new char[ Text.length() ] ;
         int i;
         for( i=0;i<=Text.length();i++)
            {
                EmptyText[i] = ' ';
            }
            EmptyText[i] ='\0';
         cout << Text; // overwrite the current output
         Sleep(1000);
            gotoxy(0,0); // move back to the start of output
         cout << EmptyText; // this will reset the output to blank
            Sleep(500);
    }

     cin.get();
     return EXIT_SUCCESS;
 }

 void gotoxy (int x, int y)
 {
     COORD coord; // coordinates
     coord.X = x; coord.Y = y; // X and Y coordinates
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); // moves to the coordinates
 }
  • these type of loop don't consumes very CPU?
  • i'm confused with 1 thing: the delay can give problems for get\set the caret position?(you can read something and the caret can moves... if you understand what i mean)
    unless i use api functiions for print the blink text;)
cambalinho 142 Practically a Posting Shark

i have code for write on console and change the text color and backcolor and clear screen(and much more) inside of a nice class console.
these function change the text color and back color:

    void SetColorAndBackground(int ForgC, int BackC=0)
    {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ForgC|(BackC<<4) );
    }

but is there any way for blink the text?

cambalinho 142 Practically a Posting Shark

after more search i found it ;)
here i use 'en_US.UTF-8' string option, but we can change it for other types

setlocale(LC_ALL, "en_US.UTF-8");

about it:

> The setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale. If locale is a null pointer, setlocale queries the current C locale without modifying it.
> Parameters
> category  -   locale category identifier, one of the LC_xxx macros. May be 0.
> locale    -   system-specific locale identifier. Can be "" for the user-preferred locale or "C" for the minimal locale
> Return value
> 
> Pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.

heres the page about it:
http://en.cppreference.com/w/cpp/locale/setlocale

thansk for all... thanks

cambalinho 142 Practically a Posting Shark

seems that the don't works for cin... why?

cambalinho 142 Practically a Posting Shark
#include <clocale>
#include <iostream>

using namespace std;

int main() 
{
    setlocale(LC_ALL, "");//these is the important line
    cout << "úçéûi"; // yes the cout works too;)
    return 0;
}

thanks too all

cambalinho 142 Practically a Posting Shark

i try with _T() and _TEXT(), but only show me the 1st letter :(

cambalinho 142 Practically a Posting Shark

sorry i get these error:
"error: converting to execution character set: Illegal byte sequence"

cambalinho 142 Practically a Posting Shark

imagine these line:

cout << "glória vitória"; //glory vitory

why instead print 'ó', prints '3/4'(the ascii char)???
changing the console font name, can resolve it?

cambalinho 142 Practically a Posting Shark

thanks.. yes i wasn't using the tchar.h
thanks.

cambalinho 142 Practically a Posting Shark

sorry, but i get the same error :(
'error: '_T' was not declared in this scope'
the same with '_TEXT'. i use them like a function:

_T(argument)
cambalinho 142 Practically a Posting Shark

so instead use LPTSTR or LPSTR, i can use char* or wchar_t*.
char* is non-unicode and wchar_t* is unicode.
that's why, too, we can't print 'é' directly on console.
for that we can use wcout with 'L'.
i have the windows.h include, but the 'L' where is declared?
or i must declare it?

cambalinho 142 Practically a Posting Shark

sorry i didn't understand 1 thing: how can use strings\char* variable names in these functions?