LNK2019 with the functions in my namespace - c++

I have tried to read the examples of others' LNK2019 error, but they doesn't match my case. It troubled me for 2 hours and have no idea what to do.
The kbam_emu and pixel_check are the namespaces of mine. The names behind are my functions. They are declared in "kbam_emu.h", "kbam_emu.cpp", "pixel_check.h" and "pixel_check.cpp" respectively:
"kbam_emu.h"
/*
Name: keyboard and mouse emulation
Copyright: -
Author: Samuel YKC
Date: 15/11/14 20:17
Description: This header file is designed for creating bots. The essential codes for keyboard and mouse input are written by
a programmer on the Internet with the user name 'Muted'. Thanks, Muted. Here is the address for his original post:
http://forum.codecall.net/topic/45292-c-keyboardmouse-emulation/
*/
#ifndef _KBAM_EMU_H_
#define _KBAM_EMU_H_
#include <string>
#include <sstream>
#include <ctype.h>
#include <windows.h>
#include <winable.h>
using namespace std;
namespace kbam_emu
{
enum mouse_button{ left, middle, right };
void GenerateKey(int vk, BOOL bExtended);
void GenerateLine(string line);
void Click(const int X, const int Y, mouse_button button = left);
void Drag(const int X, const int Y, const int X2, const int Y2);
}
#endif
"kbam_emu.cpp"
#include <kbam_emu.h>
/* This is a function to simplify usage of sending keys */
void kbam_emu::GenerateKey(int vk, BOOL bExtended)
{
KEYBDINPUT kb = {0};
INPUT Input = {0};
/* Generate a "key down" */
if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
/* Generate a "key up" */
ZeroMemory(&kb, sizeof(KEYBDINPUT));
ZeroMemory(&Input, sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
return;
}
/* This is a function to send a line containing English alphabets, numbers and spaces
It assumes that the user does not have the Caps Lock turned on initailly */
void kbam_emu::GenerateLine(string line)
{
stringstream is(line);
char c;
while(is.get(c))
{
if(isupper(c))
{
GenerateKey(VK_CAPITAL, TRUE); //Caps Lock on
GenerateKey(c, FALSE);
GenerateKey(VK_CAPITAL, TRUE); //Caps Lock off
}
else
{
GenerateKey(toupper(c), FALSE);
}
}
return;
}
/* This is a function to click somewhere on the screen */
void kbam_emu::Click(const int X, const int Y, mouse_button button)
{
SetCursorPos(X, Y);
DWORD down;
DWORD up;
switch(button)
{
case left:
down = MOUSEEVENTF_LEFTDOWN;
up = MOUSEEVENTF_LEFTUP;
break;
case middle:
down = MOUSEEVENTF_MIDDLEDOWN;
up = MOUSEEVENTF_MIDDLEUP;
break;
case right:
down = MOUSEEVENTF_RIGHTDOWN;
up = MOUSEEVENTF_RIGHTUP;
break;
}
INPUT Input[2];
ZeroMemory(Input, sizeof(INPUT) * 2);
Input[0].type = INPUT_MOUSE;
Input[0].mi.dwFlags = down;
Input[1].type = INPUT_MOUSE;
Input[1].mi.dwFlags = up;
SendInput(2, Input, sizeof(INPUT));
return;
}
void kbam_emu::Drag(const int X, const int Y, const int X2, const int Y2)
{
SetCursorPos(X, Y);
INPUT Input[1];
ZeroMemory(Input, sizeof(INPUT));
Input[0].type = INPUT_MOUSE;
Input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, Input, sizeof(INPUT));
SetCursorPos(X2, Y2);
INPUT Input2[1];
ZeroMemory(Input2, sizeof(INPUT));
Input2[0].type = INPUT_MOUSE;
Input2[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, Input2, sizeof(INPUT));
return;
}
"pixel_check.h"
/*
Name: pixel check
Copyright: -
Author: Samuel YKC
Date: 16/11/14 00:26
Description: This header file is designed for checking pixels. The essential codes for retrieving the color of a pixel
on screen are written by a programmer on the Internet with the user name 'templatetypedef'. Thanks, templatetypedef. Here
is the address for his original post:
http://stackoverflow.com/questions/4839623/getting-pixel-color-in-c
*/
#ifndef _PIXEL_CHECK_H_
#define _PIXEL_CHECK_H_
#include <windows.h>
#include "kbam_emu.h"
using namespace std;
using namespace kbam_emu;
namespace pixel_check
{
COLORREF GetPixelColor(int x, int y);
bool ComparePixelWithColor(int x, int y, COLORREF color);
void SleepOnColor(int x, int y, COLORREF color, int interval=100);
void SleepUntilColor(int x, int y, COLORREF color, int interval=100);
void ClickUntilColor(int click_x, int click_y, int pixel_x, int pixel_y, COLORREF color, int interval=1000);
}
#endif
"pixel_check.cpp"
#include "pixel_check.h"
COLORREF pixel_check::GetPixelColor(int x, int y)
{
HDC dc = GetDC(NULL);
COLORREF color = GetPixel(dc, x, y);
ReleaseDC(NULL, dc);
return color;
}
bool pixel_check::ComparePixelWithColor(int x, int y, COLORREF color)
{
HDC dc = GetDC(NULL);
COLORREF pixel_color = GetPixel(dc, x, y);
ReleaseDC(NULL, dc);
return (pixel_color==color);
}
void pixel_check::SleepOnColor(int x, int y, COLORREF color, int interval)
{
while(ComparePixelWithColor(x,y,color)) Sleep(interval);
}
void pixel_check::SleepUntilColor(int x, int y, COLORREF color, int interval)
{
while(!ComparePixelWithColor(x,y,color)) Sleep(interval);
}
void pixel_check::ClickUntilColor(int click_x, int click_y, int pixel_x, int pixel_y, COLORREF color, int interval)
{
while(!ComparePixelWithColor(pixel_x,pixel_y,color))
{
Click(click_x, click_y);
Sleep(interval);
}
}
And in my project, I put the #include like this (I placed the .h & .cpp in the default include directory so <> is fine to use):
#include <kbam_emu.h>
#include <pixel_check.h>
and uses the functions this way:
kbam_emu::Click(0, 0);
Lastly, in the .pro file I added this line:
LIBS += -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
I supposed everything I have done is logical. Still, the linker bet a differ. I tried to post the full codes here so that I won't miss anything. Does anyone know what is wrong?

After I keep randomly trying things for days, I accidentally find the solution.
I placed my files into the project instead of the default \include directory this time. Then, I clicked the button "run qmake" in Qt and those kbam_emu.obj & pixel_check.obj that haven't been created before are finally being created. No more linker problem now!
I think this might be about the makefile is not updated automatically so I need to manually give the run qmake instruction to Qt. Hope my case would help some of you.

Related

How to loop mouse clicks if left mouse button is held down

i am trying to make an autoclicker. It should repeat MOUSEEVENTF_LEFTDOWN and MOUSEEVENTF_LEFTUP when LBUTTON is held.
Here is what i have so far. it doesn't repeat it, it double clicks.
#include <iostream>
#include<Windows.h>
using namespace std;
void menu()
{
cout << "Press 'F4' to enable and 'F5' to disable autoclicker\n";
}
void clicker()
{
bool click = false;
while (true)
{
if (GetAsyncKeyState('X'))
{
click = true;
}
else if (GetAsyncKeyState('Z'))
{
click = false;
}
if (click == true)
{
while (GetKeyState(VK_LBUTTON))
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(100);
}
}
}
}
int main()
{
menu();
clicker();
return 0;
}
Any help is appreciated! thanks
You're not giving the target application enough time to detect the key press, you should be using SendInput() as it's not deprecated.
#include <chrono>
#include <thread>
INPUT LeftButton = { 0 };
LeftButton.type = INPUT_MOUSE;
LeftButton.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &LeftButton, sizeof(INPUT));
std::this_thread::sleep_for(std::chrono::milliseconds(5));
LeftButton.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &LeftButton, sizeof(INPUT));

C++ Toggle to hold left click down?

How do I make a tiny program that holds down left click, while toggleable through a key? I can make it toggle the leftmousebutton to click constantly but I have no clue on how to make it hold down.
void Clicker2()
{
while (1)
{
if (GetAsyncKeyState('U')) // U toggles on
{
click = true;
}
if (GetAsyncKeyState('I')) //I toggles off
{
click = false;
}
if (click == true)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
}
}
When using toggles you want to check the return value of GeyAsyncKeyState(), the least significant bit specifically, you do this by doing a bitwise AND with the result.
I have simplified your code, and converted it to using SendInput() which is what is recommended.
int main()
{
INPUT input{ 0 };
input.type = INPUT_MOUSE;
bool bClick = false;
while (true)
{
//toggles it on and off
if (GetAsyncKeyState('U') &1)
bClick = !bClick;
if (bClick)
{
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &input, sizeof(INPUT));
}
else
{
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &input, sizeof(INPUT));
}
}
return 0;
}

C++ Compiler throwing error with GLUT

The code was working fine but after I added the void projection(float), it's giving me unqaulified-id error inside the projection function. I'm using CodeBlocks IDE, MinGW. Please help me.
This is the error I'm getting:
||=== Build: Debug in L3 (compiler: GNU GCC Compiler) ===|
C:\Users\sos\Documents\Code Blocks c++\L3\src\CallbackFunctions.cpp||In function 'void projection(float)':|
C:\Users\sos\Documents\Code Blocks c++\L3\src\CallbackFunctions.cpp|56|error: expected unqualified-id before '=' token|
C:\Users\sos\Documents\Code Blocks c++\L3\src\CallbackFunctions.cpp|57|error: expected primary-expression before ',' token|
C:\Users\sos\Documents\Code Blocks c++\L3\src\CallbackFunctions.cpp| 57|error: expected primary-expression before ')' token|
C:\Users\sos\Documents\Code Blocks c++\L3\src\CallbackFunctions.cpp||In function 'void specialKeyboard(int, int, int)':|
||=== Build failed: 3 error(s), 15 warning(s) (0 minute(s), 0 second(s)) ===|
Moreover, if I comment everything inside projection, I get this error:
obj\Debug\src\Display.o||In function `glutInit_ATEXIT_HACK':|
C:\Program Files\CodeBlocks\MinGW\include\GL\freeglut_std.h|623|multiple definition of `keyboardKey'|
C:\Program Files\CodeBlocks\MinGW\include\GL\freeglut_std.h|623|multiple definition of `mouseX'|
C:\Program Files\CodeBlocks\MinGW\include\GL\freeglut_std.h|623|multiple definition of `mouseY'|
C:\Program Files\CodeBlocks\MinGW\include\GL\freeglut_std.h|623|multiple definition of `toggleProjection'|
CallbackFunctions.h
#ifndef CALLBACKFUNCTIONS_H
#define CALLBACKFUNCTIONS_H
#include "GL/freeglut.h"
unsigned char keyboardKey;
char *specialKeyboardKey ="";
char *modifier="";
char *mouseButtonPressed="";
char *mouseState="";
int mouseX, mouseY;
int toggleProjection=0;
char *view="";
/* Hardware Interrupts callback functions */
void display(); //called every single frame
void reshape(int width, int height); //called whenever the dimensions of the window are changed
void idle(); //when there is no interaction with the window
void keyboard(unsigned char key, int x, int y); //whenever a keyboard key is pressed/interrupt occurs
void specialKeyboard(int button, int x, int y); //captures special keys like: SHIFT ALT CTRL F1.....
void mouse(int button, int state, int x, int y); //captures the mouse clicks and their state
void mouseMotion(int x, int y); //captures the motion of the mouse pointer in the window
void projection(float asp);
#endif // CALLBACKFUNCTIONS_H
CallbackFunctions.cpp
#include "../include/CallbackFunctions.h"
#include "../include/Text.h"
extern int dim;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//Drawing stuff
glFlush();
glutSwapBuffers();
}
void idle()
{
display();
}
/* This callback function is called whenever the window is resized or reshaped */
void reshape(int width, int height)
{
//Width To Height Ratio
float w2h = (height>0)? (float)width/height : 1;
glViewport(0, 0, width, height);
projection(w2h);
}
void projection(float asp)
{
//Setting up the Viewing Matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(toggleProjection==0)
{
glOrtho(-dim*asp, +dim*asp, -dim, +dim, -dim, +dim);
}
else
{
float fov = 55.0, near = asp/5, far = asp*5;
gluPerspective(fov, asp, near, far);
//To do
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* This callback function is called when there is no activity in the window */
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
exit(0);
break;
}
keyboardKey = key;
glutPostRedisplay();
}
/* This callback function is called whenever a keyboard interrupt is encountered */
void specialKeyboard(int key, int state, int a)
{
int currentModifier = glutGetModifiers();
switch(currentModifier)
{
case GLUT_ACTIVE_SHIFT:
modifier = "SHIFT";
break;
case GLUT_ACTIVE_CTRL:
modifier = "CTRL";
break;
case GLUT_ACTIVE_ALT:
modifier = "ALT";
break;
}
switch(key)
{
case GLUT_KEY_F1:
if(toggleProjection=0)
{
toggleProjection = 1;
view = "perspective";
break;
}
else
{
toggleProjection = 0;
view = "orthographic";
break;
}
}
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_LEFT_BUTTON)
mouseButtonPressed = "Left";
else if(button == GLUT_RIGHT_BUTTON)
mouseButtonPressed = "Right";
if(state == GLUT_DOWN)
mouseState = "down";
else if(state == GLUT_UP)
mouseState = "up";
}
void mouseMotion(int x, int y)
{
mouseX = x;
mouseY = y;
}
/*void info()
{
displayTextAt(-130, -40, 0, "mouseButton: %s", mouseButtonPressed);
displayTextAt(-130, -50, 0, "mouseButtonState: %s", mouseState);
displayTextAt(-130, -60, 0, "mouseX: %d", mouseX);
displayTextAt(-130, -70, 0, "mouseY: %d", mouseY);
displayTextAt(-130, -80, 0, "keyboard key: %c", keyboardKey);
displayTextAt(-130, -90, 0, "modifier: %s", modifier);
displayTextAt(70, -90, 0, view);
}*/
This is really a global variable declaration in a header problem. I've included the pastebin code (with fixes) for posterity.
/*This is the CallbackFunctions.h ------------------ */
#ifndef CALLBACKFUNCTIONS_H
#define CALLBACKFUNCTIONS_H
#include <GL/freeglut.h>
extern unsigned char keyboardKey;
/* Hardware Interrupts callback functions */
void display(); //called every single frame
void keyboard(unsigned char key, int x, int y); //whenever a keyboard key is pressed/interrupt occurs
#endif // CALLBACKFUNCTIONS_H
/*This is the CallbackFunctions.cpp ------------------ */
#include "CallbackFunctions.h"
unsigned char keyboardKey = 0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void keyboard(unsigned char key, int x, int y)
{
keyboardKey = key;
}
/* --------------- This is the Main.cpp ---------------- */
#include <GL/freeglut.h>
#include "CallbackFunctions.h"
#define WIDTH 700
#define HEIGHT 400
void setupGlutWindow(int *argc, char **argv, int width, int height);
void setupCallbackFunctions();
int main(int argc, char** argv)
{
setupGlutWindow(&argc, argv, WIDTH, HEIGHT);
setupCallbackFunctions();
glutMainLoop();
}
void setupGlutWindow(int *argc, char **argv, int width, int height)
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(700, 500);
glutCreateWindow("Project L3");
glViewport(0, 0, width, height);
}
void setupCallbackFunctions()
{
glutDisplayFunc(display);
glutIdleFunc(display);
glutKeyboardFunc(keyboard);
}

Linux terminal not displaying anything with ncurses

I'm trying to make a library to simplify the ncurses use to display colors. I'm doing it object-oriented so it'll easy to handle changes in the future. But the problem is that I can't get to work this code.
#include <ncurses.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <iostream>
using namespace std;
class ColorWindow {
private:
bool canColor;
WINDOW* container;
int height, width, startx, starty;
public:
ColorWindow() {
if(has_colors()) {
canColor=true;
}
this->height = 20;
this->width = 84;
this->starty = (LINES - height) / 2; /* Calculating for a center placement */
this->startx = (COLS - width) / 2;
}
bool writeStringWithColor(int x, int y, const char* message) {
if(!canColor) {
writeString(3, 5, "Sorry, your term can't show colors.");
return false;
}
init_pair(1, COLOR_RED, COLOR_BLACK);
writeString(0, 10, "aaaaaaaaa");
wattron(getContainer(), COLOR_PAIR(1));
writeString(x, y, message);
wattroff(getContainer(), COLOR_PAIR(1));
}
void writeString(int x, int y, const char* message) {
mvwprintw(getContainer(), x, y, message);
}
WINDOW* createNewContainer() {
this->container = newwin(height, width, starty, startx);
wrefresh(this->container); /* Show that box */
return getContainer();
}
WINDOW* getContainer() {
return this->container;
}
void refreshContainer() {
refresh();
wrefresh(this->container); /* Show that box */
}
};
int main() {
ColorWindow cw = ColorWindow();
initscr(); /* Start curses mode */
cbreak(); /* Line buffering disabled, Pass on
* everything to me */
keypad(stdscr, TRUE);
start_color();
cw.createNewContainer();
bool success = cw.writeStringWithColor(0, 10, "Hello everyone in color!!");
if(!success)
cw.writeString(0, 10, "Write with color failed :(");
cw.refreshContainer();
sleep(2);
endwin();
return 0;
}
Thanks in Advance.
There are a couple of bugs in your code:
You don't initialize canColor and container, so copying the fields into cw in main has undefined behavior. Fixed by:
ColorWindow() : canColor(false), container(nullptr) {
writeStringWithColor is missing a return statement at the end, also leading to undefined behavior in main. Fixed by:
return true;
at the end of writeStringWithColor.
Your x and y arguments are swapped in the call to mvwprintw in writeString. Fixed by:
mvwprintw(getContainer(), y, x, message);
LINES and COLS are only valid after ncurses is initialized, so your starty and startx values are garbage. Fixed by moving the initialization of cw after the ncurses init code in main:
initscr(); /* Start curses mode */
cbreak(); /* Line buffering disabled, Pass on
* everything to me */
keypad(stdscr, TRUE);
start_color();
ColorWindow cw = ColorWindow();
Full program:
#include <ncurses.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <iostream>
using namespace std;
class ColorWindow {
private:
bool canColor;
WINDOW* container;
int height, width, startx, starty;
public:
ColorWindow() : canColor(false), container(nullptr) {
if(has_colors()) {
canColor=true;
}
this->height = 20;
this->width = 84;
this->starty = (LINES - height) / 2; /* Calculating for a center placement */
this->startx = (COLS - width) / 2;
}
bool writeStringWithColor(int x, int y, const char* message) {
if(!canColor) {
writeString(3, 5, "Sorry, your term can't show colors.");
return false;
}
init_pair(1, COLOR_RED, COLOR_BLACK);
writeString(0, 10, "aaaaaaaaa");
wattron(getContainer(), COLOR_PAIR(1));
writeString(x, y, message);
wattroff(getContainer(), COLOR_PAIR(1));
return true;
}
void writeString(int x, int y, const char* message) {
mvwprintw(getContainer(), y, x, message);
}
WINDOW* createNewContainer() {
this->container = newwin(height, width, starty, startx);
wrefresh(this->container); /* Show that box */
return getContainer();
}
WINDOW* getContainer() {
return this->container;
}
void refreshContainer() {
refresh();
wrefresh(this->container); /* Show that box */
}
};
int main() {
initscr(); /* Start curses mode */
cbreak(); /* Line buffering disabled, Pass on
* everything to me */
keypad(stdscr, TRUE);
start_color();
ColorWindow cw = ColorWindow();
cw.createNewContainer();
bool success = cw.writeStringWithColor(0, 10, "Hello everyone in color!!");
if(!success)
cw.writeString(0, 10, "Write with color failed :(");
cw.refreshContainer();
sleep(2);
endwin();
return 0;
}

How to blink particular text continuously all time during input and output?

Here is my code which blinks 'Welcome' after user enter his name.
'Welcome' does not blink when user is writing his name. As user hits enter then caret goes into the while loop. Then caret position is set back to the coordinates of 'Welcome' & cout prints 'Welcome' with 5 colors again & again so it seems that 'Welcome' is blinking.
But I want that 'Welcome' blinks continuously as the program starts.
So more likely this question also ask - can we have two caret/cursor at the same time ?
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int main(int argc, char** argv)
{
int x,y,i;char name[10];
textcolor(10);
x=wherex();y=wherey(); //corrdinates of caret will be stored in x & y.
cout<<"\t\t\t\tWelcome\n";
textcolor(15);
cout<<"\nEnter your name\n";
gets(name);
while(1)
{
for(i=10;i<15;i++)
{
textcolor(i);
gotoxy(x,y); //Transferring caret to the coordinates stored in x & y.
cout<<"\t\t\t\tWelcome";
Sleep(300);
}
}
return 0;
}
I wrote a small code for this question , it's not 100% correct answer. I am just posting this answer just for giving little bit idea to newbie.
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int x,y,b,l,n=0;
char c;
void blink()
{
{
int m;
for(m=10;m<15;m++)
{
textcolor(m);
gotoxy(x,y);
cout<<"\t\t\t\tWelcome";
Sleep(60);
}
}
}
int main(int argc, char** argv)
{
char i;int key_stroke;
textcolor(10);
x=wherex();y=wherey();
cout<<"\t\t\t\tWelcome\n";
textcolor(15);
cout<<"\nEnter your name\n";
l=wherex();b=wherey();
z:
{
while (1)
{
if(!(_kbhit()))
{
blink();
goto z;
}
else
{
i=_getch();
if(i==13)
{
gotoxy(l+n,b+1);
return 0;
}
textcolor(10);
gotoxy(l+n,b);
cout<<i;n=n+1;
}
}
}
return 0;
}
No we cant have two caret/cursor at the same time. User inputs name first.
It begins to blink right after the user has pressed the enter key
by first displaying the text in a given color and time delay.
Then after it sets the color to black and overwrites the text wth black color.
Windows code:
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y);
void setcolor(WORD color);
void clrscr();
int main(int argc, char** argv){
int x,y,i;char name[10];
setcolor(10);
cout<<"Welcome\n";
setcolor(15);
cout<<"\nEnter your name ";
gets(name);
i=0;
x=22;
y=12;
while(1) {
// counter for text color
i++; if (i>15) i=1;
// print colored text
setcolor(i);
gotoxy(x,y);
cout<<"Welcome "<<name;
Sleep(100);
// Print black text to simulate blink
setcolor(0);
gotoxy(x,y);
cout<<" ";
Sleep(100);
}
setcolor(7);
gotoxy(1,24);
return 0;
}
void setcolor(WORD color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
return;
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x; coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
return;
}
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
return;
}
Instead of such Codes you can use BLINK in textcolor() function. the only problem is that you cannot control its speed. thats it. otherwise its easy to use and you can also set text color.
Eg.
textcolor ( RED + BLINK ) ;
cprintf ( " /t/t WELCOME " ) ;
thats it. I didn't had time to read your full question and program. Also I am just a newbie. So I hope this helps you and others.